From 5b057a448c7640a75957d4f1fe01fa16d42a1a38 Mon Sep 17 00:00:00 2001 From: Marcelo Lazaroni Date: Thu, 10 Sep 2020 21:57:32 +0100 Subject: [PATCH] Fix module suggestions --- src/Development/IDE/Plugin/Completions.hs | 2 -- .../IDE/Plugin/Completions/Logic.hs | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Development/IDE/Plugin/Completions.hs b/src/Development/IDE/Plugin/Completions.hs index 6ff30e8a0..e3bad32f5 100644 --- a/src/Development/IDE/Plugin/Completions.hs +++ b/src/Development/IDE/Plugin/Completions.hs @@ -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 diff --git a/src/Development/IDE/Plugin/Completions/Logic.hs b/src/Development/IDE/Plugin/Completions/Logic.hs index a7c406971..7b1ae2f8c 100644 --- a/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/src/Development/IDE/Plugin/Completions/Logic.hs @@ -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 prefixModule after the first letter after a dot is typed. + "import Control" -> CC { prefixModule = "" , prefixText = "Control" } + "import Control." -> CC { prefixModule = "" , prefixText = "Control" } + "import Control.C" -> CC { prefixModule = "Control", prefixText = "C" } + "import Control.Concurrent" -> CC { prefixModule = "Control", prefixText = "Concurrent" } + "import Control.Concurrent." -> CC { prefixModule = "Control", prefixText = "Concurrent" } + -} + enteredQual + | typedDot = qualifiedBit <> prefixText <> "." + | otherwise = qualifiedBit + + fullPrefix = qualifiedBit <> prefixText + {- correct the position by moving 'foo :: Int -> String -> ' ^