Skip to content

Commit ed8ac13

Browse files
committed
revert ghcide
1 parent e2181d8 commit ed8ac13

23 files changed

+1946
-90
lines changed

ghcide/ghcide.cabal

+9
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ library
164164
Development.IDE.GHC.Util
165165
Development.IDE.Import.DependencyInformation
166166
Development.IDE.Import.FindImports
167+
Development.IDE.LSP.HoverDefinition
167168
Development.IDE.LSP.LanguageServer
168169
Development.IDE.LSP.Notifications
170+
Development.IDE.LSP.Outline
169171
Development.IDE.LSP.Server
170172
Development.IDE.Main
171173
Development.IDE.Main.HeapStats
@@ -356,22 +358,29 @@ test-suite ghcide-tests
356358
BootTests
357359
ClientSettingsTests
358360
CodeLensTests
361+
CompletionTests
359362
CPPTests
363+
CradleTests
360364
DependentFileTest
361365
DiagnosticTests
362366
ExceptionTests
367+
FindDefinitionAndHoverTests
363368
FuzzySearch
364369
GarbageCollectionTests
365370
HaddockTests
366371
HieDbRetry
372+
HighlightTests
367373
IfaceTests
374+
InitializeResponseTests
368375
LogType
369376
NonLspCommandLine
370377
OpenCloseTest
378+
OutlineTests
371379
PluginSimpleTests
372380
PositionMappingTests
373381
PreprocessorTests
374382
Progress
383+
ReferenceTests
375384
RootUriTests
376385
SafeTests
377386
SymlinkTests

ghcide/session-loader/Development/IDE/Session.hs

+11-29
Original file line numberDiff line numberDiff line change
@@ -585,21 +585,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
585585
let new_cache = newComponentCache recorder optExtensions hieYaml _cfp hscEnv
586586
all_target_details <- new_cache old_deps new_deps
587587

588-
this_dep_info <- getDependencyInfo $ maybeToList hieYaml
589-
let (all_targets, this_flags_map, this_options)
590-
= case HM.lookup _cfp flags_map' of
591-
Just this -> (all_targets', flags_map', this)
592-
Nothing -> (this_target_details : all_targets', HM.insert _cfp this_flags flags_map', this_flags)
593-
where all_targets' = concat all_target_details
594-
flags_map' = HM.fromList (concatMap toFlagsMap all_targets')
595-
this_target_details = TargetDetails (TargetFile _cfp) this_error_env this_dep_info [_cfp]
596-
this_flags = (this_error_env, this_dep_info)
597-
this_error_env = ([this_error], Nothing)
598-
this_error = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) _cfp
599-
$ T.unlines
600-
[ "No cradle target found. Is this file listed in the targets of your cradle?"
601-
, "If you are using a .cabal file, please ensure that this module is listed in either the exposed-modules or other-modules section"
602-
]
588+
let all_targets = concatMap fst all_target_details
589+
590+
let this_flags_map = HM.fromList (concatMap toFlagsMap all_targets)
603591

604592
void $ modifyVar' fileToFlags $
605593
Map.insert hieYaml this_flags_map
@@ -627,7 +615,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
627615
let !exportsMap' = createExportsMap $ mapMaybe (fmap hirModIface) modIfaces
628616
liftIO $ atomically $ modifyTVar' (exportsMap shakeExtras) (exportsMap' <>)
629617

630-
return $ second Map.keys this_options
618+
return $ second Map.keys $ this_flags_map HM.! _cfp
631619

632620
let consultCradle :: Maybe FilePath -> FilePath -> IO (IdeResult HscEnvEq, [FilePath])
633621
consultCradle hieYaml cfp = do
@@ -647,17 +635,15 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
647635
-- Display a user friendly progress message here: They probably don't know what a cradle is
648636
let progMsg = "Setting up " <> T.pack (takeBaseName (cradleRootDir cradle))
649637
<> " (for " <> T.pack lfp <> ")"
650-
mRunLspT lspEnv $ sendNotification (SMethod_CustomMethod (Proxy @"ghcide/cradle/eopts/before")) (toJSON cfp)
651638
eopts <- mRunLspTCallback lspEnv (\act -> withIndefiniteProgress progMsg Nothing NotCancellable (const act)) $
652639
withTrace "Load cradle" $ \addTag -> do
653640
addTag "file" lfp
654641
old_files <- readIORef cradle_files
655642
res <- cradleToOptsAndLibDir recorder cradle cfp old_files
656643
addTag "result" (show res)
657644
return res
658-
mRunLspT lspEnv $ sendNotification (SMethod_CustomMethod (Proxy @"ghcide/cradle/eopts/after")) (toJSON cfp)
645+
659646
logWith recorder Debug $ LogSessionLoadingResult eopts
660-
mRunLspT lspEnv $ sendNotification (SMethod_CustomMethod (Proxy @"ghcide/cradle/eopts/afterLog")) (toJSON (show $ pretty (LogSessionLoadingResult eopts)))
661647
case eopts of
662648
-- The cradle gave us some options so get to work turning them
663649
-- into and HscEnv.
@@ -824,7 +810,7 @@ newComponentCache
824810
-> HscEnv -- ^ An empty HscEnv
825811
-> [ComponentInfo] -- ^ New components to be loaded
826812
-> [ComponentInfo] -- ^ old, already existing components
827-
-> IO [ [TargetDetails] ]
813+
-> IO [ ([TargetDetails], (IdeResult HscEnvEq, DependencyInfo))]
828814
newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
829815
let cis = Map.unionWith unionCIs (mkMap new_cis) (mkMap old_cis)
830816
-- When we have multiple components with the same uid,
@@ -896,13 +882,14 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
896882
henv <- createHscEnvEq thisEnv (zip uids dfs)
897883
let targetEnv = (if isBad ci then multi_errs else [], Just henv)
898884
targetDepends = componentDependencyInfo ci
899-
logWith recorder Debug $ LogNewComponentCache (targetEnv, targetDepends)
885+
res = ( targetEnv, targetDepends)
886+
logWith recorder Debug $ LogNewComponentCache res
900887
evaluate $ liftRnf rwhnf $ componentTargets ci
901888

902889
let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends
903890
ctargets <- concatMapM mk (componentTargets ci)
904891

905-
return (L.nubOrdOn targetTarget ctargets)
892+
return (L.nubOrdOn targetTarget ctargets, res)
906893

907894
{- Note [Avoiding bad interface files]
908895
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1094,20 +1081,15 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
10941081
-- A special target for the file which caused this wonderful
10951082
-- component to be created. In case the cradle doesn't list all the targets for
10961083
-- the component, in which case things will be horribly broken anyway.
1097-
--
1098-
-- When we have a single component that is caused to be loaded due to a
1099-
-- file, we assume the file is part of that component. This is useful
1100-
-- for bare GHC sessions, such as many of the ones used in the testsuite
1084+
-- Otherwise, we will immediately attempt to reload this module which
1085+
-- causes an infinite loop and high CPU usage.
11011086
--
11021087
-- We don't do this when we have multiple components, because each
11031088
-- component better list all targets or there will be anarchy.
11041089
-- It is difficult to know which component to add our file to in
11051090
-- that case.
11061091
-- Multi unit arguments are likely to come from cabal, which
11071092
-- does list all targets.
1108-
--
1109-
-- If we don't end up with a target for the current file in the end, then
1110-
-- we will report it as an error for that file
11111093
abs_fp <- liftIO $ makeAbsolute (fromNormalizedFilePath cfp)
11121094
let special_target = Compat.mkSimpleTarget df abs_fp
11131095
pure $ (df, special_target : targets) :| []

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

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module Development.IDE.Core.Actions
44
, getDefinition
55
, getTypeDefinition
66
, highlightAtPoint
7+
, refsAtPoint
8+
, workspaceSymbols
79
, lookupMod
810
) where
911

@@ -122,4 +124,16 @@ highlightAtPoint file pos = runMaybeT $ do
122124
let toCurrentHighlight (DocumentHighlight range t) = flip DocumentHighlight t <$> toCurrentRange mapping range
123125
mapMaybe toCurrentHighlight <$>AtPoint.documentHighlight hf rf pos'
124126

127+
-- Refs are not an IDE action, so it is OK to be slow and (more) accurate
128+
refsAtPoint :: NormalizedFilePath -> Position -> Action [Location]
129+
refsAtPoint file pos = do
130+
ShakeExtras{withHieDb} <- getShakeExtras
131+
fs <- HM.keys <$> getFilesOfInterestUntracked
132+
asts <- HM.fromList . mapMaybe sequence . zip fs <$> usesWithStale GetHieAst fs
133+
AtPoint.referencesAtPoint withHieDb file pos (AtPoint.FOIReferences asts)
125134

135+
workspaceSymbols :: T.Text -> IdeAction (Maybe [SymbolInformation])
136+
workspaceSymbols query = runMaybeT $ do
137+
ShakeExtras{withHieDb} <- ask
138+
res <- liftIO $ withHieDb (\hieDb -> HieDb.searchDef hieDb $ T.unpack query)
139+
pure $ mapMaybe AtPoint.defRowToSymbolInfo res

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

+15-23
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
module Development.IDE.Core.Rules(
1212
-- * Types
1313
IdeState, GetParsedModule(..), TransitiveDependencies(..),
14-
GhcSessionIO(..), GetClientSettings(..),
14+
Priority(..), GhcSessionIO(..), GetClientSettings(..),
1515
-- * Functions
16+
priorityTypeCheck,
17+
priorityGenerateCore,
18+
priorityFilesOfInterest,
1619
runAction,
1720
toIdeResult,
1821
defineNoFile,
@@ -162,7 +165,6 @@ import Language.LSP.Protocol.Types (MessageType (Mess
162165
ShowMessageParams (ShowMessageParams))
163166
import Language.LSP.Server (LspT)
164167
import qualified Language.LSP.Server as LSP
165-
import qualified Language.LSP.Protocol.Message as LSP
166168
import Language.LSP.VFS
167169
import Prelude hiding (mod)
168170
import System.Directory (doesFileExist,
@@ -171,7 +173,6 @@ import System.Info.Extra (isWindows)
171173

172174

173175
import GHC.Fingerprint
174-
import qualified Development.IDE.Session as Session
175176

176177
-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
177178

@@ -181,14 +182,12 @@ import GHC (mgModSummaries)
181182

182183
#if MIN_VERSION_ghc(9,3,0)
183184
import qualified Data.IntMap as IM
184-
import Data.Row (KnownSymbol)
185185
#endif
186186

187187

188188

189189
data Log
190190
= LogShake Shake.Log
191-
| LogSession Session.Log
192191
| LogReindexingHieFile !NormalizedFilePath
193192
| LogLoadingHieFile !NormalizedFilePath
194193
| LogLoadingHieFileFail !FilePath !SomeException
@@ -218,7 +217,6 @@ instance Pretty Log where
218217
<+> "the HLS version being used, the plugins enabled, and if possible the codebase and file which"
219218
<+> "triggered this warning."
220219
]
221-
LogSession msg -> pretty msg
222220

223221
templateHaskellInstructions :: T.Text
224222
templateHaskellInstructions = "https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#static-binaries"
@@ -252,6 +250,15 @@ getParsedModuleWithComments = use GetParsedModuleWithComments
252250
-- Rules
253251
-- These typically go from key to value and are oracles.
254252

253+
priorityTypeCheck :: Priority
254+
priorityTypeCheck = Priority 0
255+
256+
priorityGenerateCore :: Priority
257+
priorityGenerateCore = Priority (-1)
258+
259+
priorityFilesOfInterest :: Priority
260+
priorityFilesOfInterest = Priority (-2)
261+
255262
-- | WARNING:
256263
-- We currently parse the module both with and without Opt_Haddock, and
257264
-- return the one with Haddocks if it -- succeeds. However, this may not work
@@ -675,6 +682,7 @@ typeCheckRuleDefinition
675682
-> ParsedModule
676683
-> Action (IdeResult TcModuleResult)
677684
typeCheckRuleDefinition hsc pm = do
685+
setPriority priorityTypeCheck
678686
IdeOptions { optDefer = defer } <- getIdeOptions
679687

680688
unlift <- askUnliftIO
@@ -712,24 +720,8 @@ loadGhcSession recorder ghcSessionDepsConfig = do
712720
return (fingerprint, res)
713721

714722
defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \GhcSession file -> do
715-
-- todo add signal
716-
ShakeExtras{exportsMap, ideTesting = IdeTesting testing, lspEnv, progress} <- getShakeExtras
717-
let
718-
signal' :: KnownSymbol s => Proxy s -> String -> Action ()
719-
signal' msg str = when testing $ liftIO $
720-
mRunLspT lspEnv $
721-
LSP.sendNotification (LSP.SMethod_CustomMethod msg) $
722-
toJSON $ [str]
723-
signal :: KnownSymbol s => Proxy s -> Action ()
724-
signal msg = signal' msg (show file)
725-
726-
727-
728-
signal (Proxy @"GhcSession/start")
729723
IdeGhcSession{loadSessionFun} <- useNoFile_ GhcSessionIO
730-
signal (Proxy @"GhcSession/loadSessionFun/before")
731724
(val,deps) <- liftIO $ loadSessionFun $ fromNormalizedFilePath file
732-
signal (Proxy @"GhcSession/loadSessionFun/after")
733725

734726
-- add the deps to the Shake graph
735727
let addDependency fp = do
@@ -742,7 +734,6 @@ loadGhcSession recorder ghcSessionDepsConfig = do
742734
mapM_ addDependency deps
743735

744736
let cutoffHash = LBS.toStrict $ B.encode (hash (snd val))
745-
signal (Proxy @"GhcSession/done")
746737
return (Just cutoffHash, val)
747738

748739
defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \(GhcSessionDeps_ fullModSummary) file -> do
@@ -945,6 +936,7 @@ generateCore :: RunSimplifier -> NormalizedFilePath -> Action (IdeResult ModGuts
945936
generateCore runSimplifier file = do
946937
packageState <- hscEnv <$> use_ GhcSessionDeps file
947938
tm <- use_ TypeCheck file
939+
setPriority priorityGenerateCore
948940
liftIO $ compileModule runSimplifier packageState (tmrModSummary tm) (tmrTypechecked tm)
949941

950942
generateCoreRule :: Recorder (WithPriority Log) -> Rules ()

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ module Development.IDE.Core.Shake(
5151
HLS.getClientConfig,
5252
getPluginConfigAction,
5353
knownTargets,
54+
setPriority,
5455
ideLogger,
5556
actionLogger,
5657
getVirtualFile,
5758
FileVersion(..),
59+
Priority(..),
5860
updatePositionMapping,
5961
updatePositionMappingHelper,
6062
deleteValue, recordDirtyKeys,
@@ -137,7 +139,6 @@ import Development.IDE.Graph.Database (ShakeDatabase,
137139
shakeNewDatabase,
138140
shakeProfileDatabase,
139141
shakeRunDatabaseForKeys)
140-
import Development.IDE.Graph.Internal.Profile (collectProfileMemory)
141142
import Development.IDE.Graph.Rule
142143
import Development.IDE.Types.Action
143144
import Development.IDE.Types.Diagnostics
@@ -717,7 +718,6 @@ shakeShut IdeState{..} = do
717718
-- request so we first abort that.
718719
for_ runner cancelShakeSession
719720
void $ shakeDatabaseProfile shakeDb
720-
void $ collectProfileMemory shakeDb
721721
progressStop $ progress shakeExtras
722722
stopMonitoring
723723

@@ -1307,6 +1307,11 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
13071307
| otherwise = c
13081308

13091309

1310+
newtype Priority = Priority Double
1311+
1312+
setPriority :: Priority -> Action ()
1313+
setPriority (Priority p) = reschedule p
1314+
13101315
ideLogger :: IdeState -> Logger
13111316
ideLogger IdeState{shakeExtras=ShakeExtras{logger}} = logger
13121317

0 commit comments

Comments
 (0)