-
-
Notifications
You must be signed in to change notification settings - Fork 392
Refactor hls-test-util and reduce getCurrentDirectory after initilization #4231
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
Changes from 102 commits
e6595bb
25108f4
542ea26
f7611a2
67438ef
9238ff6
8c709ab
5b15ebf
2eae58b
f2c1c61
308e726
543b270
2baa0c9
2ebfafc
042df98
f8f37a0
6a11d1e
7dce0f3
289528a
ca1c2b8
a3dc7ce
1d0f544
7254731
2a25a1f
3997849
e2ff7d0
91d31d8
edca60d
17e3305
4c88650
c0ed673
8223c65
9882ede
fc745c9
9eb3763
80bd4de
836c1b7
faf0cc7
887f8ed
1320577
8826256
53cfa5f
5dc3035
f3cd2e2
9298cc0
2735555
785d22a
92b8bae
1bb8c51
3a5c2cf
bb45003
166bbe9
1844682
48bc29b
54a2330
9c89410
0d4482f
6dfe592
c105dc7
f914c08
f386043
01f1437
37eacc9
7fff110
5ecce5a
f3305a5
2b9a92b
f831bf2
5579952
e4aed03
3723307
a0d64bf
a1b5927
7476dc4
b6d5e92
57366e7
ba50200
2f60c23
06dfac4
afb525b
173b580
94f94ae
e7ec5c9
a09ea8a
e5297b9
e7a81a3
c034ac4
3c7cbfa
eda61af
b75333e
fd1632f
aecf27b
c91bafb
d71cb29
b593e69
a97281c
f75391d
f77c154
6656c2e
50d6a2f
0362913
70d4d31
732d928
99d66e3
83006ad
ca50997
27474b2
2142128
03e21e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment still relevant? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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
|
||
, regenerate = regenerateHiFile session f ms | ||
} | ||
r <- loadInterface (hscEnv session) ms linkableType recompInfo | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like a good idea, some places we might need this. The ones from ghc should depend on how we load the file into There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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
|
||
then Just <$> getModTime obj_file | ||
else pure Nothing | ||
case mobj_time of | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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
|
||
initNameCache, | ||
knownKeyNames) | ||
import Development.IDE.GHC.Orphans () | ||
|
@@ -527,6 +527,30 @@ | |
-- ^ 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. | ||
-- | ||
-- use `getCurrentDirectory` makes it more difficult to run the tests, as we spawn one thread of HLS per test case. | ||
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-- 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, but we still need this now, | ||
-- since a lot of places in the codebase still rely on it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't quite get this, which |
||
-- We can drop it in the future when the condition meets: | ||
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-- 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 | ||
|
@@ -535,6 +559,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
|
||
} | ||
|
||
|
||
|
@@ -623,11 +649,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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.