@@ -65,6 +65,7 @@ import Language.LSP.Types.Capabilities
6565import qualified Language.LSP.VFS as VFS
6666import Text.Fuzzy.Parallel (Scored (score ),
6767 original )
68+ import Safe (fromJustNote )
6869
6970-- Chunk size used for parallelizing fuzzy matching
7071chunkSize :: 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
0 commit comments