Skip to content

Commit 431e3e8

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. Move lookupPluginId out of loop Replace code actions with lenses in benchmarks Allow plugins to use GetAnnotatedParsedSource by linking it in when depended on Move lookupPluginId to IdePlugins Add default extensions Move traceAst
1 parent 7760340 commit 431e3e8

File tree

165 files changed

+4533
-3798
lines changed

Some content is hidden

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

165 files changed

+4533
-3798
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ packages:
3232
./plugins/hls-stan-plugin
3333
./plugins/hls-gadt-plugin
3434
./plugins/hls-explicit-fixity-plugin
35+
./plugins/hls-refactor-plugin
3536

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

ghcide-bench/src/Experiments.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ experiments =
139139
not . null <$> getCompletions doc (fromJust identifierP),
140140
---------------------------------------------------------------------------------------
141141
benchWithSetup
142-
"code actions"
142+
"code lens"
143143
( \docs -> do
144144
unless (any (isJust . identifierP) docs) $
145145
error "None of the example modules is suitable for this experiment"
@@ -148,13 +148,12 @@ experiments =
148148
waitForProgressStart
149149
waitForProgressDone
150150
)
151-
( \docs -> not . null . catMaybes <$> forM docs (\DocumentPositions{..} ->
152-
forM identifierP $ \p ->
153-
getCodeActions doc (Range p p))
151+
( \docs -> not . null <$> forM docs (\DocumentPositions{..} ->
152+
getCodeLenses doc)
154153
),
155154
---------------------------------------------------------------------------------------
156155
benchWithSetup
157-
"code actions after edit"
156+
"code lens after edit"
158157
( \docs -> do
159158
unless (any (isJust . identifierP) docs) $
160159
error "None of the example modules is suitable for this experiment"
@@ -166,9 +165,8 @@ experiments =
166165
changeDoc doc [charEdit stringLiteralP]
167166
waitForProgressStart
168167
waitForProgressDone
169-
not . null . catMaybes <$> forM docs (\DocumentPositions{..} -> do
170-
forM identifierP $ \p ->
171-
getCodeActions doc (Range p p))
168+
not . null <$> forM docs (\DocumentPositions{..} -> do
169+
getCodeLenses doc)
172170
),
173171
---------------------------------------------------------------------------------------
174172
benchWithSetup

ghcide/ghcide.cabal

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ library
6060
filepath,
6161
fingertree,
6262
focus,
63-
ghc-exactprint < 1 || >= 1.4,
6463
ghc-trace-events,
6564
Glob,
6665
haddock-library >= 1.8 && < 1.11,
@@ -74,16 +73,13 @@ library
7473
lsp ^>= 1.5.0.0 ,
7574
monoid-subclasses,
7675
mtl,
77-
network-uri,
7876
optparse-applicative,
7977
parallel,
8078
prettyprinter-ansi-terminal,
8179
prettyprinter >= 1.6,
8280
random,
8381
regex-tdfa >= 1.3.1.0,
84-
retrie,
8582
text-rope,
86-
safe,
8783
safe-exceptions,
8884
hls-graph ^>= 1.7,
8985
sorted-list,
@@ -95,9 +91,7 @@ library
9591
time,
9692
transformers,
9793
unordered-containers >= 0.2.10.0,
98-
utf8-string,
9994
vector,
100-
vector-algorithms,
10195
hslogger,
10296
Diff ^>=0.4.0,
10397
vector,
@@ -114,9 +108,6 @@ library
114108
hie-bios ^>= 0.9.1,
115109
implicit-hie-cradle ^>= 0.3.0.5 || ^>= 0.5,
116110
base16-bytestring >=0.1.1 && <1.1
117-
if impl(ghc >= 9.2)
118-
build-depends:
119-
ghc-exactprint >= 1.4
120111
if os(windows)
121112
build-depends:
122113
Win32
@@ -172,7 +163,6 @@ library
172163
Development.IDE.GHC.Compat
173164
Development.IDE.GHC.Compat.Core
174165
Development.IDE.GHC.Compat.Env
175-
Development.IDE.GHC.Compat.ExactPrint
176166
Development.IDE.GHC.Compat.Iface
177167
Development.IDE.GHC.Compat.Logger
178168
Development.IDE.GHC.Compat.Outputable
@@ -182,9 +172,7 @@ library
182172
Development.IDE.GHC.Compat.Util
183173
Development.IDE.Core.Compile
184174
Development.IDE.GHC.CoreFile
185-
Development.IDE.GHC.Dump
186175
Development.IDE.GHC.Error
187-
Development.IDE.GHC.ExactPrint
188176
Development.IDE.GHC.Orphans
189177
Development.IDE.GHC.Util
190178
Development.IDE.Import.DependencyInformation
@@ -214,8 +202,6 @@ library
214202
Development.IDE.Plugin
215203
Development.IDE.Plugin.Completions
216204
Development.IDE.Plugin.Completions.Types
217-
Development.IDE.Plugin.CodeAction
218-
Development.IDE.Plugin.CodeAction.ExactPrint
219205
Development.IDE.Plugin.HLS
220206
Development.IDE.Plugin.HLS.GhcIde
221207
Development.IDE.Plugin.Test
@@ -226,8 +212,6 @@ library
226212
Development.IDE.Core.FileExists
227213
Development.IDE.GHC.CPP
228214
Development.IDE.GHC.Warnings
229-
Development.IDE.Plugin.CodeAction.PositionIndexed
230-
Development.IDE.Plugin.CodeAction.Args
231215
Development.IDE.Plugin.Completions.Logic
232216
Development.IDE.Session.VersionCheck
233217
Development.IDE.Types.Action
@@ -365,6 +349,7 @@ test-suite ghcide-tests
365349
ghc,
366350
--------------------------------------------------------------
367351
ghcide,
352+
ghcide-test-utils,
368353
ghc-typelits-knownnat,
369354
lsp,
370355
lsp-types,
@@ -393,12 +378,10 @@ test-suite ghcide-tests
393378
build-depends:
394379
record-dot-preprocessor,
395380
record-hasfield
396-
hs-source-dirs: test/cabal test/exe test/src bench/lib
381+
hs-source-dirs: test/cabal test/exe bench/lib
397382
ghc-options: -threaded -Wall -Wno-name-shadowing -O0 -Wno-unticked-promoted-constructors
398383
main-is: Main.hs
399384
other-modules:
400-
Development.IDE.Test
401-
Development.IDE.Test.Diagnostic
402385
Development.IDE.Test.Runfiles
403386
FuzzySearch
404387
Progress
@@ -418,3 +401,42 @@ test-suite ghcide-tests
418401
TupleSections
419402
TypeApplications
420403
ViewPatterns
404+
405+
library ghcide-test-utils
406+
visibility: public
407+
default-language: Haskell2010
408+
build-depends:
409+
aeson,
410+
base,
411+
containers,
412+
data-default,
413+
directory,
414+
extra,
415+
filepath,
416+
ghcide,
417+
lsp-types,
418+
hls-plugin-api,
419+
lens,
420+
lsp-test ^>= 0.14,
421+
tasty-hunit >= 0.10,
422+
text,
423+
hs-source-dirs: test/src
424+
ghc-options: -Wunused-packages
425+
exposed-modules:
426+
Development.IDE.Test
427+
Development.IDE.Test.Diagnostic
428+
default-extensions:
429+
BangPatterns
430+
DeriveFunctor
431+
DeriveGeneric
432+
FlexibleContexts
433+
GeneralizedNewtypeDeriving
434+
LambdaCase
435+
NamedFieldPuns
436+
OverloadedStrings
437+
RecordWildCards
438+
ScopedTypeVariables
439+
StandaloneDeriving
440+
TupleSections
441+
TypeApplications
442+
ViewPatterns

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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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/Orphans.hs

Lines changed: 0 additions & 8 deletions
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)