sailfish icon indicating copy to clipboard operation
sailfish copied to clipboard

Rust-analyzer unable to open compiled template file

Open jcuffe opened this issue 1 year ago • 10 comments

My VSCode's rust-analyzer is reporting an error while attempting to load the output file specified by the derive macro: image

I think it's likely that I'm seeing this due to some improper configuration, but I'm not sure where to look. I've verified that the file exists, and this error isn't shown when running cargo clippy.

jcuffe avatar Jul 10 '24 16:07 jcuffe

This happens maybe because rust-analyzer cannot open non .rs files. If you close that file from the editor it stops showing.

bismitpanda avatar Jul 19 '24 15:07 bismitpanda

I have the same issue, and It seems to be caused by a include! macro in sailfish-compiler, I would've debugged it but unfortunately I don't have time

ghost avatar Jul 19 '24 16:07 ghost

I am facing this same problem. Is there a way to fix this?

@panda-dev24 what do you mean by "if you close that file from the editor"? And why would that stop showing it?

Pranoy1c avatar Aug 19 '24 07:08 Pranoy1c

I am facing this same problem. Is there a way to fix this?

@panda-dev24 what do you mean by "if you close that file from the editor"? And why would that stop showing it?

It seems like it is an issue with rust-analyzer not being able to include non rs files. So if you close the file from the editor, rust analyzer stops complaining.

bismitpanda avatar Aug 19 '24 07:08 bismitpanda

I posted this on Stack Overflow and the answer was that:

Since sailfish compiles the templates into files without any extension, it is not found by rust-analyzer.

This can be resolved when either sailfish creates and uses .rs files

https://stackoverflow.com/a/78886929/1634905

Can Sailfish create files with .rs extension?

Pranoy1c avatar Aug 19 '24 17:08 Pranoy1c

This line

output_file.push(filename_hash(&input_file, &config));

If it is changed to add the .rs extension after the filename_hash function call, it will be resolved. But I am not sure the file produced is valid rust.

bismitpanda avatar Aug 20 '24 02:08 bismitpanda

I am also experiencing this same issue. It would be nice to not have this be a glaring error in my editor (neovim) even if it compiles fine.

clispios avatar Nov 09 '24 20:11 clispios

In VS Code, disabling macro errors solved it, but this workaround may not be desirable for most devs.

Add to settings.json: "rust-analyzer.diagnostics.disabled": ["macro-error"]

RenanSvarozhich avatar Feb 14 '25 07:02 RenanSvarozhich

If it is changed to add the .rs extension after the filename_hash function call, it will be resolved. But I am not sure the file produced is valid rust.

Maybe worth making a PR for this if it's enough to fix the issue with error propagation? The output does look like valid Rust (as expected, I think).

RReverser avatar Aug 16 '25 21:08 RReverser

If it is changed to add the .rs extension after the filename_hash function call, it will be resolved. But I am not sure the file produced is valid rust.

I tried it, and it didn't fix the issue, I'm still getting

failed to load file `/root/sellfish-test/target/debug/build/sailfish-compiler-d90363d14149b3b4/out/templates/16d34ee100f49deb-072575648b4d64de.rs`

HKalbasi avatar Sep 10 '25 20:09 HKalbasi