-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Fix ghcide handling project root #2543
Fix ghcide handling project root #2543
Conversation
This commit provides an alternate way to grab the project root/current working directory. Prior to this commit the relative filepath "." was hard-coded for both Db and Custom Commands. This results in inconsistent behaviour with how HLS derives it's hiedb location. This new argument to the internal Ghcide Arguments, maps from the executable Arguments `argsCwd` or by grabbing the current working directory. If the user provides an option to `--cwd` we need to make sure we make that filepath absolute. Finally, inside the command handler, if necessary, we will grab the current working directory. We cannot provide a suitable default for this argument, therefore we leave it as a `Maybe FilePath`, even though this path should never be taken.
For my benefit, could you explain the inconsistency or share an example of what could go wrong? |
Yes, I was just taking a look at the state of go-to documentation for external dependencies (#708). I was attempting to follow what @wz1000 had done, and noticed that when This effectively nullifies the point of indexing, as HLS will never pick up the indexed files. The actual call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix lsp --cwd
before merging. It would be great to get tests as well in a later PR
-- when running commands directly from GHCIDE we need to provide the ABSOLUTE path to the project root (that's what HLS uses) | ||
argsCwd <-case argsCwd of | ||
Nothing -> IO.getCurrentDirectory | ||
Just root -> IO.setCurrentDirectory root >> IO.getCurrentDirectory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little obscure: why not just call makeAbsolute
on root
? This relies on you knowing that getCurrentDirectory
returns an absolute path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right and I originally did it that way, but I wanted to match the semantics found throughout out the codebase. For example, in Development.IDE.Main.defaultMain
all of the argCommands
use the same maybe IO.getCurrentDirectory return rootPath
expression to get the project root.
0d80826
to
875a1ce
Compare
@pepeiborra just curious where does |
Also just as an aside would it be worth exploring using |
09d68cc
to
875a1ce
Compare
I think it's (optionally) set by the LSP |
Is this ready to be merged? |
Thanks, @drsooch for the work. |
NOTE: The two commits in this PR are distinct options for handling this issue.This PR provides an alternate way to grab the project root/current working directory.
Prior to this PR the relative filepath "." was hard-coded for both
Db and Custom Commands. This results in inconsistent behavior with how
HLS derives it's hiedb location.
This new argument to the internal Ghcide Arguments, maps from the
executable Arguments
argsCwd
or by grabbing the current workingdirectory. If the user provides an option to
--cwd
we need to makesure we make that filepath absolute.