Skip to content

Commit b85e6eb

Browse files
committed
Extract completions into an HLS plugin
We might want to break them down into multiple HLS plugins later on (local, non local, and module header).
1 parent fb9dbc7 commit b85e6eb

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

exe/Plugins.hs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Ide.Plugin.Example as Example
1010
import Ide.Plugin.Example2 as Example2
1111
import Development.IDE (IdeState)
1212
import Development.IDE.Plugin.HLS.GhcIde as GhcIde
13+
import Development.IDE.Plugin.Completions as Completions
1314
import Development.IDE.Plugin.TypeLenses as TypeLenses
1415

1516
-- haskell-language-server optional plugins
@@ -92,6 +93,7 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
9293
basePlugins =
9394
[ GhcIde.descriptor "ghcide"
9495
, TypeLenses.descriptor "type-lenses"
96+
, Completions.descriptor "completions"
9597
#if pragmas
9698
, Pragmas.descriptor "pragmas"
9799
#endif

ghcide/exe/Main.hs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ 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
3132
import Development.IDE.Plugin.TypeLenses as TypeLenses
3233
import Development.IDE.Plugin.Test as Test
3334
import Development.IDE.Session (loadSession)
@@ -91,6 +92,7 @@ main = do
9192
let hlsPlugins = pluginDescToIdePlugins $
9293
[ GhcIde.descriptor "ghcide"
9394
, TypeLenses.descriptor "type-lenses"
95+
, Completions.descriptor "ghcide-completions"
9496
] ++
9597
[ Test.blockCommandDescriptor "block-command" | argsTesting]
9698

ghcide/src/Development/IDE/Plugin/Completions.hs

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include "ghc-api-version.h"
44

55
module Development.IDE.Plugin.Completions
6-
(
7-
produceCompletions
8-
, getCompletionsLSP
6+
( descriptor
7+
, ProduceCompletions(..)
8+
, LocalCompletions(..)
9+
, NonLocalCompletions(..)
910
) where
1011
import Language.Haskell.LSP.Types
1112
import qualified Language.Haskell.LSP.Core as LSP
@@ -27,6 +28,13 @@ import TcRnDriver (tcRnImportDecls)
2728
import Data.Maybe
2829
import Ide.Plugin.Config (Config (completionSnippetsOn))
2930
import Ide.PluginUtils (getClientConfig)
31+
import Ide.Types
32+
33+
descriptor :: PluginId -> PluginDescriptor IdeState
34+
descriptor plId = (defaultPluginDescriptor plId)
35+
{ pluginRules = produceCompletions
36+
, pluginCompletionProvider = Just getCompletionsLSP
37+
}
3038

3139
#if defined(GHC_LIB)
3240
import Development.IDE.Import.DependencyInformation

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ import Development.IDE.GHC.Util
4949
import Outputable (Outputable)
5050
import qualified Data.Set as Set
5151
import ConLike
52-
5352
import GhcPlugins (
5453
flLabel,
5554
unpackFS)
5655
import Data.Either (fromRight)
56+
import Ide.Types(WithSnippets(..))
5757

5858
-- From haskell-ide-engine/hie-plugin-api/Haskell/Ide/Engine/Context.hs
5959

@@ -443,8 +443,6 @@ findRecordCompl _ _ _ = []
443443
ppr :: Outputable a => a -> T.Text
444444
ppr = T.pack . prettyPrint
445445

446-
newtype WithSnippets = WithSnippets Bool
447-
448446
toggleSnippets :: ClientCapabilities -> WithSnippets -> CompletionItem -> CompletionItem
449447
toggleSnippets ClientCapabilities { _textDocument } (WithSnippets with) x
450448
| with && supported = x

ghcide/src/Development/IDE/Plugin/HLS/GhcIde.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Development.IDE.Plugin.HLS.GhcIde
77
descriptor
88
) where
99
import Development.IDE
10-
import Development.IDE.Plugin.Completions as Completions
1110
import Development.IDE.Plugin.CodeAction as CodeAction
1211
import Development.IDE.LSP.HoverDefinition
1312
import Development.IDE.LSP.Outline
@@ -23,8 +22,7 @@ descriptor plId = (defaultPluginDescriptor plId)
2322
{ pluginCodeActionProvider = Just codeAction'
2423
, pluginHoverProvider = Just hover'
2524
, pluginSymbolsProvider = Just symbolsProvider
26-
, pluginCompletionProvider = Just getCompletionsLSP
27-
, pluginRules = produceCompletions <> rulePackageExports
25+
, pluginRules = rulePackageExports
2826
}
2927

3028
-- ---------------------------------------------------------------------

0 commit comments

Comments
 (0)