Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor hls-test-util and reduce getCurrentDirectory after initilization #4231

Merged
merged 109 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
e6595bb
migrate boot test
soulomoon May 13, 2024
25108f4
Merge branch 'master' into soulomoon/update-ghcide-tests-hls-test-uti…
soulomoon May 13, 2024
542ea26
restrict the cwd to the outermost layer
soulomoon May 14, 2024
f7611a2
remove makeAbsolute
soulomoon May 14, 2024
67438ef
fix import
soulomoon May 14, 2024
9238ff6
fix more dir
soulomoon May 14, 2024
8c709ab
use abs path in template haskell
soulomoon May 14, 2024
5b15ebf
fix reference test
soulomoon May 14, 2024
2eae58b
fix ExceptionTests
soulomoon May 14, 2024
f2c1c61
fix exceptionTests
soulomoon May 14, 2024
308e726
fix
soulomoon May 14, 2024
543b270
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 14, 2024
2baa0c9
fix hls
soulomoon May 14, 2024
2ebfafc
use lsp root dir
soulomoon May 14, 2024
042df98
disable stan test
soulomoon May 14, 2024
f8f37a0
Revert "disable stan test"
soulomoon May 14, 2024
6a11d1e
special function that shift to root
soulomoon May 14, 2024
7dce0f3
remove trace
soulomoon May 14, 2024
289528a
use absolute root
soulomoon May 14, 2024
ca1c2b8
change to test config
soulomoon May 15, 2024
a3dc7ce
add goldenWithTestConfig
soulomoon May 15, 2024
1d0f544
fix
soulomoon May 15, 2024
7254731
fix notes
soulomoon May 15, 2024
2a25a1f
fix windows
soulomoon May 15, 2024
3997849
relatex test
soulomoon May 15, 2024
e2ff7d0
migrate exception tests
soulomoon May 16, 2024
91d31d8
clean up
soulomoon May 16, 2024
edca60d
remove testWithDummyPluginAndCap'
soulomoon May 16, 2024
17e3305
use single thread in test
soulomoon May 16, 2024
4c88650
move semantic tokens test
soulomoon May 16, 2024
c0ed673
clean up DependentFileTest
soulomoon May 16, 2024
8223c65
merge file tree and config root
soulomoon May 16, 2024
9882ede
update doc
soulomoon May 16, 2024
fc745c9
clean up consultCradle
soulomoon May 16, 2024
9eb3763
lift toAbsolute
soulomoon May 16, 2024
80bd4de
clean up
soulomoon May 16, 2024
836c1b7
fix
soulomoon May 16, 2024
faf0cc7
shift to the lsp root if the root is not the current directory
soulomoon May 16, 2024
887f8ed
spawn to tmp dir by default
soulomoon May 16, 2024
1320577
fix exceptionTests
soulomoon May 16, 2024
8826256
clear up
soulomoon May 16, 2024
53cfa5f
migrate THTests
soulomoon May 16, 2024
5dc3035
fix Retrie
soulomoon May 16, 2024
f3cd2e2
migrate ClientSettingsTests CodeLensTests CPPTests CradleTests
soulomoon May 16, 2024
9298cc0
add comment
soulomoon May 16, 2024
2735555
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 17, 2024
785d22a
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 18, 2024
92b8bae
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 18, 2024
1bb8c51
move recorder first
soulomoon May 19, 2024
3a5c2cf
Merge remote-tracking branch 'refs/remotes/origin/soulomoon/remove-se…
soulomoon May 19, 2024
bb45003
rename
soulomoon May 19, 2024
166bbe9
clean up
soulomoon May 19, 2024
1844682
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 20, 2024
48bc29b
fix test
soulomoon May 21, 2024
54a2330
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 22, 2024
9c89410
add timeout
soulomoon May 22, 2024
0d4482f
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 26, 2024
6dfe592
Merge remote-tracking branch 'refs/remotes/origin/soulomoon/remove-se…
soulomoon May 26, 2024
c105dc7
Update hls-test-utils/src/Test/Hls.hs
soulomoon May 26, 2024
f914c08
Merge remote-tracking branch 'refs/remotes/origin/soulomoon/remove-se…
soulomoon May 26, 2024
f386043
add Note [Root Directory], fix comment, fix NotesTest, refactor toAbs…
soulomoon May 26, 2024
01f1437
Update ghcide/src/Development/IDE/Types/HscEnvEq.hs
soulomoon May 26, 2024
37eacc9
format
soulomoon May 26, 2024
7fff110
format
soulomoon May 26, 2024
5ecce5a
format
soulomoon May 26, 2024
f3305a5
fix and clean up
soulomoon May 26, 2024
2b9a92b
clean import
soulomoon May 26, 2024
f831bf2
add comment
soulomoon May 26, 2024
5579952
improve Note [Root Directory]
soulomoon May 26, 2024
e4aed03
add TODO
soulomoon May 26, 2024
3723307
add TODO
soulomoon May 26, 2024
a0d64bf
fix lookupEnv
soulomoon May 26, 2024
a1b5927
typo
soulomoon May 26, 2024
7476dc4
fix Note
soulomoon May 27, 2024
b6d5e92
Update ghcide/src/Development/IDE/Core/Shake.hs
soulomoon May 27, 2024
57366e7
Update ghcide/src/Development/IDE/Core/Shake.hs
soulomoon May 27, 2024
ba50200
Update ghcide/src/Development/IDE/Core/Shake.hs
soulomoon May 27, 2024
2f60c23
Update plugins/hls-refactor-plugin/test/Main.hs
soulomoon May 27, 2024
06dfac4
Update plugins/hls-semantic-tokens-plugin/test/SemanticTokensTest.hs
soulomoon May 27, 2024
afb525b
Update plugins/hls-semantic-tokens-plugin/test/SemanticTokensTest.hs
soulomoon May 27, 2024
173b580
Update plugins/hls-semantic-tokens-plugin/test/SemanticTokensTest.hs
soulomoon May 27, 2024
94f94ae
Update plugins/hls-rename-plugin/test/Main.hs
soulomoon May 27, 2024
e7ec5c9
Update plugins/hls-hlint-plugin/test/Main.hs
soulomoon May 27, 2024
a09ea8a
Update ghcide/src/Development/IDE/Main.hs
soulomoon May 27, 2024
e5297b9
Update plugins/hls-notes-plugin/test/NotesTest.hs
soulomoon May 27, 2024
e7a81a3
Update ghcide/test/exe/Config.hs
soulomoon May 27, 2024
c034ac4
Update plugins/hls-hlint-plugin/test/Main.hs
soulomoon May 27, 2024
3c7cbfa
Update ghcide/test/exe/DiagnosticTests.hs
soulomoon May 27, 2024
eda61af
Update ghcide/test/exe/DiagnosticTests.hs
soulomoon May 27, 2024
b75333e
Update ghcide/test/exe/ReferenceTests.hs
soulomoon May 27, 2024
fd1632f
Update ghcide/test/exe/DependentFileTest.hs
soulomoon May 27, 2024
aecf27b
add doc
soulomoon May 27, 2024
c91bafb
add doc
soulomoon May 27, 2024
d71cb29
format
soulomoon May 27, 2024
b593e69
format
soulomoon May 27, 2024
a97281c
rename
soulomoon May 27, 2024
f75391d
add doc
soulomoon May 27, 2024
f77c154
refine Note [Root Directory]
soulomoon May 27, 2024
6656c2e
add doc
soulomoon May 27, 2024
50d6a2f
drop some toAbsolutePath
soulomoon May 27, 2024
0362913
add doc
soulomoon May 27, 2024
70d4d31
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 27, 2024
732d928
Update ghcide/src/Development/IDE/Core/Shake.hs
soulomoon May 27, 2024
99d66e3
Update ghcide/src/Development/IDE/Core/Shake.hs
soulomoon May 27, 2024
83006ad
refine doc
soulomoon May 27, 2024
ca50997
typo
soulomoon May 27, 2024
27474b2
stylish
soulomoon May 27, 2024
2142128
fix import
soulomoon May 27, 2024
03e21e4
Merge branch 'master' into soulomoon/remove-set-current-dir
soulomoon May 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exe/Wrapper.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE CPP #-}

Check warning on line 1 in exe/Wrapper.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in module Main: Use module export list ▫︎ Found: "module Main where" ▫︎ Perhaps: "module Main (\n module Main\n ) where" ▫︎ Note: an explicit list is usually better
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
Expand Down Expand Up @@ -269,7 +269,8 @@
-- to shut down the LSP.
launchErrorLSP :: Recorder (WithPriority (Doc ())) -> T.Text -> IO ()
launchErrorLSP recorder errorMsg = do
let defaultArguments = Main.defaultArguments (cmapWithPrio pretty recorder) (IdePlugins [])
cwd <- getCurrentDirectory
let defaultArguments = Main.defaultArguments (cmapWithPrio pretty recorder) cwd (IdePlugins [])

inH <- Main.argsHandleIn defaultArguments

Expand Down
6 changes: 3 additions & 3 deletions ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ main = withTelemetryRecorder $ \telemetryRecorder -> do

let arguments =
if argsTesting
then IDEMain.testing (cmapWithPrio LogIDEMain recorder) hlsPlugins
else IDEMain.defaultArguments (cmapWithPrio LogIDEMain recorder) hlsPlugins
then IDEMain.testing (cmapWithPrio LogIDEMain recorder) argsCwd hlsPlugins
else IDEMain.defaultArguments (cmapWithPrio LogIDEMain recorder) argsCwd hlsPlugins

IDEMain.defaultMain (cmapWithPrio LogIDEMain recorder) arguments
{ IDEMain.argsProjectRoot = Just argsCwd
{ IDEMain.argsProjectRoot = argsCwd
, IDEMain.argCommand = argsCommand
, IDEMain.argsHlsPlugins = IDEMain.argsHlsPlugins arguments <> pluginDescToIdePlugins [lspRecorderPlugin]

Expand Down
54 changes: 29 additions & 25 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import HieDb.Create
import HieDb.Types
import HieDb.Utils
import Ide.PluginUtils (toAbsolute)
import qualified System.Random as Random
import System.Random (RandomGen)

Expand Down Expand Up @@ -438,7 +439,8 @@
loadSession recorder = loadSessionWithOptions recorder def

loadSessionWithOptions :: Recorder (WithPriority Log) -> SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession)
loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
let toAbsolutePath = toAbsolute rootDir -- see Note [Root Directory]
cradle_files <- newIORef []
-- Mapping from hie.yaml file to HscEnv, one per hie.yaml file
hscEnvs <- newVar Map.empty :: IO (Var HieMap)
Expand All @@ -459,7 +461,7 @@
-- Sometimes we get C:, sometimes we get c:, and sometimes we get a relative path
-- try and normalise that
-- e.g. see https://github.com/haskell/ghcide/issues/126
res' <- traverse makeAbsolute res
let res' = toAbsolutePath <$> res
return $ normalise <$> res'

dummyAs <- async $ return (error "Uninitialised")
Expand Down Expand Up @@ -521,7 +523,7 @@
packageSetup (hieYaml, cfp, opts, libDir) = do
-- Parse DynFlags for the newly discovered component
hscEnv <- emptyHscEnv ideNc libDir
newTargetDfs <- evalGhcEnv hscEnv $ setOptions cfp opts (hsc_dflags hscEnv)
newTargetDfs <- evalGhcEnv hscEnv $ setOptions cfp opts (hsc_dflags hscEnv) rootDir
let deps = componentDependencies opts ++ maybeToList hieYaml
dep_info <- getDependencyInfo deps
-- Now lookup to see whether we are combining with an existing HscEnv
Expand Down Expand Up @@ -588,7 +590,7 @@
-- HscEnv but set the active component accordingly
hscEnv <- emptyHscEnv ideNc _libDir
let new_cache = newComponentCache recorder optExtensions hieYaml _cfp hscEnv
all_target_details <- new_cache old_deps new_deps
all_target_details <- new_cache old_deps new_deps rootDir

this_dep_info <- getDependencyInfo $ maybeToList hieYaml
let (all_targets, this_flags_map, this_options)
Expand Down Expand Up @@ -632,25 +634,20 @@

let consultCradle :: Maybe FilePath -> FilePath -> IO (IdeResult HscEnvEq, [FilePath])
consultCradle hieYaml cfp = do
lfpLog <- flip makeRelative cfp <$> getCurrentDirectory
let lfpLog = makeRelative rootDir cfp
logWith recorder Info $ LogCradlePath lfpLog

when (isNothing hieYaml) $
logWith recorder Warning $ LogCradleNotFound lfpLog

cradle <- loadCradle recorder hieYaml dir
-- TODO: Why are we repeating the same command we have on line 646?
lfp <- flip makeRelative cfp <$> getCurrentDirectory

cradle <- loadCradle recorder hieYaml rootDir
when optTesting $ mRunLspT lspEnv $
sendNotification (SMethod_CustomMethod (Proxy @"ghcide/cradle/loaded")) (toJSON cfp)

-- Display a user friendly progress message here: They probably don't know what a cradle is
let progMsg = "Setting up " <> T.pack (takeBaseName (cradleRootDir cradle))
<> " (for " <> T.pack lfp <> ")"
<> " (for " <> T.pack lfpLog <> ")"
eopts <- mRunLspTCallback lspEnv (\act -> withIndefiniteProgress progMsg Nothing NotCancellable (const act)) $
withTrace "Load cradle" $ \addTag -> do
addTag "file" lfp
addTag "file" lfpLog
old_files <- readIORef cradle_files
res <- cradleToOptsAndLibDir recorder (sessionLoading clientConfig) cradle cfp old_files
addTag "result" (show res)
Expand All @@ -668,7 +665,7 @@
InstallationMismatch{..} ->
return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
InstallationChecked _compileTime _ghcLibCheck -> do
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))

Check warning on line 668 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in loadSessionWithOptions in module Development.IDE.Session: Use atomicModifyIORef'_ ▫︎ Found: "atomicModifyIORef' cradle_files (\\ xs -> (cfp : xs, ()))" ▫︎ Perhaps: "atomicModifyIORef'_ cradle_files ((:) cfp)"
session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
-- Failure case, either a cradle error or the none cradle
Left err -> do
Expand Down Expand Up @@ -713,7 +710,7 @@
modifyVar_ hscEnvs (const (return Map.empty))

v <- Map.findWithDefault HM.empty hieYaml <$> readVar fileToFlags
cfp <- makeAbsolute file
let cfp = toAbsolutePath file
case HM.lookup (toNormalizedFilePath' cfp) v of
Just (opts, old_di) -> do
deps_ok <- checkDependencyInfo old_di
Expand All @@ -735,7 +732,7 @@
-- before attempting to do so.
let getOptions :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])
getOptions file = do
ncfp <- toNormalizedFilePath' <$> makeAbsolute file
let ncfp = toNormalizedFilePath' (toAbsolutePath file)
cachedHieYamlLocation <- HM.lookup ncfp <$> readVar filesMap
hieYaml <- cradleLoc file
sessionOpts (join cachedHieYamlLocation <|> hieYaml, file) `Safe.catch` \e ->
Expand Down Expand Up @@ -814,19 +811,20 @@
-> TargetId
-> IdeResult HscEnvEq
-> DependencyInfo
-> FilePath -- ^ root dir, see Note [Root Directory]
-> IO [TargetDetails]
-- For a target module we consider all the import paths
fromTargetId is exts (GHC.TargetModule modName) env dep = do
fromTargetId is exts (GHC.TargetModule modName) env dep dir = do
soulomoon marked this conversation as resolved.
Show resolved Hide resolved
let fps = [i </> moduleNameSlashes modName -<.> ext <> boot
| ext <- exts
, i <- is
, boot <- ["", "-boot"]
]
locs <- mapM (fmap toNormalizedFilePath' . makeAbsolute) fps
let locs = fmap (toNormalizedFilePath' . toAbsolute dir) fps
return [TargetDetails (TargetModule modName) env dep locs]
-- For a 'TargetFile' we consider all the possible module names
fromTargetId _ _ (GHC.TargetFile f _) env deps = do
nf <- toNormalizedFilePath' <$> makeAbsolute f
fromTargetId _ _ (GHC.TargetFile f _) env deps dir = do
let nf = toNormalizedFilePath' $ toAbsolute dir f
let other
| "-boot" `isSuffixOf` f = toNormalizedFilePath' (L.dropEnd 5 $ fromNormalizedFilePath nf)
| otherwise = toNormalizedFilePath' (fromNormalizedFilePath nf ++ "-boot")
Expand Down Expand Up @@ -915,8 +913,9 @@
-> HscEnv -- ^ An empty HscEnv
-> [ComponentInfo] -- ^ New components to be loaded
-> [ComponentInfo] -- ^ old, already existing components
-> FilePath -- ^ root dir, see Note [Root Directory]
-> IO [ [TargetDetails] ]
newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis dir = do
let cis = Map.unionWith unionCIs (mkMap new_cis) (mkMap old_cis)
-- When we have multiple components with the same uid,
-- prefer the new one over the old.
Expand Down Expand Up @@ -961,7 +960,7 @@

forM (Map.elems cis) $ \ci -> do
let df = componentDynFlags ci
let createHscEnvEq = maybe newHscEnvEqPreserveImportPaths newHscEnvEq cradlePath
let createHscEnvEq = maybe newHscEnvEqPreserveImportPaths (newHscEnvEq dir) cradlePath
thisEnv <- do
#if MIN_VERSION_ghc(9,3,0)
-- In GHC 9.4 we have multi component support, and we have initialised all the units
Expand All @@ -986,7 +985,7 @@
logWith recorder Debug $ LogNewComponentCache (targetEnv, targetDepends)
evaluate $ liftRnf rwhnf $ componentTargets ci

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

return (L.nubOrdOn targetTarget ctargets)
Expand Down Expand Up @@ -1171,8 +1170,13 @@
putCmdLineState (unit_str : units)

-- | Throws if package flags are unsatisfiable
setOptions :: GhcMonad m => NormalizedFilePath -> ComponentOptions -> DynFlags -> m (NonEmpty (DynFlags, [GHC.Target]))
setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
setOptions :: GhcMonad m
=> NormalizedFilePath
-> ComponentOptions
-> DynFlags
-> FilePath -- ^ root dir, see Note [Root Directory]
-> m (NonEmpty (DynFlags, [GHC.Target]))
setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
((theOpts',_errs,_warns),units) <- processCmdLineP unit_flags [] (map noLoc theOpts)
case NE.nonEmpty units of
Just us -> initMulti us
Expand All @@ -1195,7 +1199,7 @@
--
-- If we don't end up with a target for the current file in the end, then
-- we will report it as an error for that file
abs_fp <- liftIO $ makeAbsolute (fromNormalizedFilePath cfp)
let abs_fp = toAbsolute rootDir (fromNormalizedFilePath cfp)
let special_target = Compat.mkSimpleTarget df abs_fp
pure $ (df, special_target : targets) :| []
where
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Development.IDE.Core.Shake as X (FastResult (..),
defineNoDiagnostics,
getClientConfig,
getPluginConfigAction,
ideLogger,
ideLogger, rootDir,
runIdeAction,
shakeExtras, use,
useNoFile,
Expand Down
9 changes: 4 additions & 5 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@
import qualified Language.LSP.Server as LSP
import Language.LSP.VFS
import Prelude hiding (mod)
import System.Directory (doesFileExist,
makeAbsolute)
import System.Directory (doesFileExist)
import System.Info.Extra (isWindows)


Expand Down Expand Up @@ -719,13 +718,13 @@

defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \GhcSession file -> do
IdeGhcSession{loadSessionFun} <- useNoFile_ GhcSessionIO
-- loading is always returning a absolute path now
(val,deps) <- liftIO $ loadSessionFun $ fromNormalizedFilePath file

-- add the deps to the Shake graph
let addDependency fp = do
-- VSCode uses absolute paths in its filewatch notifications
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still relevant?

Copy link
Collaborator Author

@soulomoon soulomoon May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it here as the remainder.

afp <- liftIO $ makeAbsolute fp
let nfp = toNormalizedFilePath' afp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we guaranteed that it is already absolute? Or do we just no longer care?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We absolute them in up stream function. The 'loadSessionFun'

let nfp = toNormalizedFilePath' fp
itExists <- getFileExists nfp
when itExists $ void $ do
use_ GetModificationTime nfp
Expand Down Expand Up @@ -823,7 +822,7 @@
{ source_version = ver
, old_value = m_old
, get_file_version = use GetModificationTime_{missingFileDiagnostics = False}
, get_linkable_hashes = \fs -> map (snd . fromJust . hirCoreFp) <$> uses_ GetModIface fs

Check warning on line 825 in ghcide/src/Development/IDE/Core/Rules.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in getModIfaceFromDiskRule in module Development.IDE.Core.Rules: Use fmap ▫︎ Found: "\\ fs -> map (snd . fromJust . hirCoreFp) <$> uses_ GetModIface fs" ▫︎ Perhaps: "fmap (map (snd . fromJust . hirCoreFp)) . uses_ GetModIface"
, regenerate = regenerateHiFile session f ms
}
r <- loadInterface (hscEnv session) ms linkableType recompInfo
Expand Down Expand Up @@ -853,7 +852,7 @@
hie_loc = Compat.ml_hie_file $ ms_location ms
fileHash <- liftIO $ Util.getFileHash hie_loc
mrow <- liftIO $ withHieDb (\hieDb -> HieDb.lookupHieFileFromSource hieDb (fromNormalizedFilePath f))
hie_loc' <- liftIO $ traverse (makeAbsolute . HieDb.hieModuleHieFile) mrow
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc said hieModuleHieFile would return a full path, I guess it is not necessary to absolute it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about this sort of thing. If we need it to be absolute then I think it can be sensible to absolutize it just to be sure... since we don't track it in the types or anything.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should also introduce an abstraction that tracks whether we expect a path to be absolute or relative?

Copy link
Collaborator Author

@soulomoon soulomoon May 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea, some places we might need this.
path from [ghc, hiedb, lsp client, cradle].

The ones from ghc should depend on how we load the file into ghc in sessionloader?

Copy link
Collaborator Author

@soulomoon soulomoon May 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is quite a mess in our codebase, we might need to open an issue and try to sweep and standardize them.

let hie_loc' = HieDb.hieModuleHieFile <$> mrow
case mrow of
Just row
| fileHash == HieDb.modInfoHash (HieDb.hieModInfo row)
Expand Down Expand Up @@ -1105,7 +1104,7 @@
-- thus bump its modification time, forcing this rule to be rerun every time.
exists <- liftIO $ doesFileExist obj_file
mobj_time <- liftIO $
if exists

Check warning on line 1107 in ghcide/src/Development/IDE/Core/Rules.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in getLinkableRule in module Development.IDE.Core.Rules: Use whenMaybe ▫︎ Found: "if exists then Just <$> getModTime obj_file else pure Nothing" ▫︎ Perhaps: "whenMaybe exists (getModTime obj_file)"
then Just <$> getModTime obj_file
else pure Nothing
case mobj_time of
Expand Down
8 changes: 5 additions & 3 deletions ghcide/src/Development/IDE/Core/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ initialise :: Recorder (WithPriority Log)
-> WithHieDb
-> IndexQueue
-> Monitoring
-> FilePath -- ^ Root directory see Note [Root Directory]
-> IO IdeState
initialise recorder defaultConfig plugins mainRule lspEnv debouncer options withHieDb hiedbChan metrics = do
initialise recorder defaultConfig plugins mainRule lspEnv debouncer options withHieDb hiedbChan metrics rootDir = do
shakeProfiling <- do
let fromConf = optShakeProfiling options
fromEnv <- lookupEnv "GHCIDE_BUILD_PROFILING"
Expand All @@ -86,11 +87,12 @@ initialise recorder defaultConfig plugins mainRule lspEnv debouncer options with
hiedbChan
(optShakeOptions options)
metrics
$ do
(do
addIdeGlobal $ GlobalIdeOptions options
ofInterestRules (cmapWithPrio LogOfInterest recorder)
fileExistsRules (cmapWithPrio LogFileExists recorder) lspEnv
mainRule
mainRule)
rootDir

-- | Shutdown the Compiler Service.
shutdown :: IdeState -> IO ()
Expand Down
36 changes: 34 additions & 2 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
-- always stored as real Haskell values, whereas Shake serialises all 'A' values
-- between runs. To deserialise a Shake value, we just consult Values.
module Development.IDE.Core.Shake(
IdeState, shakeSessionInit, shakeExtras, shakeDb,
IdeState, shakeSessionInit, shakeExtras, shakeDb, rootDir,
ShakeExtras(..), getShakeExtras, getShakeExtrasRules,
KnownTargets, Target(..), toKnownFiles,
IdeRule, IdeResult,
Expand Down Expand Up @@ -123,7 +123,7 @@
import Development.IDE.Core.ProgressReporting
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Tracing
import Development.IDE.GHC.Compat (NameCache,

Check warning on line 126 in ghcide/src/Development/IDE/Core/Shake.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in module Development.IDE.Core.Shake: Use fewer imports ▫︎ Found: "import Development.IDE.GHC.Compat\n ( NameCache, initNameCache, knownKeyNames )\nimport Development.IDE.GHC.Compat\n ( NameCacheUpdater(NCU), mkSplitUniqSupply, upNameCache )\n" ▫︎ Perhaps: "import Development.IDE.GHC.Compat\n ( NameCache,\n initNameCache,\n knownKeyNames,\n NameCacheUpdater(NCU),\n mkSplitUniqSupply,\n upNameCache )\n"
initNameCache,
knownKeyNames)
import Development.IDE.GHC.Orphans ()
Expand Down Expand Up @@ -527,6 +527,33 @@
-- ^ Closes the Shake session
}

-- Note [Root Directory]
-- ~~~~~~~~~~~~~~~~~~~~~
-- We keep track of the root directory explicitly, which is the directory of the project root.
-- We might be setting it via these options with decreasing priority:
--
-- 1. from LSP workspace root, `resRootPath` in `LanguageContextEnv`.
-- 2. command line (--cwd)
-- 3. default to the current directory.
--
-- Using `getCurrentDirectory` makes it more difficult to run the tests, as we spawn one thread of HLS per test case.
-- If we modify the global Variable CWD, via `setCurrentDirectory`, all other test threads are suddenly affected,
-- forcing us to run all integration tests sequentially.
--
-- Also, there might be a race condition if we depend on the current directory, as some plugin might change it.
-- e.g. stylish's `loadConfig`. https://github.com/haskell/haskell-language-server/issues/4234
--
-- But according to https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_workspaceFolders
-- The root dir is deprecated, that means we should cleanup dependency on the project root(Or $CWD) thing gradually,
-- so multi-workspaces can actually be supported when we use absolute path everywhere(might also need some high level design).
-- That might not be possible unless we have everything adapted to it, like 'hlint' and 'evaluation of template haskell'.
-- But we should still be working towards the goal.
--
-- We can drop it in the future once:
-- 1. We can get rid all the usages of root directory in the codebase.
-- 2. LSP version we support actually removes the root directory from the protocol.
--

-- | A Shake database plus persistent store. Can be thought of as storing
-- mappings from @(FilePath, k)@ to @RuleResult k@.
data IdeState = IdeState
Expand All @@ -535,6 +562,8 @@
,shakeExtras :: ShakeExtras
,shakeDatabaseProfile :: ShakeDatabase -> IO (Maybe FilePath)
,stopMonitoring :: IO ()
-- | See Note [Root Directory]
,rootDir :: FilePath
soulomoon marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down Expand Up @@ -623,11 +652,14 @@
-> ShakeOptions
-> Monitoring
-> Rules ()
-> FilePath
soulomoon marked this conversation as resolved.
Show resolved Hide resolved
-- ^ Root directory, this one might be picking up from `LanguageContextEnv`'s `resRootPath`
-- , see Note [Root Directory]
-> IO IdeState
shakeOpen recorder lspEnv defaultConfig idePlugins debouncer
shakeProfileDir (IdeReportProgress reportProgress)
ideTesting@(IdeTesting testing)
withHieDb indexQueue opts monitoring rules = mdo
withHieDb indexQueue opts monitoring rules rootDir = mdo

#if MIN_VERSION_ghc(9,3,0)
ideNc <- initNameCache 'r' knownKeyNames
Expand Down
Loading
Loading