Skip to content

Use completionSnippetsOn flag #1195

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 4 commits into from
Jan 11, 2021
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Here is a list of the additional settings currently supported by `haskell-langua
- Format on imports (`haskell.formatOnImportOn`, default true): whether to format after adding an import
- Maximum number of problems to report (`haskell.maxNumberOfProblems`, default 100): the maximum number of problems the server will send to the client
- Diagnostics on change (`haskell.diagnosticsOnChange`, default true): (currently unused)
- Completion snippets (`haskell.completionSnippetsOn`, default true): whether to support completion snippets (currently unused until we have snippets to provide)
- Completion snippets (`haskell.completionSnippetsOn`, default true): whether to support completion snippets
- Liquid Haskell (`haskell.liquidOn`, default false): whether to enable Liquid Haskell support (currently unused until the Liquid Haskell support is functional again)
- Hlint (`haskell.hlintOn`, default true): whether to enable Hlint support

Expand Down
11 changes: 7 additions & 4 deletions ghcide/src/Development/IDE/Plugin/Completions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import Development.IDE.GHC.Util
import Development.IDE.LSP.Server
import TcRnDriver (tcRnImportDecls)
import Data.Maybe
import Ide.Plugin.Config (Config(completionSnippetsOn))
import Ide.PluginUtils (getClientConfig)

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

plugin :: Plugin c
plugin :: Plugin Config
plugin = Plugin produceCompletions setHandlersCompletion

produceCompletions :: Rules ()
Expand Down Expand Up @@ -116,7 +118,7 @@ instance Binary NonLocalCompletions

-- | Generate code actions.
getCompletionsLSP
:: LSP.LspFuncs cofd
:: LSP.LspFuncs Config
-> IdeState
-> CompletionParams
-> IO (Either ResponseError CompletionResponseResult)
Expand All @@ -142,12 +144,13 @@ getCompletionsLSP lsp ide
-> return (Completions $ List [])
(Just pfix', _) -> do
let clientCaps = clientCapabilities $ shakeExtras ide
Completions . List <$> getCompletions ideOpts cci' parsedMod bindMap pfix' clientCaps (WithSnippets True)
snippets <- WithSnippets . completionSnippetsOn <$> getClientConfig lsp
Completions . List <$> getCompletions ideOpts cci' parsedMod bindMap pfix' clientCaps snippets
_ -> return (Completions $ List [])
_ -> return (Completions $ List [])
_ -> return (Completions $ List [])

setHandlersCompletion :: PartialHandlers c
setHandlersCompletion :: PartialHandlers Config
setHandlersCompletion = PartialHandlers $ \WithMessage{..} x -> return x{
LSP.completionHandler = withResponse RspCompletion getCompletionsLSP
}
3 changes: 1 addition & 2 deletions test/functional/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ snippetTests = testGroup "snippets" [
item ^. insertTextFormat @?= Just Snippet
item ^. insertText @?= Just "intersperse ${1:a} ${2:[a]}"

, ignoreTestBecause "ghcide does not support the completionSnippetsOn option" $
testCase "respects lsp configuration" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
, testCase "respects lsp configuration" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
doc <- openDoc "Completion.hs" "haskell"

let config = object [ "haskell" .= (object ["completionSnippetsOn" .= False])]
Expand Down