Skip to content

Commit d656731

Browse files
committed
Fix completion for qualified import
1 parent e14f12d commit d656731

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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

Lines changed: 6 additions & 3 deletions
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

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

0 commit comments

Comments
 (0)