Skip to content

Commit

Permalink
Remove exactprint dependencies from ghcide by introducing hls-refacto…
Browse files Browse the repository at this point in the history
…r-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.
  • Loading branch information
wz1000 committed Aug 11, 2022
1 parent 524ef15 commit bd09b59
Show file tree
Hide file tree
Showing 152 changed files with 4,475 additions and 3,728 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ jobs:
name: Test hls-brittany-plugin
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"

- if: matrix.test
name: Test hls-refactor-plugin
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"

- if: matrix.test
name: Test hls-floskell-plugin
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"
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ packages:
./plugins/hls-change-type-signature-plugin
./plugins/hls-stan-plugin
./plugins/hls-gadt-plugin
./plugins/hls-refactor-plugin

-- Standard location for temporary packages needed for particular environments
-- For example it is used in the project gitlab mirror to help in the MAcOS M1 build script
Expand Down
11 changes: 11 additions & 0 deletions exe/Plugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ import qualified Ide.Plugin.StylishHaskell as StylishHaskell
import qualified Ide.Plugin.Brittany as Brittany
#endif

#if hls_refactor
import qualified Development.IDE.Plugin.CodeAction as Refactor
#endif

data Log = forall a. (Pretty a) => Log a

instance Pretty Log where
Expand Down Expand Up @@ -205,6 +209,13 @@ idePlugins recorder includeExamples = pluginDescToIdePlugins allPlugins
#endif
#if hls_gadt
GADT.descriptor "gadt" :
#endif
#if hls_refactor
Refactor.iePluginDescriptor pluginRecorder "ghcide-code-actions-imports-exports" :
Refactor.typeSigsPluginDescriptor pluginRecorder "ghcide-code-actions-type-signatures" :
Refactor.bindingsPluginDescriptor pluginRecorder "ghcide-code-actions-bindings" :
Refactor.fillHolePluginDescriptor pluginRecorder "ghcide-code-actions-fill-holes" :
Refactor.extendImportPluginDescriptor pluginRecorder "ghcide-extend-import-action" :
#endif
-- The ghcide descriptors should come last so that the notification handlers
-- (which restart the Shake build) run after everything else
Expand Down
62 changes: 42 additions & 20 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 2.4
cabal-version: 3.0
build-type: Simple
category: Development
name: ghcide
Expand Down Expand Up @@ -59,7 +59,6 @@ library
filepath,
fingertree,
focus,
ghc-exactprint < 1 || >= 1.4,
ghc-trace-events,
Glob,
haddock-library >= 1.8 && < 1.11,
Expand All @@ -71,18 +70,14 @@ library
hiedb == 0.4.1.*,
lsp-types ^>= 1.4.0.1,
lsp ^>= 1.4.0.0 ,
monoid-subclasses,
mtl,
network-uri,
optparse-applicative,
parallel,
prettyprinter-ansi-terminal,
prettyprinter >= 1.6,
random,
regex-tdfa >= 1.3.1.0,
retrie,
rope-utf16-splay,
safe,
safe-exceptions,
hls-graph ^>= 1.7,
sorted-list,
Expand All @@ -94,9 +89,7 @@ library
time,
transformers,
unordered-containers >= 0.2.10.0,
utf8-string,
vector,
vector-algorithms,
hslogger,
Diff ^>=0.4.0,
vector,
Expand All @@ -113,9 +106,6 @@ library
hie-bios ^>= 0.9.1,
implicit-hie-cradle ^>= 0.3.0.5 || ^>= 0.5,
base16-bytestring >=0.1.1 && <1.1
if impl(ghc >= 9.2)
build-depends:
ghc-exactprint >= 1.4
if os(windows)
build-depends:
Win32
Expand Down Expand Up @@ -171,7 +161,6 @@ library
Development.IDE.GHC.Compat
Development.IDE.GHC.Compat.Core
Development.IDE.GHC.Compat.Env
Development.IDE.GHC.Compat.ExactPrint
Development.IDE.GHC.Compat.Iface
Development.IDE.GHC.Compat.Logger
Development.IDE.GHC.Compat.Outputable
Expand All @@ -183,7 +172,6 @@ library
Development.IDE.GHC.CoreFile
Development.IDE.GHC.Dump
Development.IDE.GHC.Error
Development.IDE.GHC.ExactPrint
Development.IDE.GHC.Orphans
Development.IDE.GHC.Util
Development.IDE.Import.DependencyInformation
Expand Down Expand Up @@ -212,8 +200,6 @@ library
Development.IDE.Plugin
Development.IDE.Plugin.Completions
Development.IDE.Plugin.Completions.Types
Development.IDE.Plugin.CodeAction
Development.IDE.Plugin.CodeAction.ExactPrint
Development.IDE.Plugin.HLS
Development.IDE.Plugin.HLS.GhcIde
Development.IDE.Plugin.Test
Expand All @@ -225,8 +211,6 @@ library
Development.IDE.GHC.CPP
Development.IDE.GHC.Warnings
Development.IDE.LSP.Notifications
Development.IDE.Plugin.CodeAction.PositionIndexed
Development.IDE.Plugin.CodeAction.Args
Development.IDE.Plugin.Completions.Logic
Development.IDE.Session.VersionCheck
Development.IDE.Types.Action
Expand Down Expand Up @@ -405,6 +389,7 @@ test-suite ghcide-tests
ghc,
--------------------------------------------------------------
ghcide,
ghcide-test-utils,
ghc-typelits-knownnat,
haddock-library,
lsp,
Expand Down Expand Up @@ -442,12 +427,10 @@ test-suite ghcide-tests
build-depends:
record-dot-preprocessor,
record-hasfield
hs-source-dirs: test/cabal test/exe test/src bench/lib
hs-source-dirs: test/cabal test/exe bench/lib
ghc-options: -threaded -Wall -Wno-name-shadowing -O0 -Wno-unticked-promoted-constructors
main-is: Main.hs
other-modules:
Development.IDE.Test
Development.IDE.Test.Diagnostic
Development.IDE.Test.Runfiles
Experiments
Experiments.Types
Expand All @@ -470,6 +453,45 @@ test-suite ghcide-tests
TypeApplications
ViewPatterns

library ghcide-test-utils
visibility: public
default-language: Haskell2010
build-depends:
aeson,
base,
containers,
data-default,
directory,
extra,
filepath,
ghcide,
lsp-types,
hls-plugin-api,
lens,
lsp-test ^>= 0.14,
tasty-hunit >= 0.10,
text,
hs-source-dirs: test/src
ghc-options: -Wunused-packages
exposed-modules:
Development.IDE.Test
Development.IDE.Test.Diagnostic
default-extensions:
BangPatterns
DeriveFunctor
DeriveGeneric
FlexibleContexts
GeneralizedNewtypeDeriving
LambdaCase
NamedFieldPuns
OverloadedStrings
RecordWildCards
ScopedTypeVariables
StandaloneDeriving
TupleSections
TypeApplications
ViewPatterns

flag bench-exe
description: Build the ghcide-bench executable
default: True
Expand Down
5 changes: 0 additions & 5 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ import Development.IDE.GHC.Compat hiding
import qualified Development.IDE.GHC.Compat as Compat hiding (vcat, nest)
import qualified Development.IDE.GHC.Compat.Util as Util
import Development.IDE.GHC.Error
import Development.IDE.GHC.ExactPrint hiding (LogShake, Log)
import Development.IDE.GHC.Util hiding
(modifyDynFlags)
import Development.IDE.Graph
Expand Down Expand Up @@ -154,7 +153,6 @@ import System.Info.Extra (isWindows)
import HIE.Bios.Ghc.Gap (hostIsDynamic)
import Development.IDE.Types.Logger (Recorder, logWith, cmapWithPrio, WithPriority, Pretty (pretty), (<+>), nest, vcat)
import qualified Development.IDE.Core.Shake as Shake
import qualified Development.IDE.GHC.ExactPrint as ExactPrint hiding (LogShake)
import qualified Development.IDE.Types.Logger as Logger
import qualified Development.IDE.Types.Shake as Shake
import Development.IDE.GHC.CoreFile
Expand All @@ -167,7 +165,6 @@ data Log
| LogLoadingHieFile !NormalizedFilePath
| LogLoadingHieFileFail !FilePath !SomeException
| LogLoadingHieFileSuccess !FilePath
| LogExactPrint ExactPrint.Log
| LogTypecheckedFOI !NormalizedFilePath
deriving Show

Expand All @@ -185,7 +182,6 @@ instance Pretty Log where
, pretty (displayException e) ]
LogLoadingHieFileSuccess path ->
"SUCCEEDED LOADING HIE FILE FOR" <+> pretty path
LogExactPrint log -> pretty log
LogTypecheckedFOI path -> vcat
[ "Typechecked a file which is not currently open in the editor:" <+> pretty (fromNormalizedFilePath path)
, "This can indicate a bug which results in excessive memory usage."
Expand Down Expand Up @@ -1230,7 +1226,6 @@ mainRule recorder RulesConfig{..} = do
else defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \NeedsCompilation _ -> return $ Just Nothing
generateCoreRule recorder
getImportMapRule recorder
getAnnotatedParsedSourceRule (cmapWithPrio LogExactPrint recorder)
persistentHieFileRule recorder
persistentDocMapRule
persistentImportMapRule
Expand Down
5 changes: 4 additions & 1 deletion ghcide/src/Development/IDE/Core/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Development.IDE.Core.Shake hiding (Log)
import qualified Development.IDE.Core.Shake as Shake
import Development.IDE.Types.Monitoring (Monitoring)
import Development.IDE.Types.Shake (WithHieDb)
import Ide.Types (IdePlugins)
import System.Environment (lookupEnv)

data Log
Expand All @@ -61,6 +62,7 @@ instance Pretty Log where
-- | Initialise the Compiler Service.
initialise :: Recorder (WithPriority Log)
-> Config
-> IdePlugins IdeState
-> Rules ()
-> Maybe (LSP.LanguageContextEnv Config)
-> Logger
Expand All @@ -70,7 +72,7 @@ initialise :: Recorder (WithPriority Log)
-> IndexQueue
-> Monitoring
-> IO IdeState
initialise recorder defaultConfig mainRule lspEnv logger debouncer options withHieDb hiedbChan metrics = do
initialise recorder defaultConfig plugins mainRule lspEnv logger debouncer options withHieDb hiedbChan metrics = do
shakeProfiling <- do
let fromConf = optShakeProfiling options
fromEnv <- lookupEnv "GHCIDE_BUILD_PROFILING"
Expand All @@ -79,6 +81,7 @@ initialise recorder defaultConfig mainRule lspEnv logger debouncer options withH
(cmapWithPrio LogShake recorder)
lspEnv
defaultConfig
plugins
logger
debouncer
shakeProfiling
Expand Down
6 changes: 4 additions & 2 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ import GHC.Stack (HasCallStack)
import HieDb.Types
import Ide.Plugin.Config
import qualified Ide.PluginUtils as HLS
import Ide.Types (PluginId)
import Ide.Types (PluginId, IdePlugins)
import Language.LSP.Diagnostics
import qualified Language.LSP.Server as LSP
import Language.LSP.Types
Expand Down Expand Up @@ -239,6 +239,7 @@ data ShakeExtras = ShakeExtras
lspEnv :: Maybe (LSP.LanguageContextEnv Config)
,debouncer :: Debouncer NormalizedUri
,logger :: Logger
,idePlugins :: IdePlugins IdeState
,globals :: TVar (HMap.HashMap TypeRep Dynamic)
-- ^ Registry of global state used by rules.
-- Small and immutable after startup, so not worth using an STM.Map.
Expand Down Expand Up @@ -552,6 +553,7 @@ seqValue val = case val of
shakeOpen :: Recorder (WithPriority Log)
-> Maybe (LSP.LanguageContextEnv Config)
-> Config
-> IdePlugins IdeState
-> Logger
-> Debouncer NormalizedUri
-> Maybe FilePath
Expand All @@ -563,7 +565,7 @@ shakeOpen :: Recorder (WithPriority Log)
-> Monitoring
-> Rules ()
-> IO IdeState
shakeOpen recorder lspEnv defaultConfig logger debouncer
shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
shakeProfileDir (IdeReportProgress reportProgress)
ideTesting@(IdeTesting testing)
withHieDb indexQueue opts monitoring rules = mdo
Expand Down
2 changes: 0 additions & 2 deletions ghcide/src/Development/IDE/GHC/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ module Development.IDE.GHC.Compat(
-- * Compat modules
module Development.IDE.GHC.Compat.Core,
module Development.IDE.GHC.Compat.Env,
module Development.IDE.GHC.Compat.ExactPrint,
module Development.IDE.GHC.Compat.Iface,
module Development.IDE.GHC.Compat.Logger,
module Development.IDE.GHC.Compat.Outputable,
Expand Down Expand Up @@ -119,7 +118,6 @@ module Development.IDE.GHC.Compat(
import Data.Bifunctor
import Development.IDE.GHC.Compat.Core
import Development.IDE.GHC.Compat.Env
import Development.IDE.GHC.Compat.ExactPrint
import Development.IDE.GHC.Compat.Iface
import Development.IDE.GHC.Compat.Logger
import Development.IDE.GHC.Compat.Outputable
Expand Down
14 changes: 8 additions & 6 deletions ghcide/src/Development/IDE/GHC/Dump.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ import GhcPlugins
import Prelude hiding ((<>))

-- | Show a GHC syntax tree in HTML.
#if MIN_VERSION_ghc(9,2,1)
showAstDataHtml :: (Data a, ExactPrint a, Outputable a) => a -> SDoc
#else
showAstDataHtml :: (Data a, Outputable a) => a -> SDoc
#endif
showAstDataHtml a0 = html $
header $$
body (tag' [("id",text (show @String "myUL"))] "ul" $ vcat
[
-- #if MIN_VERSION_ghc(9,2,1)

-- #else
#if MIN_VERSION_ghc(9,2,1)
li (pre $ text (exactPrint a0)),
li (showAstDataHtml' a0),
-- li (pre $ text (exactPrint a0)),
-- li (showAstDataHtml' a0),
-- li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan NoBlankEpAnnotations a0)
li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan NoBlankEpAnnotations a0)
#else
li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan a0)
Expand All @@ -56,6 +56,7 @@ showAstDataHtml a0 = html $
header = tag "head" $ tag "style" $ text css
html = tag "html"
pre = tag "pre"
{-
#if MIN_VERSION_ghc(9,2,1)
showAstDataHtml' :: Data a => a -> SDoc
showAstDataHtml' =
Expand Down Expand Up @@ -281,6 +282,7 @@ showAstDataHtml a0 = html $
Nothing -> text "locatedAnn:unmatched" <+> tag
<+> (text (showConstr (toConstr ss)))
#endif
-}


normalize_newlines :: String -> String
Expand Down
8 changes: 0 additions & 8 deletions ghcide/src/Development/IDE/GHC/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import Unique (getKey)
#endif


import Retrie.ExactPrint (Annotated)

import Development.IDE.GHC.Compat
import Development.IDE.GHC.Util

Expand Down Expand Up @@ -195,12 +193,6 @@ instance NFData ModGuts where
instance NFData (ImportDecl GhcPs) where
rnf = rwhnf

instance Show (Annotated ParsedSource) where
show _ = "<Annotated ParsedSource>"

instance NFData (Annotated ParsedSource) where
rnf = rwhnf

#if MIN_VERSION_ghc(9,0,1)
instance (NFData HsModule) where
#else
Expand Down
Loading

0 comments on commit bd09b59

Please sign in to comment.