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

Avoid unnecessary Target canonicalisation in Session setup #2359

Merged
merged 13 commits into from
Nov 29, 2021
Merged
4 changes: 2 additions & 2 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,11 @@ fromTargetId is exts (GHC.TargetModule mod) env dep = do
, i <- is
, boot <- ["", "-boot"]
]
locs <- mapM (fmap toNormalizedFilePath' . canonicalizePath) fps
let locs = map toNormalizedFilePath' fps
return [TargetDetails (TargetModule mod) env dep locs]
-- For a 'TargetFile' we consider all the possible module names
fromTargetId _ _ (GHC.TargetFile f _) env deps = do
nf <- toNormalizedFilePath' <$> canonicalizePath f
let nf = toNormalizedFilePath' f
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
let nf = toNormalizedFilePath' f
nf <- toNormalizedFilePath' <$> makeAbsolute f

This might be better to make sure the paths are absolute but let's see what CI says

return [TargetDetails (TargetFile nf) env deps [nf]]

toFlagsMap :: TargetDetails -> [(NormalizedFilePath, (IdeResult HscEnvEq, DependencyInfo))]
Expand Down
10 changes: 10 additions & 0 deletions ghcide/test/data/symlink/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

cradle:
direct:
arguments:
- -i
- -isrc
- -iother_loc/
- other_loc/Sym.hs
- src/Foo.hs
- -Wall
Empty file.
4 changes: 4 additions & 0 deletions ghcide/test/data/symlink/some_loc/Sym.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Sym where

foo :: String
foo = ""
4 changes: 4 additions & 0 deletions ghcide/test/data/symlink/src/Foo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Foo where

import Sym

13 changes: 13 additions & 0 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ main = do
, pluginParsedResultTests
, preprocessorTests
, thTests
, symlinkTests
, safeTests
, unitTests
, haddockTests
Expand Down Expand Up @@ -4055,6 +4056,18 @@ thTests =
expectDiagnostics [ ( cPath, [(DsWarning, (3, 0), "Top-level binding with no type signature: a :: A")] ) ]
]

-- | Tests for projects that use symbolic links one way or another
symlinkTests :: TestTree
symlinkTests =
testGroup "Projects using Symlinks"
[ testCase "Module is symlinked" $ runWithExtraFiles "symlink" $ \dir -> do
liftIO $ createFileLink (dir </> "some_loc" </> "Sym.hs") (dir </> "other_loc" </> "Sym.hs")
let fooPath = dir </> "src" </> "Foo.hs"
_ <- openDoc fooPath "haskell"
expectDiagnosticsWithTags [("src" </> "Foo.hs", [(DsWarning, (2, 0), "The import of 'Sym' is redundant", Just DtUnnecessary)])]
pure ()
]

-- | test that TH is reevaluated on typecheck
thReloadingTest :: Bool -> TestTree
thReloadingTest unboxed = testCase name $ runWithExtraFiles dir $ \dir -> do
Expand Down