@@ -2,6 +2,8 @@
3module Development.IDE.Plugin.Completions(plugin) where
3module Development.IDE.Plugin.Completions(plugin) where
5+import Control.Applicative
5import Language.Haskell.LSP.Messages
7import Language.Haskell.LSP.Messages
6import Language.Haskell.LSP.Types
8import Language.Haskell.LSP.Types
7import qualified Language.Haskell.LSP.Core as LSP
9import qualified Language.Haskell.LSP.Core as LSP
@@ -10,8 +12,6 @@ import Language.Haskell.LSP.Types.Capabilities
10import Development.Shake.Classes
12import Development.Shake.Classes
11import Development.Shake
13import Development.Shake
12import GHC.Generics
14import GHC.Generics
16import Development.IDE.Plugin
16import Development.IDE.Plugin
17import Development.IDE.Core.Service
17import Development.IDE.Core.Service
@@ -37,14 +37,14 @@ produceCompletions =
37 packageState <- fmap (hscEnv . fst) <$> useWithStale GhcSession file
37 packageState <- fmap (hscEnv . fst) <$> useWithStale GhcSession file
38 case (tm, packageState) of
38 case (tm, packageState) of
39 (Just tm', Just packageState') -> do
39 (Just tm', Just packageState') -> do
40− cdata <- liftIO $ cacheDataProducer packageState' (hsc_dflags packageState')
40+ cdata <- liftIO $ cacheDataProducer packageState'
41 (tmrModule tm') parsedDeps
41 (tmrModule tm') parsedDeps
42− return ([], Just (cdata, tm'))
42+ return ([], Just cdata)
43 _ -> return ([], Nothing)
43 _ -> return ([], Nothing)
46-- | Produce completions info for a file
46-- | Produce completions info for a file
47−type instance RuleResult ProduceCompletions = (CachedCompletions, TcModuleResult)
47+type instance RuleResult ProduceCompletions = CachedCompletions
49data ProduceCompletions = ProduceCompletions
49data ProduceCompletions = ProduceCompletions
50 deriving (Eq, Show, Typeable, Generic)
50 deriving (Eq, Show, Typeable, Generic)
@@ -67,17 +67,21 @@ getCompletionsLSP lsp ide
67 fmap Right $ case (contents, uriToFilePath' uri) of
67 fmap Right $ case (contents, uriToFilePath' uri) of
68 (Just cnts, Just path) -> do
68 (Just cnts, Just path) -> do
69 let npath = toNormalizedFilePath path
69 let npath = toNormalizedFilePath path
70+ (ideOpts, compls) <- runAction ide $ do
71+ opts <- getIdeOptions
70− (ideOpts, compls) <- runAction ide ((,) <$> getIdeOptions <*> useWithStale ProduceCompletions npath)
72+ compls <- useWithStale ProduceCompletions npath
73+ pm <- useWithStale GetParsedModule npath
74+ pure (opts, liftA2 (,) compls pm)
71 case compls of
75 case compls of
72− Just ((cci', tm'), mapping) -> do
76+ Just ((cci', _), (pm, mapping)) -> do
73− let position' = fromCurrentPosition mapping position
77+ let !position' = fromCurrentPosition mapping position
74 pfix <- maybe (return Nothing) (flip VFS.getCompletionPrefix cnts) position'
78 pfix <- maybe (return Nothing) (flip VFS.getCompletionPrefix cnts) position'
75 case (pfix, completionContext) of
79 case (pfix, completionContext) of
76 (Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."})
80 (Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."})
77 -> return (Completions $ List [])
81 -> return (Completions $ List [])
78 (Just pfix', _) -> do
82 (Just pfix', _) -> do
79 let fakeClientCapabilities = ClientCapabilities Nothing Nothing Nothing Nothing
83 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)
81 _ -> return (Completions $ List [])
85 _ -> return (Completions $ List [])
82 _ -> return (Completions $ List [])
86 _ -> return (Completions $ List [])
83 _ -> return (Completions $ List [])
87 _ -> return (Completions $ List [])