on master help sign in
Trigger completion after dot (#313)

* Trigger completion after dot * Fix stupid mistake in test

commitc122ebdc4fbe406d8a8d4da3b46706b49e80557c authorAlejandro Serrano <trupill@gmail.com> dateFri 10 Jan 2020, 10:05 (7 years ago) parenta0aa013
3 files changed+10−4
src/Development/IDE/LSP/Completions.hs+8−3 src/Development/IDE/LSP/LanguageServer.hs+1 test/exe/Main.hs+1−1
src/Development/IDE/LSP/Completions.hs+8−3
@@ -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+1
@@ -206,6 +206,7 @@ data Message
206206modifyOptions :: LSP.Options -> LSP.Options
207207modifyOptions 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+1−1
@@ -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)