Skip to content

Sort vscode extension schema json by keys #3203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions ghcide/src/Development/IDE/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines -193 to -194
Copy link
Collaborator Author

@fendor fendor Sep 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone who was wondering, this was the actual codepath taken, instead of VSCodeExtensionSchemaMode from src/Ide/Main.hs. That used to be dead-code.

| Custom {ideCommand :: IdeCommand IdeState} -- ^ User defined
deriving Show

Expand All @@ -208,21 +206,13 @@ 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
fileCmd = many (argument str (metavar "FILES/DIRS..."))
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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/Ide/Arguments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/Ide/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -96,17 +97,20 @@ 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"
hieYaml <- Session.findCradle def initialFp
cradle <- Session.loadCradle def hieYaml d
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle
putStr libdir
where
encodePrettySorted = A.encodePretty' A.defConfig
{ A.confCompare = compare
}

-- ---------------------------------------------------------------------

Expand Down