@@ -13,6 +13,7 @@ import Control.Exception.Safe (Exception (displayExcept
13
13
catchAny )
14
14
import Control.Monad.Extra (concatMapM , unless ,
15
15
when )
16
+ import qualified Data.Aeson.Encode.Pretty as A
16
17
import Data.Default (Default (def ))
17
18
import Data.Foldable (traverse_ )
18
19
import qualified Data.HashMap.Strict as HashMap
@@ -22,6 +23,8 @@ import Data.List.Extra (intercalate, isPrefixOf,
22
23
import Data.Maybe (catMaybes , isJust )
23
24
import qualified Data.Text as T
24
25
import qualified Data.Text.IO as T
26
+ import Data.Text.Lazy.Encoding (decodeUtf8 )
27
+ import qualified Data.Text.Lazy.IO as LT
25
28
import Development.IDE (Action , Rules ,
26
29
hDuplicateTo' )
27
30
import Development.IDE.Core.Debouncer (Debouncer ,
@@ -71,10 +74,16 @@ import qualified HieDb.Run as HieDb
71
74
import Ide.Plugin.Config (CheckParents (NeverCheck ),
72
75
Config ,
73
76
getConfigFromNotification )
77
+ import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig ,
78
+ pluginsToVSCodeExtensionSchema )
74
79
import Ide.PluginUtils (allLspCmdIds' ,
75
80
getProcessID ,
76
81
pluginDescToIdePlugins )
77
- import Ide.Types (IdePlugins )
82
+ import Ide.Types (IdeCommand (IdeCommand ),
83
+ IdePlugins ,
84
+ PluginDescriptor (PluginDescriptor , pluginCli ),
85
+ PluginId (PluginId ),
86
+ ipMap )
78
87
import qualified Language.LSP.Server as LSP
79
88
import Options.Applicative hiding (action )
80
89
import qualified System.Directory.Extra as IO
@@ -97,12 +106,11 @@ data Command
97
106
| Db { projectRoot :: FilePath , hieOptions :: HieDb. Options , hieCommand :: HieDb. Command}
98
107
-- ^ Run a command in the hiedb
99
108
| LSP -- ^ Run the LSP server
100
- | Custom { projectRoot :: FilePath , ideCommand :: IdeCommand } -- ^ User defined
109
+ | PrintExtensionSchema
110
+ | PrintDefaultConfig
111
+ | Custom { projectRoot :: FilePath , ideCommand :: IdeCommand IdeState } -- ^ User defined
101
112
deriving Show
102
113
103
- newtype IdeCommand = IdeCommand (IdeState -> IO () )
104
-
105
- instance Show IdeCommand where show _ = " <ide command>"
106
114
107
115
-- TODO move these to hiedb
108
116
deriving instance Show HieDb. Command
@@ -112,16 +120,31 @@ isLSP :: Command -> Bool
112
120
isLSP LSP = True
113
121
isLSP _ = False
114
122
115
- commandP :: Parser Command
116
- commandP = hsubparser (command " typecheck" (info (Check <$> fileCmd) fileInfo)
117
- <> command " hiedb" (info (Db " ." <$> HieDb. optParser " " True <*> HieDb. cmdParser <**> helper) hieInfo)
118
- <> command " lsp" (info (pure LSP <**> helper) lspInfo)
119
- )
123
+ commandP :: IdePlugins IdeState -> Parser Command
124
+ commandP plugins =
125
+ hsubparser(command " typecheck" (info (Check <$> fileCmd) fileInfo)
126
+ <> command " hiedb" (info (Db " ." <$> HieDb. optParser " " True <*> HieDb. cmdParser <**> helper) hieInfo)
127
+ <> command " lsp" (info (pure LSP <**> helper) lspInfo)
128
+ <> command " vscode-extension-schema" extensionSchemaCommand
129
+ <> command " generate-default-config" generateDefaultConfigCommand
130
+ <> pluginCommands
131
+ )
120
132
where
121
133
fileCmd = many (argument str (metavar " FILES/DIRS..." ))
122
134
lspInfo = fullDesc <> progDesc " Start talking to an LSP client"
123
135
fileInfo = fullDesc <> progDesc " Used as a test bed to check your IDE will work"
124
136
hieInfo = fullDesc <> progDesc " Query .hie files"
137
+ extensionSchemaCommand =
138
+ info (pure PrintExtensionSchema )
139
+ (fullDesc <> progDesc " Print generic config schema for plugins (used in the package.json of haskell vscode extension)" )
140
+ generateDefaultConfigCommand =
141
+ info (pure PrintDefaultConfig )
142
+ (fullDesc <> progDesc " Print config supported by the server with default values" )
143
+
144
+ pluginCommands = mconcat
145
+ [ command (T. unpack pId) (Custom " ." <$> p)
146
+ | (PluginId pId, PluginDescriptor {pluginCli = Just p}) <- ipMap plugins
147
+ ]
125
148
126
149
127
150
data Arguments = Arguments
@@ -198,6 +221,10 @@ defaultMain Arguments{..} = do
198
221
outH <- argsHandleOut
199
222
200
223
case argCommand of
224
+ PrintExtensionSchema ->
225
+ LT. putStrLn $ decodeUtf8 $ A. encodePretty $ pluginsToVSCodeExtensionSchema argsHlsPlugins
226
+ PrintDefaultConfig ->
227
+ LT. putStrLn $ decodeUtf8 $ A. encodePretty $ pluginsToDefaultConfig argsHlsPlugins
201
228
LSP -> do
202
229
t <- offsetTime
203
230
hPutStrLn stderr " Starting LSP server..."
@@ -310,6 +337,7 @@ defaultMain Arguments{..} = do
310
337
case mlibdir of
311
338
Nothing -> exitWith $ ExitFailure 1
312
339
Just libdir -> HieDb. runCommand libdir opts{HieDb. database = dbLoc} cmd
340
+
313
341
Custom projectRoot (IdeCommand c) -> do
314
342
dbLoc <- getHieDbLoc projectRoot
315
343
runWithDb dbLoc $ \ hiedb hieChan -> do
0 commit comments