Skip to content

Commit 6f9b435

Browse files
fendormergify[bot]michaelpj
authored
Sort vscode extension schema json by keys (#3203)
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. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Michael Peyton Jones <[email protected]>
1 parent c422cf3 commit 6f9b435

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
@@ -190,8 +190,6 @@ data Command
190190
| Db {hieOptions :: HieDb.Options, hieCommand :: HieDb.Command}
191191
-- ^ Run a command in the hiedb
192192
| LSP -- ^ Run the LSP server
193-
| PrintExtensionSchema
194-
| PrintDefaultConfig
195193
| Custom {ideCommand :: IdeCommand IdeState} -- ^ User defined
196194
deriving Show
197195

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

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

332322
case argCommand of
333-
PrintExtensionSchema ->
334-
LT.putStrLn $ decodeUtf8 $ A.encodePretty $ pluginsToVSCodeExtensionSchema argsHlsPlugins
335-
PrintDefaultConfig ->
336-
LT.putStrLn $ decodeUtf8 $ A.encodePretty $ pluginsToDefaultConfig argsHlsPlugins
337323
LSP -> withNumCapabilities (maybe (numProcessors `div` 2) fromIntegral argsThreads) $ do
338324
t <- offsetTime
339325
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)