Skip to content

Commit 8a6932c

Browse files
committed
Sort vscode extension schema json by keys
Makes it easier to copy and paste configurations into VSCode and reviewing what options have been added and removed. Remove code-duplication, namely ghcide exe loses some capabilities, as it is destined to be removed sooner or later.
1 parent bd1d0a1 commit 8a6932c

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

ghcide/src/Development/IDE/Main.hs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ data Command
191191
| Db {hieOptions :: HieDb.Options, hieCommand :: HieDb.Command}
192192
-- ^ Run a command in the hiedb
193193
| LSP -- ^ Run the LSP server
194-
| PrintExtensionSchema
195-
| PrintDefaultConfig
196194
| Custom {ideCommand :: IdeCommand IdeState} -- ^ User defined
197195
deriving Show
198196

@@ -209,21 +207,13 @@ commandP plugins =
209207
hsubparser(command "typecheck" (info (Check <$> fileCmd) fileInfo)
210208
<> command "hiedb" (info (Db <$> HieDb.optParser "" True <*> HieDb.cmdParser) hieInfo)
211209
<> command "lsp" (info (pure LSP) lspInfo)
212-
<> command "vscode-extension-schema" extensionSchemaCommand
213-
<> command "generate-default-config" generateDefaultConfigCommand
214210
<> pluginCommands
215211
)
216212
where
217213
fileCmd = many (argument str (metavar "FILES/DIRS..."))
218214
lspInfo = fullDesc <> progDesc "Start talking to an LSP client"
219215
fileInfo = fullDesc <> progDesc "Used as a test bed to check your IDE will work"
220216
hieInfo = fullDesc <> progDesc "Query .hie files"
221-
extensionSchemaCommand =
222-
info (pure PrintExtensionSchema)
223-
(fullDesc <> progDesc "Print generic config schema for plugins (used in the package.json of haskell vscode extension)")
224-
generateDefaultConfigCommand =
225-
info (pure PrintDefaultConfig)
226-
(fullDesc <> progDesc "Print config supported by the server with default values")
227217

228218
pluginCommands = mconcat
229219
[ command (T.unpack pId) (Custom <$> p)
@@ -331,10 +321,6 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
331321
numProcessors <- getNumProcessors
332322

333323
case argCommand of
334-
PrintExtensionSchema ->
335-
LT.putStrLn $ decodeUtf8 $ A.encodePretty $ pluginsToVSCodeExtensionSchema argsHlsPlugins
336-
PrintDefaultConfig ->
337-
LT.putStrLn $ decodeUtf8 $ A.encodePretty $ pluginsToDefaultConfig argsHlsPlugins
338324
LSP -> withNumCapabilities (maybe (numProcessors `div` 2) fromIntegral argsThreads) $ do
339325
t <- offsetTime
340326
log Info $ LogLspStart (pluginId <$> ipMap argsHlsPlugins)

src/Ide/Arguments.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ getArguments exeName plugins = execParser opts
6666
opts = info ((
6767
VersionMode <$> printVersionParser exeName
6868
<|> probeToolsParser exeName
69+
<|> hsubparser
70+
( command "vscode-extension-schema" extensionSchemaCommand
71+
<> command "generate-default-config" generateDefaultConfigCommand
72+
)
6973
<|> listPluginsParser
7074
<|> BiosMode <$> biosParser
7175
<|> Ghcide <$> arguments plugins
@@ -76,6 +80,13 @@ getArguments exeName plugins = execParser opts
7680
<> progDesc "Used as a test bed to check your IDE Client will work"
7781
<> header (exeName ++ " - GHC Haskell LSP server"))
7882

83+
extensionSchemaCommand =
84+
info (pure VSCodeExtensionSchemaMode)
85+
(fullDesc <> progDesc "Print generic config schema for plugins (used in the package.json of haskell vscode extension)")
86+
generateDefaultConfigCommand =
87+
info (pure DefaultConfigurationMode)
88+
(fullDesc <> progDesc "Print config supported by the server with default values")
89+
7990
printVersionParser :: String -> Parser PrintVersion
8091
printVersionParser exeName =
8192
flag' PrintVersion

src/Ide/Main.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ import qualified Data.Aeson.Encode.Pretty as A
1515
import qualified Data.ByteString.Lazy.Char8 as LBS
1616
import Data.Coerce (coerce)
1717
import Data.Default
18+
import Data.Function (on)
1819
import Data.List (sort)
1920
import Data.Text (Text)
2021
import qualified Data.Text as T
22+
import Data.Text.Lazy.Encoding (decodeUtf8)
23+
import qualified Data.Text.Lazy.IO as LT
2124
import Development.IDE.Core.Rules hiding (Log, logToPriority)
2225
import Development.IDE.Core.Tracing (withTelemetryLogger)
2326
import Development.IDE.Main (isLSP)
@@ -96,17 +99,20 @@ defaultMain recorder args idePlugins = do
9699
runLspMode recorder ghcideArgs idePlugins
97100

98101
VSCodeExtensionSchemaMode -> do
99-
LBS.putStrLn $ A.encodePretty $ pluginsToVSCodeExtensionSchema idePlugins
100-
102+
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToVSCodeExtensionSchema idePlugins
101103
DefaultConfigurationMode -> do
102-
LBS.putStrLn $ A.encodePretty $ pluginsToDefaultConfig idePlugins
104+
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToDefaultConfig idePlugins
103105
PrintLibDir -> do
104106
d <- getCurrentDirectory
105107
let initialFp = d </> "a"
106108
hieYaml <- Session.findCradle def initialFp
107109
cradle <- Session.loadCradle def hieYaml d
108110
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle
109111
putStr libdir
112+
where
113+
encodePrettySorted = A.encodePretty' A.defConfig
114+
{ A.confCompare = compare
115+
}
110116

111117
-- ---------------------------------------------------------------------
112118

0 commit comments

Comments
 (0)