From 6f9b43533164252327ba14ff86fa7935d6ec1d4f Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 25 Sep 2022 17:34:55 +0200 Subject: [PATCH] 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 --- ghcide/src/Development/IDE/Main.hs | 14 -------------- src/Ide/Arguments.hs | 11 +++++++++++ src/Ide/Main.hs | 12 ++++++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ghcide/src/Development/IDE/Main.hs b/ghcide/src/Development/IDE/Main.hs index e6c9d9373..a344a46dd 100644 --- a/ghcide/src/Development/IDE/Main.hs +++ b/ghcide/src/Development/IDE/Main.hs @@ -190,8 +190,6 @@ data Command | Db {hieOptions :: HieDb.Options, hieCommand :: HieDb.Command} -- ^ Run a command in the hiedb | LSP -- ^ Run the LSP server - | PrintExtensionSchema - | PrintDefaultConfig | Custom {ideCommand :: IdeCommand IdeState} -- ^ User defined deriving Show @@ -208,8 +206,6 @@ commandP plugins = hsubparser(command "typecheck" (info (Check <$> fileCmd) fileInfo) <> command "hiedb" (info (Db <$> HieDb.optParser "" True <*> HieDb.cmdParser) hieInfo) <> command "lsp" (info (pure LSP) lspInfo) - <> command "vscode-extension-schema" extensionSchemaCommand - <> command "generate-default-config" generateDefaultConfigCommand <> pluginCommands ) where @@ -217,12 +213,6 @@ commandP plugins = lspInfo = fullDesc <> progDesc "Start talking to an LSP client" fileInfo = fullDesc <> progDesc "Used as a test bed to check your IDE will work" hieInfo = fullDesc <> progDesc "Query .hie files" - extensionSchemaCommand = - info (pure PrintExtensionSchema) - (fullDesc <> progDesc "Print generic config schema for plugins (used in the package.json of haskell vscode extension)") - generateDefaultConfigCommand = - info (pure PrintDefaultConfig) - (fullDesc <> progDesc "Print config supported by the server with default values") pluginCommands = mconcat [ command (T.unpack pId) (Custom <$> p) @@ -330,10 +320,6 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re numProcessors <- getNumProcessors case argCommand of - PrintExtensionSchema -> - LT.putStrLn $ decodeUtf8 $ A.encodePretty $ pluginsToVSCodeExtensionSchema argsHlsPlugins - PrintDefaultConfig -> - LT.putStrLn $ decodeUtf8 $ A.encodePretty $ pluginsToDefaultConfig argsHlsPlugins LSP -> withNumCapabilities (maybe (numProcessors `div` 2) fromIntegral argsThreads) $ do t <- offsetTime log Info $ LogLspStart (pluginId <$> ipMap argsHlsPlugins) diff --git a/src/Ide/Arguments.hs b/src/Ide/Arguments.hs index eb87bee30..43826dbd9 100644 --- a/src/Ide/Arguments.hs +++ b/src/Ide/Arguments.hs @@ -66,6 +66,10 @@ getArguments exeName plugins = execParser opts opts = info (( VersionMode <$> printVersionParser exeName <|> probeToolsParser exeName + <|> hsubparser + ( command "vscode-extension-schema" extensionSchemaCommand + <> command "generate-default-config" generateDefaultConfigCommand + ) <|> listPluginsParser <|> BiosMode <$> biosParser <|> Ghcide <$> arguments plugins @@ -76,6 +80,13 @@ getArguments exeName plugins = execParser opts <> progDesc "Used as a test bed to check your IDE Client will work" <> header (exeName ++ " - GHC Haskell LSP server")) + extensionSchemaCommand = + info (pure VSCodeExtensionSchemaMode) + (fullDesc <> progDesc "Print generic config schema for plugins (used in the package.json of haskell vscode extension)") + generateDefaultConfigCommand = + info (pure DefaultConfigurationMode) + (fullDesc <> progDesc "Print config supported by the server with default values") + printVersionParser :: String -> Parser PrintVersion printVersionParser exeName = flag' PrintVersion diff --git a/src/Ide/Main.hs b/src/Ide/Main.hs index 7e0335741..eaf15d644 100644 --- a/src/Ide/Main.hs +++ b/src/Ide/Main.hs @@ -12,12 +12,13 @@ module Ide.Main(defaultMain, runLspMode, Log(..)) where import Control.Monad.Extra import qualified Data.Aeson.Encode.Pretty as A -import qualified Data.ByteString.Lazy.Char8 as LBS import Data.Coerce (coerce) import Data.Default import Data.List (sort) import Data.Text (Text) import qualified Data.Text as T +import Data.Text.Lazy.Encoding (decodeUtf8) +import qualified Data.Text.Lazy.IO as LT import Development.IDE.Core.Rules hiding (Log, logToPriority) import Development.IDE.Core.Tracing (withTelemetryLogger) import Development.IDE.Main (isLSP) @@ -96,10 +97,9 @@ defaultMain recorder args idePlugins = do runLspMode recorder ghcideArgs idePlugins VSCodeExtensionSchemaMode -> do - LBS.putStrLn $ A.encodePretty $ pluginsToVSCodeExtensionSchema idePlugins - + LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToVSCodeExtensionSchema idePlugins DefaultConfigurationMode -> do - LBS.putStrLn $ A.encodePretty $ pluginsToDefaultConfig idePlugins + LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToDefaultConfig idePlugins PrintLibDir -> do d <- getCurrentDirectory let initialFp = d "a" @@ -107,6 +107,10 @@ defaultMain recorder args idePlugins = do cradle <- Session.loadCradle def hieYaml d (CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle putStr libdir + where + encodePrettySorted = A.encodePretty' A.defConfig + { A.confCompare = compare + } -- ---------------------------------------------------------------------