Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Fix module suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lazamar committed Sep 13, 2020
1 parent f79e930 commit 1e8588f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/Development/IDE/Plugin/Completions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ getCompletionsLSP lsp ide
let !position' = fromCurrentPosition mapping position
pfix <- maybe (return Nothing) (flip VFS.getCompletionPrefix cnts) position'
case (pfix, completionContext) of
(Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."})
-> return (Completions $ List [])
(Just pfix', _) -> do
-- TODO pass the real capabilities here (or remove the logic for snippets)
let fakeClientCapabilities = ClientCapabilities Nothing Nothing Nothing Nothing
Expand Down
25 changes: 22 additions & 3 deletions src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,28 @@ toggleSnippets ClientCapabilities { _textDocument } (WithSnippets with) x
getCompletions :: IdeOptions -> CachedCompletions -> ParsedModule -> VFS.PosPrefixInfo -> ClientCapabilities -> WithSnippets -> IO [CompletionItem]
getCompletions ideOpts CC { allModNamesAsNS, unqualCompls, qualCompls, importableModules }
pm prefixInfo caps withSnippets = do
let VFS.PosPrefixInfo { VFS.fullLine, VFS.prefixModule, VFS.prefixText } = prefixInfo
enteredQual = if T.null prefixModule then "" else prefixModule <> "."
fullPrefix = enteredQual <> prefixText
let VFS.PosPrefixInfo { VFS.fullLine, VFS.prefixModule, VFS.prefixText, VFS.cursorPos } = prefixInfo
maybeIndex ix = T.take 1 . T.drop ix

typedDot = "." == maybeIndex (_character cursorPos) fullLine

qualifiedBit
| T.null prefixModule = ""
| otherwise = prefixModule <> "."

{- Items are only added to prefix module after the first letter.
"Control" -> CC { prefixModule = "" , prefixText = "Control" }
"Control." -> CC { prefixModule = "" , prefixText = "Control" }
"Control.C" -> CC { prefixModule = "Control", prefixText = "C" }
"Control.Concurrent" -> CC { prefixModule = "Control", prefixText = "Concurrent" }
"Control.Concurrent." -> CC { prefixModule = "Control", prefixText = "Concurrent" }
-}
enteredQual
| typedDot = qualifiedBit <> prefixText <> "."
| otherwise = qualifiedBit

fullPrefix = qualifiedBit <> prefixText


{- correct the position by moving 'foo :: Int -> String -> '
^
Expand Down

0 comments on commit 1e8588f

Please sign in to comment.