@@ -65,6 +65,7 @@ import Language.LSP.Types.Capabilities
65
65
import qualified Language.LSP.VFS as VFS
66
66
import Text.Fuzzy.Parallel (Scored (score ),
67
67
original )
68
+ import Safe (fromJustNote )
68
69
69
70
-- Chunk size used for parallelizing fuzzy matching
70
71
chunkSize :: Int
@@ -636,6 +637,8 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
636
637
, enteredQual `T.isPrefixOf` original label
637
638
]
638
639
640
+ getModuleName line = let ws = filter (/= " qualified" ) (T. words line)
641
+ in if List. length ws >= 2 then Just (ws !! 1 ) else Nothing
639
642
filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
640
643
filterModuleExports moduleName = filtListWith $ mkModuleFunctionImport moduleName
641
644
filtKeywordCompls
@@ -645,10 +648,10 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
645
648
if
646
649
-- TODO: handle multiline imports
647
650
| " 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
650
653
-> do
651
- let moduleName = T. pack $ words ( T. unpack fullLine) !! 1
654
+ let moduleName = fromJustNote " NEVER FAILS: module name checked above " $ getModuleName fullLine
652
655
funcs = HM. lookupDefault HashSet. empty moduleName moduleExportsMap
653
656
funs = map (show . name) $ HashSet. toList funcs
654
657
return $ filterModuleExports moduleName $ map T. pack funs
0 commit comments