Trigger completion after dot (#313)

* Trigger completion after dot

* Fix stupid mistake in test
This commit is contained in:
Alejandro Serrano 2020-01-10 10:05:44 +01:00 committed by Andreas Herrmann
parent a0aa013e33
commit c122ebdc4f
3 changed files with 10 additions and 4 deletions

View File

@ -22,7 +22,10 @@ getCompletionsLSP
-> IdeState
-> CompletionParams
-> IO CompletionResponseResult
getCompletionsLSP lsp ide CompletionParams{_textDocument=TextDocumentIdentifier uri,_position=position} = do
getCompletionsLSP lsp ide
CompletionParams{_textDocument=TextDocumentIdentifier uri
,_position=position
,_context=completionContext} = do
contents <- LSP.getVirtualFileFunc lsp $ toNormalizedUri uri
case (contents, uriToFilePath' uri) of
(Just cnts, Just path) -> do
@ -32,8 +35,10 @@ getCompletionsLSP lsp ide CompletionParams{_textDocument=TextDocumentIdentifier
Just ((cci', tm'), mapping) -> do
let position' = fromCurrentPosition mapping position
pfix <- maybe (return Nothing) (flip VFS.getCompletionPrefix cnts) position'
case pfix of
Just pfix' -> do
case (pfix, completionContext) of
(Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."})
-> return (Completions $ List [])
(Just pfix', _) -> do
let fakeClientCapabilities = ClientCapabilities Nothing Nothing Nothing Nothing
Completions . List <$> getCompletions ideOpts cci' (tmrModule tm') pfix' fakeClientCapabilities (WithSnippets True)
_ -> return (Completions $ List [])

View File

@ -206,6 +206,7 @@ data Message
modifyOptions :: LSP.Options -> LSP.Options
modifyOptions x = x{ LSP.textDocumentSync = Just $ tweakTDS origTDS
, LSP.executeCommandCommands = Just ["typesignature.add"]
, LSP.completionTriggerCharacters = Just "."
}
where
tweakTDS tds = tds{_openClose=Just True, _change=Just TdSyncIncremental, _save=Just $ SaveOptions Nothing}

View File

@ -67,7 +67,7 @@ initializeResponseTests = withResource acquire release tests where
testGroup "initialize response capabilities"
[ chk " text doc sync" _textDocumentSync tds
, chk " hover" _hoverProvider (Just True)
, chk " completion" _completionProvider (Just $ CompletionOptions (Just False) Nothing Nothing)
, chk " completion" _completionProvider (Just $ CompletionOptions (Just False) (Just ["."]) Nothing)
, chk "NO signature help" _signatureHelpProvider Nothing
, chk " goto definition" _definitionProvider (Just True)
, chk "NO goto type definition" _typeDefinitionProvider (Just $ GotoOptionsStatic False)