Skip to content

Commit

Permalink
Use completionSnippetsOn flag (#1195)
Browse files Browse the repository at this point in the history
* Use completionSnippetsOn flag

* Enable testCase "respects lsp configuration"

* Update README: haskell.completionSnippetsOn is worked now

Co-authored-by: Junyoung/Clare Jang <jjc9310@gmail.com>
  • Loading branch information
takoeight0821 and Ailrun authored Jan 11, 2021
1 parent fde10fa commit 5685afb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
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

0 comments on commit 5685afb

Please sign in to comment.