Stream: t-compiler/rust-analyzer

Topic: Attaching diagnostics to tokens

Jonas Schievink [he/him] (Nov 27 2020 at 12:43, on Zulip):

I'd like to attach a diagnostic to a specific token in an attribute. This token is not its own syntax node, since it's just part of the attributes TokenTree.

Is there any existing way to accomplish this? I don't see any, since diagnostics are always attached to SyntaxNodePtrs, which only work for nodes, not SyntaxElements.

Florian Diebold (Nov 27 2020 at 12:51, on Zulip):

on the IDE level the diagnostic just has a TextRange, so it should be possible to narrow the range during diagnostic collection there. You could use the token ID of the token in the tree in the HIR diagnostic, I guess?

Jonas Schievink [he/him] (Nov 27 2020 at 12:55, on Zulip):

hmm, yeah, that's right

matklad (Nov 28 2020 at 15:07, on Zulip):

Yeah, the idea is that diagnostic struct are more semantic-based, and that rendering them into specific ranges is handled by an IDE. It might make sense to document that somewhere though.

Last update: Jul 29 2021 at 08:00UTC