Skip to content

Commit 04f03d9

Browse files
committed
Fix completion for qualified import
1 parent 5493fbb commit 04f03d9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

+6-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import Language.LSP.Types.Capabilities
6565
import qualified Language.LSP.VFS as VFS
6666
import Text.Fuzzy.Parallel (Scored (score),
6767
original)
68+
import Safe (fromJustNote)
6869

6970
-- Chunk size used for parallelizing fuzzy matching
7071
chunkSize :: Int
@@ -636,6 +637,8 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
636637
, enteredQual `T.isPrefixOf` original label
637638
]
638639

640+
getModuleName line = let ws = filter (/= "qualified") (T.words line)
641+
in if List.length ws >= 2 then Just (ws !! 1) else Nothing
639642
filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
640643
filterModuleExports moduleName = filtListWith $ mkModuleFunctionImport moduleName
641644
filtKeywordCompls
@@ -645,10 +648,10 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
645648
if
646649
-- TODO: handle multiline imports
647650
| "import " `T.isPrefixOf` fullLine
648-
&& (List.length (words (T.unpack fullLine)) >= 2)
649-
&& "(" `isInfixOf` T.unpack fullLine
651+
&& isJust (getModuleName fullLine)
652+
&& "(" `T.isInfixOf` fullLine
650653
-> do
651-
let moduleName = T.pack $ words (T.unpack fullLine) !! 1
654+
let moduleName = fromJustNote "NEVER FAILS: module name checked above" $ getModuleName fullLine
652655
funcs = HM.lookupDefault HashSet.empty moduleName moduleExportsMap
653656
funs = map (show . name) $ HashSet.toList funcs
654657
return $ filterModuleExports moduleName $ map T.pack funs

ghcide/test/exe/Main.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5040,8 +5040,8 @@ nonLocalCompletionTests =
50405040
"join"
50415041
["{-# LANGUAGE NoImplicitPrelude #-}",
50425042
"module A where", "import Control.Monad as M ()", "import Control.Monad as N (join)", "f = N.joi"]
5043-
-- Failing test for https://github.com/haskell/haskell-language-server/issues/2824
5044-
, expectFailBecause "known broken #2824" $ completionNoCommandTest
5043+
-- Regression test for https://github.com/haskell/haskell-language-server/issues/2824
5044+
, completionNoCommandTest
50455045
"explicit qualified"
50465046
["{-# LANGUAGE NoImplicitPrelude #-}",
50475047
"module A where", "import qualified Control.Monad as M (j)"]

0 commit comments

Comments
 (0)