Skip to content

"Given directory does not exist" from rust-analyzer #6

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

Closed
max-sixty opened this issue Jul 27, 2024 · 5 comments
Closed

"Given directory does not exist" from rust-analyzer #6

max-sixty opened this issue Jul 27, 2024 · 5 comments

Comments

@max-sixty
Copy link

Possibly this is an issue with rust-analyzer, but posting here to see whether it's helpful feedback for this crate.

At https://github.com/PRQL/prql/blob/d3ed63e250b9368fbcbaa1984eef42a382a23aa5/prqlc/prqlc/tests/integration/queries.rs#L14, each of the invocations gets an error "Given directory does not exist".

It compiles & tests fine.

It's not related to the in-path module, since I tried removing that and still get the error:

image
[{
	"resource": "/Users/maximilian/workspace/prql/prqlc/prqlc/tests/integration/queries.rs",
	"owner": "rustc",
	"code": {
		"value": "macro-error",
		"target": {
			"$mid": 1,
			"external": "https://rust-analyzer.github.io/manual.html#macro-error",
			"path": "/manual.html",
			"scheme": "https",
			"authority": "rust-analyzer.github.io",
			"fragment": "macro-error"
		}
	},
	"severity": 8,
	"message": "Given directory does not exist",
	"source": "rust-analyzer",
	"startLineNumber": 52,
	"startColumn": 26,
	"endLineNumber": 52,
	"endColumn": 67
}]

Thanks for any guidance!

@JonathanBrouwer
Copy link
Contributor

JonathanBrouwer commented Jul 30, 2024

I've done some debugging and it seems that Rustc takes "prql" (the workspace directory) as the cwd (current working directory) when running the proc macro, while rust-analyzer takes "prql/prqlc/prqlc" (the subcrate) as the cwd. So this is indeed an issue of rust-analyzer. I think it's best to open an issue on the rust-analyzer repo https://github.com/rust-lang/rust-analyzer/

I learned the following things:

  • Changing the path in the macro to "./tests/integration/queries" fixes the rust-analyzer error but creates a rustc error
  • Opening "prql/prqlc/prqlc" as the folder in VSCode, and changing the path to "./tests/integration/queries" removes the highlighted error completely but then when you try to run the test using cargo it still fails (since it is still part of the workspace, rust-analyzer just doesn't realize it)

@max-sixty
Copy link
Author

Thanks @JonathanBrouwer .

Do you know how the path is represented after the macro is expanded? That could help with a smaller example which I can put into rust-analyzer.

@JonathanBrouwer
Copy link
Contributor

JonathanBrouwer commented Jul 30, 2024

The problem is not how the macro is expanded, the problem is that the environment during execution is wrong.

I've made a simple example:

  • A cargo workspace directory containing am empty file ROOT.txt, and two projects test_macro and test_src
  • test_macro defines a proc macro that during execution calls assert!(Path::new("./ROOT.txt").is_file()). It does not output any tokens.
  • test_src calls the macro defined by test_macro and does nothing else.

I've pushed the code to a branch available here:
https://github.com/binary-banter/test-each-file/tree/repro

Using cargo run, the test_src project builds and runs, however if you open the workspace folder in VS code it will show an error on test_src::src::main.rs line 4

@max-sixty
Copy link
Author

Great case, thanks! I put the issue in

@JonathanBrouwer
Copy link
Contributor

Fixed in rust-analyzer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants