Skip to content

Commit 3ccebde

Browse files
ndmitchellcocreature
authored andcommitted
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 <>
1 parent 0992bc7 commit 3ccebde

File tree

10 files changed

+61
-46
lines changed

10 files changed

+61
-46
lines changed

.hlint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Development.IDE.Types.Diagnostics
2828
import Development.IDE.Types.Options
2929
import Development.IDE.Types.Logger
3030
import Development.IDE.GHC.Util
31+
import Development.IDE.Plugin.Completions
32+
import Development.IDE.Plugin.CodeAction
3133
import qualified Data.Text as T
3234
import qualified Data.Text.IO as T
3335
import 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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

143143
executable ghcide-test-preprocessor

src/Development/IDE/Core/RuleTypes.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import Module (InstalledUnitId)
2727
import HscTypes (CgGuts, Linkable, HomeModInfo, ModDetails)
2828
import Development.IDE.GHC.Compat
2929

30-
import Development.IDE.Core.CompletionsTypes
3130
import Development.IDE.Spans.Type
3231

3332

@@ -86,9 +85,6 @@ type instance RuleResult ReportImportCycles = ()
8685
-- | Read the given HIE file.
8786
type instance RuleResult GetHieFile = HieFile
8887

89-
-- | Produce completions info for a file
90-
type instance RuleResult ProduceCompletions = (CachedCompletions, TcModuleResult)
91-
9288

9389
data GetParsedModule = GetParsedModule
9490
deriving (Eq, Show, Typeable, Generic)
@@ -157,9 +153,3 @@ data GetHieFile = GetHieFile FilePath
157153
instance Hashable GetHieFile
158154
instance NFData GetHieFile
159155
instance 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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import Control.Monad
3232
import Control.Monad.Trans.Class
3333
import Control.Monad.Trans.Maybe
3434
import Development.IDE.Core.Compile
35-
import Development.IDE.Core.Completions
3635
import Development.IDE.Types.Options
3736
import Development.IDE.Spans.Calculate
3837
import Development.IDE.Import.DependencyInformation
@@ -307,20 +306,6 @@ generateCoreRule :: Rules ()
307306
generateCoreRule =
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-
324309
generateByteCodeRule :: Rules ()
325310
generateByteCodeRule =
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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import System.IO
2929
import Control.Monad.Extra
3030

3131
import Development.IDE.LSP.HoverDefinition
32-
import Development.IDE.LSP.CodeAction
33-
import Development.IDE.LSP.Completions
3432
import Development.IDE.LSP.Notifications
3533
import Development.IDE.LSP.Outline
3634
import 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 renamed to src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 renamed to src/Development/IDE/Plugin/Completions.hs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
1-
module Development.IDE.LSP.Completions (
2-
setHandlersCompletion
1+
{-# LANGUAGE TypeFamilies #-}
2+
3+
module Development.IDE.Plugin.Completions (
4+
setHandlersCompletion, produceCompletions
35
) where
46

57
import Language.Haskell.LSP.Messages
68
import Language.Haskell.LSP.Types
79
import qualified Language.Haskell.LSP.Core as LSP
810
import qualified Language.Haskell.LSP.VFS as VFS
911
import 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

1118
import Development.IDE.Core.Service
12-
import Development.IDE.Core.Completions
19+
import Development.IDE.Plugin.Completions.Logic
1320
import Development.IDE.Types.Location
1421
import Development.IDE.Core.PositionMapping
1522
import Development.IDE.Core.RuleTypes
1623
import Development.IDE.Core.Shake
24+
import Development.IDE.GHC.Util
1725
import 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.
2055
getCompletionsLSP

src/Development/IDE/Core/Completions.hs renamed to src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2929
import Language.Haskell.LSP.Types
3030
import Language.Haskell.LSP.Types.Capabilities
3131
import qualified Language.Haskell.LSP.VFS as VFS
32-
import Development.IDE.Core.CompletionsTypes
32+
import Development.IDE.Plugin.Completions.Types
3333
import Development.IDE.Spans.Documentation
3434
import Development.IDE.GHC.Error
3535
import Development.IDE.Types.Options

src/Development/IDE/Core/CompletionsTypes.hs renamed to src/Development/IDE/Plugin/Completions/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

55
import Control.DeepSeq

0 commit comments

Comments
 (0)