Skip to content

Make completions a HLS plugin #1147

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

Closed
Closed
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
4 changes: 3 additions & 1 deletion 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.HLS.Completions as Completions

-- haskell-language-server optional plugins

Expand Down Expand Up @@ -81,7 +82,8 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
then basePlugins ++ examplePlugins
else basePlugins
basePlugins =
[ GhcIde.descriptor "ghcide"
[ GhcIde.descriptor "ghcide",
Completions.descriptor "completions"
#if pragmas
, Pragmas.descriptor "pragmas"
#endif
Expand Down
3 changes: 2 additions & 1 deletion ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Development.IDE.Core.Tracing
import Development.IDE.Types.Shake (Key(Key))
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
import Development.IDE.Plugin.HLS.GhcIde as GhcIde
import Development.IDE.Plugin.HLS.Completions as Completions
import Ide.Plugin.Config
import Ide.PluginUtils (allLspCmdIds', getProcessID, pluginDescToIdePlugins)

Expand Down Expand Up @@ -86,7 +87,7 @@ main = do

dir <- IO.getCurrentDirectory

let hlsPlugins = pluginDescToIdePlugins [GhcIde.descriptor "ghcide"]
let hlsPlugins = pluginDescToIdePlugins [GhcIde.descriptor "ghcide", Completions.descriptor "completions"]

pid <- T.pack . show <$> getProcessID
let hlsPlugin = asGhcIdePlugin hlsPlugins
Expand Down
1 change: 1 addition & 0 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ library
Development.IDE.Plugin.CodeAction
Development.IDE.Plugin.HLS
Development.IDE.Plugin.HLS.GhcIde
Development.IDE.Plugin.HLS.Completions
Development.IDE.Plugin.Test

-- Unfortunately, we cannot use loadSession with ghc-lib since hie-bios uses
Expand Down
30 changes: 30 additions & 0 deletions ghcide/src/Development/IDE/Plugin/HLS/Completions.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Exposes the ghcide features as an HLS plugin
module Development.IDE.Plugin.HLS.Completions
(
descriptor
) where

import Data.Aeson
import Development.IDE
import Development.IDE.Plugin as Ghcide
import Development.IDE.Plugin.Completions as Completions
import Ide.PluginUtils
import Ide.Types
import Language.Haskell.LSP.Types
import Text.Regex.TDFA.Text()

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

descriptor :: PluginId -> PluginDescriptor IdeState
descriptor plId = (defaultPluginDescriptor plId)
{ pluginCommands = []
, pluginCodeActionProvider = Nothing
, pluginCodeLensProvider = Nothing
, pluginHoverProvider = Nothing
, pluginSymbolsProvider = Nothing
, pluginCompletionProvider = Just getCompletionsLSP
, pluginRules = Ghcide.pluginRules Completions.plugin
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, we can move code in Plugins/Completions.hs into this module and get rid of that module. That will reduce this redirection which seems redudant.

Any thoughts?

4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Plugin/HLS/GhcIde.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ descriptor plId = (defaultPluginDescriptor plId)
, pluginCodeLensProvider = Just codeLens'
, pluginHoverProvider = Just hover'
, pluginSymbolsProvider = Just symbolsProvider
, pluginCompletionProvider = Just getCompletionsLSP
, pluginRules = Ghcide.pluginRules Completions.plugin <> Ghcide.pluginRules CodeAction.plugin
, pluginCompletionProvider = Nothing
, pluginRules = Ghcide.pluginRules CodeAction.plugin
}

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