Skip to content

Go to definition / open link for file path in include_str should work for non-Rust files #11025

Open
@fmease

Description

@fmease
Member

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_strs 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

cies

cies commented on May 15, 2025

@cies

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

ChayimFriedman2 commented on May 15, 2025

@ChayimFriedman2
Contributor

I wonder: can we, instead of detecting included files, just let users configure what files they include? @Veykril

cies

cies commented on May 15, 2025

@cies

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 and sql in the value.

Veykril

Veykril commented on May 15, 2025

@Veykril
Member

I wonder: can we, instead of detecting included files, just let users configure what files they include? @Veykril

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

cies commented on May 19, 2025

@cies

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @cies@Veykril@fmease@ChayimFriedman2

      Issue actions

        Go to definition / open link for file path in `include_str` should work for non-Rust files · Issue #11025 · rust-lang/rust-analyzer