Skip to content

Break down ghcide functionality in HLS plugins #1257

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 8 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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).
  • Loading branch information
pepeiborra committed Jan 24, 2021
commit d59cac402b90d88ea665764cd0b900a2b254403c
2 changes: 2 additions & 0 deletions exe/Plugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Ide.Plugin.Example as Example
import Ide.Plugin.Example2 as Example2
import Development.IDE (IdeState)
import Development.IDE.Plugin.HLS.GhcIde as GhcIde
import Development.IDE.Plugin.Completions as Completions
import Development.IDE.Plugin.TypeLenses as TypeLenses

-- haskell-language-server optional plugins
Expand Down Expand Up @@ -92,6 +93,7 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
basePlugins =
[ GhcIde.descriptor "ghcide"
, TypeLenses.descriptor "type-lenses"
, Completions.descriptor "completions"
#if pragmas
, Pragmas.descriptor "pragmas"
#endif
Expand Down
2 changes: 2 additions & 0 deletions ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Options
import Development.IDE.Types.Logger
import Development.IDE.Plugin
import Development.IDE.Plugin.Completions as Completions
import Development.IDE.Plugin.TypeLenses as TypeLenses
import Development.IDE.Plugin.Test as Test
import Development.IDE.Session (loadSession)
Expand Down Expand Up @@ -91,6 +92,7 @@ main = do
let hlsPlugins = pluginDescToIdePlugins $
[ GhcIde.descriptor "ghcide"
, TypeLenses.descriptor "type-lenses"
, Completions.descriptor "ghcide-completions"
] ++
[ Test.blockCommandDescriptor "block-command" | argsTesting]

Expand Down
15 changes: 12 additions & 3 deletions ghcide/src/Development/IDE/Plugin/Completions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#include "ghc-api-version.h"

module Development.IDE.Plugin.Completions
(
produceCompletions
, getCompletionsLSP
( descriptor
, ProduceCompletions(..)
, LocalCompletions(..)
, NonLocalCompletions(..)
) where
import Language.Haskell.LSP.Types
import qualified Language.Haskell.LSP.Core as LSP
Expand All @@ -27,10 +28,18 @@ import TcRnDriver (tcRnImportDecls)
import Data.Maybe
import Ide.Plugin.Config (Config (completionSnippetsOn))
import Ide.PluginUtils (getClientConfig)
import Ide.Types

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

descriptor :: PluginId -> PluginDescriptor IdeState
descriptor plId = (defaultPluginDescriptor plId)
{ pluginRules = produceCompletions
, pluginCompletionProvider = Just getCompletionsLSP
}

produceCompletions :: Rules ()
produceCompletions = do
define $ \ProduceCompletions file -> do
Expand Down
4 changes: 1 addition & 3 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ import Development.IDE.GHC.Util
import Outputable (Outputable)
import qualified Data.Set as Set
import ConLike

import GhcPlugins (
flLabel,
unpackFS)
import Data.Either (fromRight)
import Ide.Types(WithSnippets(..))

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

Expand Down Expand Up @@ -443,8 +443,6 @@ findRecordCompl _ _ _ = []
ppr :: Outputable a => a -> T.Text
ppr = T.pack . prettyPrint

newtype WithSnippets = WithSnippets Bool

toggleSnippets :: ClientCapabilities -> WithSnippets -> CompletionItem -> CompletionItem
toggleSnippets ClientCapabilities { _textDocument } (WithSnippets with) x
| with && supported = x
Expand Down
4 changes: 1 addition & 3 deletions ghcide/src/Development/IDE/Plugin/HLS/GhcIde.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Development.IDE.Plugin.HLS.GhcIde
descriptor
) where
import Development.IDE
import Development.IDE.Plugin.Completions as Completions
import Development.IDE.Plugin.CodeAction as CodeAction
import Development.IDE.LSP.HoverDefinition
import Development.IDE.LSP.Outline
Expand All @@ -23,8 +22,7 @@ descriptor plId = (defaultPluginDescriptor plId)
{ pluginCodeActionProvider = Just codeAction'
, pluginHoverProvider = Just hover'
, pluginSymbolsProvider = Just symbolsProvider
, pluginCompletionProvider = Just getCompletionsLSP
, pluginRules = produceCompletions <> rulePackageExports
, pluginRules = rulePackageExports
}

-- ---------------------------------------------------------------------
Expand Down