Skip to main content

name_at

Function name_at 

Source
pub fn name_at(doc: &DocumentState, offset: usize) -> Option<(String, Span)>
Expand description

Per-document state: source text, analysis results, and cached diagnostics. The NAME under the cursor, and where it is written.

★ ONE RULE, FOUR ASKERS. Go-to-definition, hover, rename and find-references each asked this question for themselves, and each answered it the same wrong way: find the token at the offset, read its text. Inside a View: that token is the whole RawBlock, so all four read the ENTIRE TEMPLATE as the name and matched nothing — the same bug four times, discoverable four separate times. An author hovering {count} got nothing; renaming it was not even offered.

A recorded REFERENCE wins over the token, and inside a template it is the only thing there is: the parser noted every name a template mentions with its file span, precisely because that information exists nowhere else by the time the tokens are all that is left. It is the better answer outside a template too — a reference is a name the index has already placed, where a token is only a string that happens to sit under the cursor.