Closed mucinoab closed 1 year ago
Hey @maxbrunsfeld I would really appreciate if you could review this. Thank you.
Is there any review planned soon? This feature is really cool!
The difference with Rust & Python is that in Python, an f string's interpolations are always valid, whereas in Rust it's only valid in certain macro invocations, a regular string with brackets is not an interpolation, so I don't think this makes much sense and is better left to an lsp
This is kind of a new feature for Rust. Announcing Rust 1.58.0: Captured identifiers in format strings
And there is still a lot of work going on to improve things.
My point still stands, it's not valid in all string contexts and rust-analyzer handles this anyways
Sure, maybe it needs to be only in macro context, but the feature exists for other editors like intellij and vscode since at least one year if I remember correctly, so it shouldn't be so hard to implement.
The feature exists in Rust's LSP
Since which version ? Because I can't see any sign of this working in my installation of rust-analyzer 1.71.0. Renaming doesn't apply to the variable inside the string format and coloration is still the same as regular string.
Since which version ? Because I can't see any sign of this working in my installation of rust-analyzer 1.71.0. Renaming doesn't apply to the variable inside the string format and coloration is still the same as regular string.
I can't comment on your IDE/setup, but in Neovim inspecting the LSP semantic tokens shows the following under my cursor
I believe that it is okay for tree-sitter to have features that another system already has.
tree-sitter is designed to be very fast and run on every keystroke, rust analyzer on the other hand is not, it has to do a bunch of additional work and, depending the crate/project, this can take seconds or even minutes.
Two systems with two different goals. @amaanq
I believe that it is okay for tree-sitter to have features that another system already has.
Tree-sitter is not an lsp at all, if so, we'd have knowledge of when an identifier is a type, variable, or function when used anywhere. So that makes no sense
Introducing this would bring false positives in normal strings, rather than false negatives in print-like macro invocations. To me false negatives are better than false positives in this case, anywhere brackets are used would be highlighted incorrectly. You can also solve this with injections by writing a tiny rust format specifier grammar to inject in strings.
Since which version ? Because I can't see any sign of this working in my installation of rust-analyzer 1.71.0. Renaming doesn't apply to the variable inside the string format and coloration is still the same as regular string.
I can't comment on your IDE/setup, but in Neovim inspecting the LSP semantic tokens shows the following under my cursor
![]()
![]()
Hello, I am trying to figure out why I don't get syntax highlighting for string interpolation in rust
I am currently :Inspect
-ing on params
in the line println!("->> {:<12} - handler_hello - {params:?}", "HANDLER");
I'm wondering if I missed something in my config
I based my approach in the python implementation. This is my fist time working with the tree-sitter machinery, please let me know of any issues.
Solves #129