Skip to content

Commit bac9fec

Browse files
committed
Remove exactprint dependencies from ghcide by introducing hls-refactor-plugin.
All code actions have been moved to hls-refactor-plugin Mostly straightforward, only slight complication was that completion auto imports depends on exactprint, but I didn't want to remove all completion logic from ghcide just for this. Instead, I added logic to dynamically lookup the plugin that provides the extend import command, so that auto imports work as expected when you have hls-refactor-plugin enabled.
1 parent 3b2f9f6 commit bac9fec

File tree

152 files changed

+4438
-3728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+4438
-3728
lines changed

.github/workflows/test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ jobs:
160160
name: Test hls-brittany-plugin
161161
run: cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-brittany-plugin --test-options="$TEST_OPTS"
162162

163+
- if: matrix.test
164+
name: Test hls-refactor-plugin
165+
run: cabal test hls-refactor-plugin --test-options="$TEST_OPTS" || cabal test hls-refactor-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-refactor-plugin --test-options="$TEST_OPTS"
166+
163167
- if: matrix.test
164168
name: Test hls-floskell-plugin
165169
run: cabal test hls-floskell-plugin --test-options="$TEST_OPTS" || cabal test hls-floskell-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-floskell-plugin --test-options="$TEST_OPTS"

cabal.project

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ packages:
3131
./plugins/hls-stan-plugin
3232
./plugins/hls-gadt-plugin
3333
./plugins/hls-explicit-fixity-plugin
34+
./plugins/hls-refactor-plugin
3435

3536
-- Standard location for temporary packages needed for particular environments
3637
-- For example it is used in the project gitlab mirror to help in the MAcOS M1 build script

exe/Plugins.hs

+11
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ import qualified Ide.Plugin.StylishHaskell as StylishHaskell
118118
import qualified Ide.Plugin.Brittany as Brittany
119119
#endif
120120

121+
#if hls_refactor
122+
import qualified Development.IDE.Plugin.CodeAction as Refactor
123+
#endif
124+
121125
data Log = forall a. (Pretty a) => Log a
122126

123127
instance Pretty Log where
@@ -210,6 +214,13 @@ idePlugins recorder includeExamples = pluginDescToIdePlugins allPlugins
210214
#endif
211215
#if hls_gadt
212216
GADT.descriptor "gadt" :
217+
#endif
218+
#if hls_refactor
219+
Refactor.iePluginDescriptor pluginRecorder "ghcide-code-actions-imports-exports" :
220+
Refactor.typeSigsPluginDescriptor pluginRecorder "ghcide-code-actions-type-signatures" :
221+
Refactor.bindingsPluginDescriptor pluginRecorder "ghcide-code-actions-bindings" :
222+
Refactor.fillHolePluginDescriptor pluginRecorder "ghcide-code-actions-fill-holes" :
223+
Refactor.extendImportPluginDescriptor pluginRecorder "ghcide-extend-import-action" :
213224
#endif
214225
-- The ghcide descriptors should come last so that the notification handlers
215226
-- (which restart the Shake build) run after everything else

ghcide/ghcide.cabal

+42-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cabal-version: 2.4
1+
cabal-version: 3.0
22
build-type: Simple
33
category: Development
44
name: ghcide
@@ -59,7 +59,6 @@ library
5959
filepath,
6060
fingertree,
6161
focus,
62-
ghc-exactprint < 1 || >= 1.4,
6362
ghc-trace-events,
6463
Glob,
6564
haddock-library >= 1.8 && < 1.11,
@@ -71,18 +70,14 @@ library
7170
hiedb == 0.4.1.*,
7271
lsp-types ^>= 1.4.0.1,
7372
lsp ^>= 1.4.0.0 ,
74-
monoid-subclasses,
7573
mtl,
76-
network-uri,
7774
optparse-applicative,
7875
parallel,
7976
prettyprinter-ansi-terminal,
8077
prettyprinter >= 1.6,
8178
random,
8279
regex-tdfa >= 1.3.1.0,
83-
retrie,
8480
rope-utf16-splay,
85-
safe,
8681
safe-exceptions,
8782
hls-graph ^>= 1.7,
8883
sorted-list,
@@ -94,9 +89,7 @@ library
9489
time,
9590
transformers,
9691
unordered-containers >= 0.2.10.0,
97-
utf8-string,
9892
vector,
99-
vector-algorithms,
10093
hslogger,
10194
Diff ^>=0.4.0,
10295
vector,
@@ -113,9 +106,6 @@ library
113106
hie-bios ^>= 0.9.1,
114107
implicit-hie-cradle ^>= 0.3.0.5 || ^>= 0.5,
115108
base16-bytestring >=0.1.1 && <1.1
116-
if impl(ghc >= 9.2)
117-
build-depends:
118-
ghc-exactprint >= 1.4
119109
if os(windows)
120110
build-depends:
121111
Win32
@@ -171,7 +161,6 @@ library
171161
Development.IDE.GHC.Compat
172162
Development.IDE.GHC.Compat.Core
173163
Development.IDE.GHC.Compat.Env
174-
Development.IDE.GHC.Compat.ExactPrint
175164
Development.IDE.GHC.Compat.Iface
176165
Development.IDE.GHC.Compat.Logger
177166
Development.IDE.GHC.Compat.Outputable
@@ -183,7 +172,6 @@ library
183172
Development.IDE.GHC.CoreFile
184173
Development.IDE.GHC.Dump
185174
Development.IDE.GHC.Error
186-
Development.IDE.GHC.ExactPrint
187175
Development.IDE.GHC.Orphans
188176
Development.IDE.GHC.Util
189177
Development.IDE.Import.DependencyInformation
@@ -212,8 +200,6 @@ library
212200
Development.IDE.Plugin
213201
Development.IDE.Plugin.Completions
214202
Development.IDE.Plugin.Completions.Types
215-
Development.IDE.Plugin.CodeAction
216-
Development.IDE.Plugin.CodeAction.ExactPrint
217203
Development.IDE.Plugin.HLS
218204
Development.IDE.Plugin.HLS.GhcIde
219205
Development.IDE.Plugin.Test
@@ -225,8 +211,6 @@ library
225211
Development.IDE.GHC.CPP
226212
Development.IDE.GHC.Warnings
227213
Development.IDE.LSP.Notifications
228-
Development.IDE.Plugin.CodeAction.PositionIndexed
229-
Development.IDE.Plugin.CodeAction.Args
230214
Development.IDE.Plugin.Completions.Logic
231215
Development.IDE.Session.VersionCheck
232216
Development.IDE.Types.Action
@@ -405,6 +389,7 @@ test-suite ghcide-tests
405389
ghc,
406390
--------------------------------------------------------------
407391
ghcide,
392+
ghcide-test-utils,
408393
ghc-typelits-knownnat,
409394
haddock-library,
410395
lsp,
@@ -442,12 +427,10 @@ test-suite ghcide-tests
442427
build-depends:
443428
record-dot-preprocessor,
444429
record-hasfield
445-
hs-source-dirs: test/cabal test/exe test/src bench/lib
430+
hs-source-dirs: test/cabal test/exe bench/lib
446431
ghc-options: -threaded -Wall -Wno-name-shadowing -O0 -Wno-unticked-promoted-constructors
447432
main-is: Main.hs
448433
other-modules:
449-
Development.IDE.Test
450-
Development.IDE.Test.Diagnostic
451434
Development.IDE.Test.Runfiles
452435
Experiments
453436
Experiments.Types
@@ -470,6 +453,45 @@ test-suite ghcide-tests
470453
TypeApplications
471454
ViewPatterns
472455

456+
library ghcide-test-utils
457+
visibility: public
458+
default-language: Haskell2010
459+
build-depends:
460+
aeson,
461+
base,
462+
containers,
463+
data-default,
464+
directory,
465+
extra,
466+
filepath,
467+
ghcide,
468+
lsp-types,
469+
hls-plugin-api,
470+
lens,
471+
lsp-test ^>= 0.14,
472+
tasty-hunit >= 0.10,
473+
text,
474+
hs-source-dirs: test/src
475+
ghc-options: -Wunused-packages
476+
exposed-modules:
477+
Development.IDE.Test
478+
Development.IDE.Test.Diagnostic
479+
default-extensions:
480+
BangPatterns
481+
DeriveFunctor
482+
DeriveGeneric
483+
FlexibleContexts
484+
GeneralizedNewtypeDeriving
485+
LambdaCase
486+
NamedFieldPuns
487+
OverloadedStrings
488+
RecordWildCards
489+
ScopedTypeVariables
490+
StandaloneDeriving
491+
TupleSections
492+
TypeApplications
493+
ViewPatterns
494+
473495
flag bench-exe
474496
description: Build the ghcide-bench executable
475497
default: True

ghcide/src/Development/IDE/Core/Rules.hs

-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ import Development.IDE.GHC.Compat hiding
119119
import qualified Development.IDE.GHC.Compat as Compat hiding (vcat, nest)
120120
import qualified Development.IDE.GHC.Compat.Util as Util
121121
import Development.IDE.GHC.Error
122-
import Development.IDE.GHC.ExactPrint hiding (LogShake, Log)
123122
import Development.IDE.GHC.Util hiding
124123
(modifyDynFlags)
125124
import Development.IDE.Graph
@@ -154,7 +153,6 @@ import System.Info.Extra (isWindows)
154153
import HIE.Bios.Ghc.Gap (hostIsDynamic)
155154
import Development.IDE.Types.Logger (Recorder, logWith, cmapWithPrio, WithPriority, Pretty (pretty), (<+>), nest, vcat)
156155
import qualified Development.IDE.Core.Shake as Shake
157-
import qualified Development.IDE.GHC.ExactPrint as ExactPrint hiding (LogShake)
158156
import qualified Development.IDE.Types.Logger as Logger
159157
import qualified Development.IDE.Types.Shake as Shake
160158
import Development.IDE.GHC.CoreFile
@@ -167,7 +165,6 @@ data Log
167165
| LogLoadingHieFile !NormalizedFilePath
168166
| LogLoadingHieFileFail !FilePath !SomeException
169167
| LogLoadingHieFileSuccess !FilePath
170-
| LogExactPrint ExactPrint.Log
171168
| LogTypecheckedFOI !NormalizedFilePath
172169
deriving Show
173170

@@ -185,7 +182,6 @@ instance Pretty Log where
185182
, pretty (displayException e) ]
186183
LogLoadingHieFileSuccess path ->
187184
"SUCCEEDED LOADING HIE FILE FOR" <+> pretty path
188-
LogExactPrint log -> pretty log
189185
LogTypecheckedFOI path -> vcat
190186
[ "Typechecked a file which is not currently open in the editor:" <+> pretty (fromNormalizedFilePath path)
191187
, "This can indicate a bug which results in excessive memory usage."
@@ -1230,7 +1226,6 @@ mainRule recorder RulesConfig{..} = do
12301226
else defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \NeedsCompilation _ -> return $ Just Nothing
12311227
generateCoreRule recorder
12321228
getImportMapRule recorder
1233-
getAnnotatedParsedSourceRule (cmapWithPrio LogExactPrint recorder)
12341229
persistentHieFileRule recorder
12351230
persistentDocMapRule
12361231
persistentImportMapRule

ghcide/src/Development/IDE/Core/Service.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import Development.IDE.Core.Shake hiding (Log)
4141
import qualified Development.IDE.Core.Shake as Shake
4242
import Development.IDE.Types.Monitoring (Monitoring)
4343
import Development.IDE.Types.Shake (WithHieDb)
44+
import Ide.Types (IdePlugins)
4445
import System.Environment (lookupEnv)
4546

4647
data Log
@@ -61,6 +62,7 @@ instance Pretty Log where
6162
-- | Initialise the Compiler Service.
6263
initialise :: Recorder (WithPriority Log)
6364
-> Config
65+
-> IdePlugins IdeState
6466
-> Rules ()
6567
-> Maybe (LSP.LanguageContextEnv Config)
6668
-> Logger
@@ -70,7 +72,7 @@ initialise :: Recorder (WithPriority Log)
7072
-> IndexQueue
7173
-> Monitoring
7274
-> IO IdeState
73-
initialise recorder defaultConfig mainRule lspEnv logger debouncer options withHieDb hiedbChan metrics = do
75+
initialise recorder defaultConfig plugins mainRule lspEnv logger debouncer options withHieDb hiedbChan metrics = do
7476
shakeProfiling <- do
7577
let fromConf = optShakeProfiling options
7678
fromEnv <- lookupEnv "GHCIDE_BUILD_PROFILING"
@@ -79,6 +81,7 @@ initialise recorder defaultConfig mainRule lspEnv logger debouncer options withH
7981
(cmapWithPrio LogShake recorder)
8082
lspEnv
8183
defaultConfig
84+
plugins
8285
logger
8386
debouncer
8487
shakeProfiling

ghcide/src/Development/IDE/Core/Shake.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ import GHC.Stack (HasCallStack)
158158
import HieDb.Types
159159
import Ide.Plugin.Config
160160
import qualified Ide.PluginUtils as HLS
161-
import Ide.Types (PluginId)
161+
import Ide.Types (PluginId, IdePlugins)
162162
import Language.LSP.Diagnostics
163163
import qualified Language.LSP.Server as LSP
164164
import Language.LSP.Types
@@ -239,6 +239,7 @@ data ShakeExtras = ShakeExtras
239239
lspEnv :: Maybe (LSP.LanguageContextEnv Config)
240240
,debouncer :: Debouncer NormalizedUri
241241
,logger :: Logger
242+
,idePlugins :: IdePlugins IdeState
242243
,globals :: TVar (HMap.HashMap TypeRep Dynamic)
243244
-- ^ Registry of global state used by rules.
244245
-- Small and immutable after startup, so not worth using an STM.Map.
@@ -552,6 +553,7 @@ seqValue val = case val of
552553
shakeOpen :: Recorder (WithPriority Log)
553554
-> Maybe (LSP.LanguageContextEnv Config)
554555
-> Config
556+
-> IdePlugins IdeState
555557
-> Logger
556558
-> Debouncer NormalizedUri
557559
-> Maybe FilePath
@@ -563,7 +565,7 @@ shakeOpen :: Recorder (WithPriority Log)
563565
-> Monitoring
564566
-> Rules ()
565567
-> IO IdeState
566-
shakeOpen recorder lspEnv defaultConfig logger debouncer
568+
shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
567569
shakeProfileDir (IdeReportProgress reportProgress)
568570
ideTesting@(IdeTesting testing)
569571
withHieDb indexQueue opts monitoring rules = mdo

ghcide/src/Development/IDE/GHC/Compat.hs

-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ module Development.IDE.GHC.Compat(
6363
-- * Compat modules
6464
module Development.IDE.GHC.Compat.Core,
6565
module Development.IDE.GHC.Compat.Env,
66-
module Development.IDE.GHC.Compat.ExactPrint,
6766
module Development.IDE.GHC.Compat.Iface,
6867
module Development.IDE.GHC.Compat.Logger,
6968
module Development.IDE.GHC.Compat.Outputable,
@@ -119,7 +118,6 @@ module Development.IDE.GHC.Compat(
119118
import Data.Bifunctor
120119
import Development.IDE.GHC.Compat.Core
121120
import Development.IDE.GHC.Compat.Env
122-
import Development.IDE.GHC.Compat.ExactPrint
123121
import Development.IDE.GHC.Compat.Iface
124122
import Development.IDE.GHC.Compat.Logger
125123
import Development.IDE.GHC.Compat.Outputable

ghcide/src/Development/IDE/GHC/Dump.hs

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ import GhcPlugins
2121
import Prelude hiding ((<>))
2222

2323
-- | Show a GHC syntax tree in HTML.
24-
#if MIN_VERSION_ghc(9,2,1)
25-
showAstDataHtml :: (Data a, ExactPrint a, Outputable a) => a -> SDoc
26-
#else
2724
showAstDataHtml :: (Data a, Outputable a) => a -> SDoc
28-
#endif
2925
showAstDataHtml a0 = html $
3026
header $$
3127
body (tag' [("id",text (show @String "myUL"))] "ul" $ vcat
3228
[
29+
-- #if MIN_VERSION_ghc(9,2,1)
30+
31+
-- #else
3332
#if MIN_VERSION_ghc(9,2,1)
34-
li (pre $ text (exactPrint a0)),
35-
li (showAstDataHtml' a0),
33+
-- li (pre $ text (exactPrint a0)),
34+
-- li (showAstDataHtml' a0),
35+
-- li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan NoBlankEpAnnotations a0)
3636
li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan NoBlankEpAnnotations a0)
3737
#else
3838
li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan a0)
@@ -56,6 +56,7 @@ showAstDataHtml a0 = html $
5656
header = tag "head" $ tag "style" $ text css
5757
html = tag "html"
5858
pre = tag "pre"
59+
{-
5960
#if MIN_VERSION_ghc(9,2,1)
6061
showAstDataHtml' :: Data a => a -> SDoc
6162
showAstDataHtml' =
@@ -281,6 +282,7 @@ showAstDataHtml a0 = html $
281282
Nothing -> text "locatedAnn:unmatched" <+> tag
282283
<+> (text (showConstr (toConstr ss)))
283284
#endif
285+
-}
284286

285287

286288
normalize_newlines :: String -> String

ghcide/src/Development/IDE/GHC/Orphans.hs

-8
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import Unique (getKey)
2929
#endif
3030

3131

32-
import Retrie.ExactPrint (Annotated)
33-
3432
import Development.IDE.GHC.Compat
3533
import Development.IDE.GHC.Util
3634

@@ -195,12 +193,6 @@ instance NFData ModGuts where
195193
instance NFData (ImportDecl GhcPs) where
196194
rnf = rwhnf
197195

198-
instance Show (Annotated ParsedSource) where
199-
show _ = "<Annotated ParsedSource>"
200-
201-
instance NFData (Annotated ParsedSource) where
202-
rnf = rwhnf
203-
204196
#if MIN_VERSION_ghc(9,0,1)
205197
instance (NFData HsModule) where
206198
#else

0 commit comments

Comments
 (0)