Skip to content

Commit 0fd848b

Browse files
committed
Use HLS plugins in ghcide
For now there is only one, the main ghcide plugin. But this will allow us to break it down in more fine grained plugins with parallel semantics, both for execution and error handling
1 parent c20d322 commit 0fd848b

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

ghcide/exe/Main.hs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import Development.IDE.Types.Diagnostics
2828
import Development.IDE.Types.Options
2929
import Development.IDE.Types.Logger
3030
import Development.IDE.Plugin
31-
import Development.IDE.Plugin.Completions as Completions
32-
import Development.IDE.Plugin.CodeAction as CodeAction
3331
import Development.IDE.Plugin.Test as Test
3432
import Development.IDE.Session (loadSession)
3533
import qualified Language.Haskell.LSP.Core as LSP
@@ -54,6 +52,10 @@ import Development.IDE (action)
5452
import Text.Printf
5553
import Development.IDE.Core.Tracing
5654
import Development.IDE.Types.Shake (Key(Key))
55+
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
56+
import Development.IDE.Plugin.HLS.GhcIde as GhcIde
57+
import Ide.Plugin.Config
58+
import Ide.PluginUtils (allLspCmdIds', getProcessID, pluginDescToIdePlugins)
5759

5860
ghcideVersion :: IO String
5961
ghcideVersion = do
@@ -83,18 +85,23 @@ main = do
8385
whenJust argsCwd IO.setCurrentDirectory
8486

8587
dir <- IO.getCurrentDirectory
86-
command <- makeLspCommandId "typesignature.add"
8788

88-
let plugins = Completions.plugin <> CodeAction.plugin
89+
let hlsPlugins = pluginDescToIdePlugins [GhcIde.descriptor "ghcide"]
90+
91+
pid <- T.pack . show <$> getProcessID
92+
let hlsPlugin = asGhcIdePlugin hlsPlugins
93+
hlsCommands = allLspCmdIds' pid hlsPlugins
94+
95+
let plugins = hlsPlugin
8996
<> if argsTesting then Test.plugin else mempty
90-
onInitialConfiguration :: InitializeRequest -> Either T.Text LspConfig
97+
onInitialConfiguration :: InitializeRequest -> Either T.Text Config
9198
onInitialConfiguration x = case x ^. params . initializationOptions of
92-
Nothing -> Right defaultLspConfig
99+
Nothing -> Right def
93100
Just v -> case J.fromJSON v of
94101
J.Error err -> Left $ T.pack err
95102
J.Success a -> Right a
96103
onConfigurationChange = const $ Left "Updating Not supported"
97-
options = def { LSP.executeCommandCommands = Just [command]
104+
options = def { LSP.executeCommandCommands = Just hlsCommands
98105
, LSP.completionTriggerCharacters = Just "."
99106
}
100107

@@ -106,7 +113,7 @@ main = do
106113
t <- t
107114
hPutStrLn stderr $ "Started LSP server in " ++ showDuration t
108115
sessionLoader <- loadSession $ fromMaybe dir rootPath
109-
config <- fromMaybe defaultLspConfig <$> getConfig
116+
config <- fromMaybe def <$> getConfig
110117
let options = (defaultIdeOptions sessionLoader)
111118
{ optReportProgress = clientSupportsProgress caps
112119
, optShakeProfiling = argsShakeProfiling
@@ -159,7 +166,7 @@ main = do
159166
, optTesting = IdeTesting argsTesting
160167
, optThreads = argsThreads
161168
, optCheckParents = NeverCheck
162-
, optCheckProject = CheckProject False
169+
, optCheckProject = False
163170
}
164171
logLevel = if argsVerbose then minBound else Info
165172
ide <- initialise def mainRule (pure $ IdInt 0) (showEvent lock) dummyWithProg (const (const id)) (logger logLevel) debouncer options vfs

ghcide/ghcide.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ executable ghcide
269269
haskell-lsp-types,
270270
heapsize,
271271
hie-bios,
272+
hls-plugin-api,
272273
ghcide,
273274
lens,
274275
optparse-applicative,

0 commit comments

Comments
 (0)