Skip to content

Commit c122ebd

Browse files
serrasaherrmann-da
authored andcommitted
Trigger completion after dot (#313)
* Trigger completion after dot * Fix stupid mistake in test
1 parent a0aa013 commit c122ebd

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/Development/IDE/LSP/Completions.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ getCompletionsLSP
2222
-> IdeState
2323
-> CompletionParams
2424
-> IO CompletionResponseResult
25-
getCompletionsLSP lsp ide CompletionParams{_textDocument=TextDocumentIdentifier uri,_position=position} = do
25+
getCompletionsLSP lsp ide
26+
CompletionParams{_textDocument=TextDocumentIdentifier uri
27+
,_position=position
28+
,_context=completionContext} = do
2629
contents <- LSP.getVirtualFileFunc lsp $ toNormalizedUri uri
2730
case (contents, uriToFilePath' uri) of
2831
(Just cnts, Just path) -> do
@@ -32,8 +35,10 @@ getCompletionsLSP lsp ide CompletionParams{_textDocument=TextDocumentIdentifier
3235
Just ((cci', tm'), mapping) -> do
3336
let position' = fromCurrentPosition mapping position
3437
pfix <- maybe (return Nothing) (flip VFS.getCompletionPrefix cnts) position'
35-
case pfix of
36-
Just pfix' -> do
38+
case (pfix, completionContext) of
39+
(Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."})
40+
-> return (Completions $ List [])
41+
(Just pfix', _) -> do
3742
let fakeClientCapabilities = ClientCapabilities Nothing Nothing Nothing Nothing
3843
Completions . List <$> getCompletions ideOpts cci' (tmrModule tm') pfix' fakeClientCapabilities (WithSnippets True)
3944
_ -> return (Completions $ List [])

src/Development/IDE/LSP/LanguageServer.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ data Message
206206
modifyOptions :: LSP.Options -> LSP.Options
207207
modifyOptions x = x{ LSP.textDocumentSync = Just $ tweakTDS origTDS
208208
, LSP.executeCommandCommands = Just ["typesignature.add"]
209+
, LSP.completionTriggerCharacters = Just "."
209210
}
210211
where
211212
tweakTDS tds = tds{_openClose=Just True, _change=Just TdSyncIncremental, _save=Just $ SaveOptions Nothing}

test/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ initializeResponseTests = withResource acquire release tests where
6767
testGroup "initialize response capabilities"
6868
[ chk " text doc sync" _textDocumentSync tds
6969
, chk " hover" _hoverProvider (Just True)
70-
, chk " completion" _completionProvider (Just $ CompletionOptions (Just False) Nothing Nothing)
70+
, chk " completion" _completionProvider (Just $ CompletionOptions (Just False) (Just ["."]) Nothing)
7171
, chk "NO signature help" _signatureHelpProvider Nothing
7272
, chk " goto definition" _definitionProvider (Just True)
7373
, chk "NO goto type definition" _typeDefinitionProvider (Just $ GotoOptionsStatic False)

0 commit comments

Comments
 (0)