Description
Split off from #11019. See #11019 (comment).
Go to definition / open link for file paths in include
, include_str
, include_bytes
does work already (#11019 (comment)).
Sadly, this only works if the file extension is rs
. My codebase on the other hand include_str
s JS and CSS files and include_bytes
WOFF files (just like librustdoc!). In such a case, this feature does not work.
I would say more often than not one doesn't include_str
Rust files (contrary to include
). I am not sure if that still counts as jump to definition in the LSP sense but it's reasonable to support (as open link or whatever other mechanism available) in my opinion. I am not familiar with the LSP though.
rust-analyzer version: rust-analyzer version: db2a708 2021-12-13 stable
rustc version: rustc 1.59.0-nightly (48a5999fc 2021-12-01)
Activity
include
macro family #11019cies commentedon May 15, 2025
Came here to request this. I'm using
include_str!()
with SQLx to split out my SQL code in.sql
files that I cannot quickly navigate to, sadly.This is a pretty common workflow on SQLx: it allows VSCode to properly highlight the SQL code (which is does not when it is embedded in Rust code by (raw) string literals).
ChayimFriedman2 commentedon May 15, 2025
I wonder: can we, instead of detecting included files, just let users configure what files they include? @Veykril
cies commentedon May 15, 2025
I found a work around in VSCode:
Instead of naming my files
*.sql
, I name them*.sql.rs
; this way the CRTL-click to goto definition works!Only the SQL code in the files is then highlighted as Rust.
For this I found another workaround, in VSCode:
File > Preferences > Settings
· Search "File associations" · Click on "Add Item" · Add your*.sql.rs
in the key column andsql
in the value.Veykril commentedon May 15, 2025
Probably? That would mean we'd need to add these files to all source roots though, as we don't know which source root is interested in the paths
cies commentedon May 19, 2025
I just found out that SQLx has a macro that takes a filename: https://docs.rs/sqlx/latest/sqlx/macro.query_file.html
That link-to-sql-file-string in the macro invocation is not ctrl-clickable (cannot use to to quickly navigate to the file).
Maybe it should be possible to instruct
rust-analyzer
to specify to means of an annotation that a certain parameter in a macro call contains a link to a file, so all macros like this become easy to navigate through.