on master help sign in
Move the completions and code actions into Plugin (#359)

* Move the completions into a Plugin pile * Fix HLint * Turn CodeAction into a plugin as well * Fix HLint * Remove a redundant def <>

commit3ccebde8671e55e3163b7f5161fd6cdc775e9763 authorNeil Mitchell <ndmitchell@gmail.com> dateSun 26 Jan 2020, 09:36 (7 years ago) parent0992bc7
10 files changed+61−46
.hlint.yaml+2−2 exe/Main.hs+11−2 ghcide.cabal+4−4 src/Development/IDE/Core/RuleTypes.hs−10 src/Development/IDE/Core/Rules.hs+1−16 src/Development/IDE/LSP/LanguageServer.hs−4 src/Development/IDE/LSP/CodeAction.hs → src/Development/IDE/Plugin/CodeAction.hs+1−1 src/Development/IDE/LSP/Completions.hs → src/Development/IDE/Plugin/Completions.hs+38−3 src/Development/IDE/Core/Completions.hs → src/Development/IDE/Plugin/Completions/Logic.hs+2−2 src/Development/IDE/Core/CompletionsTypes.hs → src/Development/IDE/Plugin/Completions/Types.hs+2−2
.hlint.yaml+2−2
@@ -76,16 +76,16 @@
7676 - {name: ImplicitParams, within: []}
7777 - name: CPP
7878 within:
79− - Development.IDE.Core.Completions
8079 - Development.IDE.Core.FileStore
8180 - Development.IDE.Core.Compile
8281 - Development.IDE.GHC.Compat
8382 - Development.IDE.GHC.Util
8483 - Development.IDE.Import.FindImports
85− - Development.IDE.LSP.CodeAction
8684 - Development.IDE.Spans.Calculate
8785 - Development.IDE.Spans.Documentation
8886 - Development.IDE.Spans.Common
87+ - Development.IDE.Plugin.CodeAction
88+ - Development.IDE.Plugin.Completions.Logic
8989 - Main
9090
9191- flags:
exe/Main.hs+11−2
@@ -28,6 +28,8 @@ import Development.IDE.Types.Diagnostics
2828import Development.IDE.Types.Options
2929import Development.IDE.Types.Logger
3030import Development.IDE.GHC.Util
31+import Development.IDE.Plugin.Completions
32+import Development.IDE.Plugin.CodeAction
3133import qualified Data.Text as T
3234import qualified Data.Text.IO as T
3335import Language.Haskell.LSP.Messages
@@ -83,11 +85,18 @@ main = do
8385
8486 dir <- getCurrentDirectory
8587
88+ let handlers =
89+ setHandlersCompletion <>
90+ setHandlersCodeAction <> setHandlersCodeLens
91+ let rules = do
92+ mainRule
93+ produceCompletions
94+
8695 if argLSP then do
8796 t <- offsetTime
8897 hPutStrLn stderr "Starting LSP server..."
8998 hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcidie WITHOUT the --lsp option!"
90− runLanguageServer def def $ \getLspId event vfs caps -> do
99+ runLanguageServer def handlers $ \getLspId event vfs caps -> do
91100 t <- t
92101 hPutStrLn stderr $ "Started LSP server in " ++ showDuration t
93102 -- very important we only call loadSession once, and it's fast, so just do it before starting
@@ -96,7 +105,7 @@ main = do
96105 { optReportProgress = clientSupportsProgress caps
97106 , optShakeProfiling = argsShakeProfiling
98107 }
99− initialise caps (mainRule >> action kick) getLspId event (logger minBound) options vfs
108+ initialise caps (rules >> action kick) getLspId event (logger minBound) options vfs
100109 else do
101110 putStrLn $ "Ghcide setup tester in " ++ dir ++ "."
102111 putStrLn "Report bugs at https://github.com/digital-asset/ghcide/issues"
ghcide.cabal+4−4
@@ -99,8 +99,6 @@ library
9999 include-dirs:
100100 include
101101 exposed-modules:
102− Development.IDE.Core.Completions
103− Development.IDE.Core.CompletionsTypes
104102 Development.IDE.Core.FileStore
105103 Development.IDE.Core.OfInterest
106104 Development.IDE.Core.PositionMapping
@@ -117,6 +115,8 @@ library
117115 Development.IDE.Types.Location
118116 Development.IDE.Types.Logger
119117 Development.IDE.Types.Options
118+ Development.IDE.Plugin.Completions
119+ Development.IDE.Plugin.CodeAction
120120 other-modules:
121121 Development.IDE.Core.Debouncer
122122 Development.IDE.Core.Compile
@@ -128,8 +128,6 @@ library
128128 Development.IDE.GHC.Orphans
129129 Development.IDE.GHC.Warnings
130130 Development.IDE.Import.FindImports
131− Development.IDE.LSP.CodeAction
132− Development.IDE.LSP.Completions
133131 Development.IDE.LSP.HoverDefinition
134132 Development.IDE.LSP.Notifications
135133 Development.IDE.LSP.Outline
@@ -138,6 +136,8 @@ library
138136 Development.IDE.Spans.Common
139137 Development.IDE.Spans.Documentation
140138 Development.IDE.Spans.Type
139+ Development.IDE.Plugin.Completions.Logic
140+ Development.IDE.Plugin.Completions.Types
141141 ghc-options: -Wall -Wno-name-shadowing
142142
143143executable ghcide-test-preprocessor
src/Development/IDE/Core/RuleTypes.hs−10
@@ -27,7 +27,6 @@ import Module (InstalledUnitId)
2727import HscTypes (CgGuts, Linkable, HomeModInfo, ModDetails)
2828import Development.IDE.GHC.Compat
2929
30−import Development.IDE.Core.CompletionsTypes
3130import Development.IDE.Spans.Type
3231
3332
@@ -86,9 +85,6 @@ type instance RuleResult ReportImportCycles = ()
8685-- | Read the given HIE file.
8786type instance RuleResult GetHieFile = HieFile
8887
89−-- | Produce completions info for a file
90−type instance RuleResult ProduceCompletions = (CachedCompletions, TcModuleResult)
91−
9288
9389data GetParsedModule = GetParsedModule
9490 deriving (Eq, Show, Typeable, Generic)
@@ -157,9 +153,3 @@ data GetHieFile = GetHieFile FilePath
157153instance Hashable GetHieFile
158154instance NFData GetHieFile
159155instance Binary GetHieFile
160−
161−data ProduceCompletions = ProduceCompletions
162− deriving (Eq, Show, Typeable, Generic)
163−instance Hashable ProduceCompletions
164−instance NFData ProduceCompletions
165−instance Binary ProduceCompletions
src/Development/IDE/Core/Rules.hs+1−16
@@ -32,7 +32,6 @@ import Control.Monad
3232import Control.Monad.Trans.Class
3333import Control.Monad.Trans.Maybe
3434import Development.IDE.Core.Compile
35−import Development.IDE.Core.Completions
3635import Development.IDE.Types.Options
3736import Development.IDE.Spans.Calculate
3837import Development.IDE.Import.DependencyInformation
@@ -307,20 +306,6 @@ generateCoreRule :: Rules ()
307306generateCoreRule =
308307 define $ \GenerateCore -> generateCore
309308
310−produceCompletions :: Rules ()
311−produceCompletions =
312− define $ \ProduceCompletions file -> do
313− deps <- maybe (TransitiveDependencies [] []) fst <$> useWithStale GetDependencies file
314− tms <- mapMaybe (fmap fst) <$> usesWithStale TypeCheck (transitiveModuleDeps deps)
315− tm <- fmap fst <$> useWithStale TypeCheck file
316− packageState <- fmap (hscEnv . fst) <$> useWithStale GhcSession file
317− case (tm, packageState) of
318− (Just tm', Just packageState') -> do
319− cdata <- liftIO $ cacheDataProducer packageState' (hsc_dflags packageState')
320− (tmrModule tm') (map tmrModule tms)
321− return ([], Just (cdata, tm'))
322− _ -> return ([], Nothing)
323−
324309generateByteCodeRule :: Rules ()
325310generateByteCodeRule =
326311 define $ \GenerateByteCode file -> do
@@ -378,7 +363,7 @@ mainRule = do
378363 generateByteCodeRule
379364 loadGhcSession
380365 getHieFileRule
381− produceCompletions
366+
382367
383368------------------------------------------------------------
384369
src/Development/IDE/LSP/LanguageServer.hs−4
@@ -29,8 +29,6 @@ import System.IO
2929import Control.Monad.Extra
3030
3131import Development.IDE.LSP.HoverDefinition
32−import Development.IDE.LSP.CodeAction
33−import Development.IDE.LSP.Completions
3432import Development.IDE.LSP.Notifications
3533import Development.IDE.LSP.Outline
3634import Development.IDE.Core.Service
@@ -98,8 +96,6 @@ runLanguageServer options userHandlers getIdeState = do
9896 let PartialHandlers parts =
9997 setHandlersIgnore <> -- least important
10098 setHandlersDefinition <> setHandlersHover <>
101− setHandlersCodeAction <> setHandlersCodeLens <> -- useful features someone may override
102− setHandlersCompletion <>
10399 setHandlersOutline <>
104100 userHandlers <>
105101 setHandlersNotifications <> -- absolutely critical, join them with user notifications
src/Development/IDE/LSP/CodeAction.hs → src/Development/IDE/Plugin/CodeAction.hsrenamed+1−1
@@ -6,7 +6,7 @@
66#include "ghc-api-version.h"
77
88-- | Go to the definition of a variable.
9−module Development.IDE.LSP.CodeAction
9+module Development.IDE.Plugin.CodeAction
1010 ( setHandlersCodeAction
1111 , setHandlersCodeLens
1212 ) where
src/Development/IDE/LSP/Completions.hs → src/Development/IDE/Plugin/Completions.hsrenamed+38−3
@@ -1,5 +1,7 @@
1−module Development.IDE.LSP.Completions (
2− setHandlersCompletion
1+{-# LANGUAGE TypeFamilies #-}
2+
3+module Development.IDE.Plugin.Completions (
4+ setHandlersCompletion, produceCompletions
35) where
46
57import Language.Haskell.LSP.Messages
@@ -7,14 +9,47 @@ import Language.Haskell.LSP.Types
79import qualified Language.Haskell.LSP.Core as LSP
810import qualified Language.Haskell.LSP.VFS as VFS
911import Language.Haskell.LSP.Types.Capabilities
12+import Development.Shake.Classes
13+import Development.Shake
14+import GHC.Generics
15+import Data.Maybe
16+import HscTypes
1017
1118import Development.IDE.Core.Service
12−import Development.IDE.Core.Completions
19+import Development.IDE.Plugin.Completions.Logic
1320import Development.IDE.Types.Location
1421import Development.IDE.Core.PositionMapping
1522import Development.IDE.Core.RuleTypes
1623import Development.IDE.Core.Shake
24+import Development.IDE.GHC.Util
1725import Development.IDE.LSP.Server
26+import Development.IDE.Import.DependencyInformation
27+
28+
29+produceCompletions :: Rules ()
30+produceCompletions =
31+ define $ \ProduceCompletions file -> do
32+ deps <- maybe (TransitiveDependencies [] []) fst <$> useWithStale GetDependencies file
33+ tms <- mapMaybe (fmap fst) <$> usesWithStale TypeCheck (transitiveModuleDeps deps)
34+ tm <- fmap fst <$> useWithStale TypeCheck file
35+ packageState <- fmap (hscEnv . fst) <$> useWithStale GhcSession file
36+ case (tm, packageState) of
37+ (Just tm', Just packageState') -> do
38+ cdata <- liftIO $ cacheDataProducer packageState' (hsc_dflags packageState')
39+ (tmrModule tm') (map tmrModule tms)
40+ return ([], Just (cdata, tm'))
41+ _ -> return ([], Nothing)
42+
43+
44+-- | Produce completions info for a file
45+type instance RuleResult ProduceCompletions = (CachedCompletions, TcModuleResult)
46+
47+data ProduceCompletions = ProduceCompletions
48+ deriving (Eq, Show, Typeable, Generic)
49+instance Hashable ProduceCompletions
50+instance NFData ProduceCompletions
51+instance Binary ProduceCompletions
52+
1853
1954-- | Generate code actions.
2055getCompletionsLSP
src/Development/IDE/Core/Completions.hs → src/Development/IDE/Plugin/Completions/Logic.hsrenamed+2−2
@@ -1,6 +1,6 @@
11{-# LANGUAGE CPP #-}
22-- Mostly taken from "haskell-ide-engine"
3−module Development.IDE.Core.Completions (
3+module Development.IDE.Plugin.Completions.Logic (
44 CachedCompletions
55, cacheDataProducer
66, WithSnippets(..)
@@ -29,7 +29,7 @@ import DynFlags
2929import Language.Haskell.LSP.Types
3030import Language.Haskell.LSP.Types.Capabilities
3131import qualified Language.Haskell.LSP.VFS as VFS
32−import Development.IDE.Core.CompletionsTypes
32+import Development.IDE.Plugin.Completions.Types
3333import Development.IDE.Spans.Documentation
3434import Development.IDE.GHC.Error
3535import Development.IDE.Types.Options
src/Development/IDE/Core/CompletionsTypes.hs → src/Development/IDE/Plugin/Completions/Types.hsrenamed+2−2
@@ -1,5 +1,5 @@
1−module Development.IDE.Core.CompletionsTypes (
2− module Development.IDE.Core.CompletionsTypes
1+module Development.IDE.Plugin.Completions.Types (
2+ module Development.IDE.Plugin.Completions.Types
33) where
44
55import Control.DeepSeq