Skip to content

Commit d92a59a

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 d92a59a

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ module Ide.Main(defaultMain, runLspMode, Log(..)) where
1212

1313
import Control.Monad.Extra
1414
import qualified Data.Aeson.Encode.Pretty as A
15-
import qualified Data.ByteString.Lazy.Char8 as LBS
1615
import Data.Coerce (coerce)
1716
import Data.Default
1817
import Data.List (sort)
1918
import Data.Text (Text)
2019
import qualified Data.Text as T
20+
import Data.Text.Lazy.Encoding (decodeUtf8)
21+
import qualified Data.Text.Lazy.IO as LT
2122
import Development.IDE.Core.Rules hiding (Log, logToPriority)
2223
import Development.IDE.Core.Tracing (withTelemetryLogger)
2324
import Development.IDE.Main (isLSP)
@@ -96,17 +97,20 @@ defaultMain recorder args idePlugins = do
9697
runLspMode recorder ghcideArgs idePlugins
9798

9899
VSCodeExtensionSchemaMode -> do
99-
LBS.putStrLn $ A.encodePretty $ pluginsToVSCodeExtensionSchema idePlugins
100-
100+
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToVSCodeExtensionSchema idePlugins
101101
DefaultConfigurationMode -> do
102-
LBS.putStrLn $ A.encodePretty $ pluginsToDefaultConfig idePlugins
102+
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToDefaultConfig idePlugins
103103
PrintLibDir -> do
104104
d <- getCurrentDirectory
105105
let initialFp = d </> "a"
106106
hieYaml <- Session.findCradle def initialFp
107107
cradle <- Session.loadCradle def hieYaml d
108108
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle
109109
putStr libdir
110+
where
111+
encodePrettySorted = A.encodePretty' A.defConfig
112+
{ A.confCompare = compare
113+
}
110114

111115
-- ---------------------------------------------------------------------
112116

0 commit comments

Comments
 (0)