Skip to content

session-loader: Set working directory on GHC 9.4+ #3891

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

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
Nothing -> compRoot
Just wdir -> compRoot </> wdir
let dflags''' =
setWorkingDirectory root $
disableWarningsAsErrors $
-- disabled, generated directly by ghcide instead
flip gopt_unset Opt_WriteInterface $
Expand All @@ -1125,7 +1126,7 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags = do
setBytecodeLinkerOptions $
disableOptimisation $
Compat.setUpTypedHoles $
makeDynFlagsAbsolute compRoot
makeDynFlagsAbsolute compRoot -- makeDynFlagsAbsolute already accounts for workingDirectory
dflags''
-- initPackages parses the -package flags and
-- sets up the visibility for each component.
Expand Down
9 changes: 8 additions & 1 deletion ghcide/src/Development/IDE/GHC/Compat/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module Development.IDE.GHC.Compat.Env (
setBackend,
ghciBackend,
Development.IDE.GHC.Compat.Env.platformDefaultBackend,
workingDirectory
workingDirectory,
setWorkingDirectory,
) where

import GHC (setInteractiveDynFlags)
Expand Down Expand Up @@ -91,6 +92,12 @@ hsc_EPS = Env.hsc_unit_env
#if !MIN_VERSION_ghc(9,3,0)
workingDirectory :: a -> Maybe b
workingDirectory _ = Nothing

setWorkingDirectory :: FilePath -> DynFlags -> DynFlags
setWorkingDirectory = const id
#else
setWorkingDirectory :: FilePath -> DynFlags -> DynFlags
setWorkingDirectory p d = d { workingDirectory = Just p }
#endif

setHomeUnitId_ :: UnitId -> DynFlags -> DynFlags
Expand Down
11 changes: 11 additions & 0 deletions ghcide/test/data/working-dir/a/A.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# LANGUAGE TemplateHaskell #-}
module A(th_a) where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Control.Monad.IO.Class

th_a :: DecsQ
th_a = do
str <- makeRelativeToProject "wdtest" >>= liftIO . readFile
[d| a = $(lift str) |]
6 changes: 6 additions & 0 deletions ghcide/test/data/working-dir/a/B.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
module B() where

import A

$th_a
11 changes: 11 additions & 0 deletions ghcide/test/data/working-dir/a/a.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: a
version: 1.0.0
build-type: Simple
cabal-version: >= 1.2
extra-source-files: wdtest

library
build-depends: base, template-haskell
exposed-modules: A B
ghc-options: -Wmissing-signatures
hs-source-dirs: .
1 change: 1 addition & 0 deletions ghcide/test/data/working-dir/a/wdtest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions ghcide/test/data/working-dir/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: a
2 changes: 2 additions & 0 deletions ghcide/test/data/working-dir/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cradle:
cabal: