@@ -2,6 +2,8 @@
22
33module Development.IDE.Plugin.Completions(plugin) where
44
5+import Control.Applicative
6+import Data.Maybe
57import Language.Haskell.LSP.Messages
68import Language.Haskell.LSP.Types
79import qualified Language.Haskell.LSP.Core as LSP
@@ -10,8 +12,6 @@ import Language.Haskell.LSP.Types.Capabilities
1012import Development.Shake.Classes
1113import Development.Shake
1214import GHC.Generics
13−import Data.Maybe
14−import HscTypes
1515
1616import Development.IDE.Plugin
1717import Development.IDE.Core.Service
@@ -37,14 +37,14 @@ produceCompletions =
3737 packageState <- fmap (hscEnv . fst) <$> useWithStale GhcSession file
3838 case (tm, packageState) of
3939 (Just tm', Just packageState') -> do
40− cdata <- liftIO $ cacheDataProducer packageState' (hsc_dflags packageState')
40+ cdata <- liftIO $ cacheDataProducer packageState'
4141 (tmrModule tm') parsedDeps
42− return ([], Just (cdata, tm'))
42+ return ([], Just cdata)
4343 _ -> return ([], Nothing)
4444
4545
4646-- | Produce completions info for a file
47−type instance RuleResult ProduceCompletions = (CachedCompletions, TcModuleResult)
47+type instance RuleResult ProduceCompletions = CachedCompletions
4848
4949data ProduceCompletions = ProduceCompletions
5050 deriving (Eq, Show, Typeable, Generic)
@@ -67,17 +67,21 @@ getCompletionsLSP lsp ide
6767 fmap Right $ case (contents, uriToFilePath' uri) of
6868 (Just cnts, Just path) -> do
6969 let npath = toNormalizedFilePath path
70− (ideOpts, compls) <- runAction ide ((,) <$> getIdeOptions <*> useWithStale ProduceCompletions npath)
70+ (ideOpts, compls) <- runAction ide $ do
71+ opts <- getIdeOptions
72+ compls <- useWithStale ProduceCompletions npath
73+ pm <- useWithStale GetParsedModule npath
74+ pure (opts, liftA2 (,) compls pm)
7175 case compls of
72− Just ((cci', tm'), mapping) -> do
73− let position' = fromCurrentPosition mapping position
76+ Just ((cci', _), (pm, mapping)) -> do
77+ let !position' = fromCurrentPosition mapping position
7478 pfix <- maybe (return Nothing) (flip VFS.getCompletionPrefix cnts) position'
7579 case (pfix, completionContext) of
7680 (Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."})
7781 -> return (Completions $ List [])
7882 (Just pfix', _) -> do
7983 let fakeClientCapabilities = ClientCapabilities Nothing Nothing Nothing Nothing
80− Completions . List <$> getCompletions ideOpts cci' (tmrModule tm') pfix' fakeClientCapabilities (WithSnippets True)
84+ Completions . List <$> getCompletions ideOpts cci' pm pfix' fakeClientCapabilities (WithSnippets True)
8185 _ -> return (Completions $ List [])
8286 _ -> return (Completions $ List [])
8387 _ -> return (Completions $ List [])