Skip to content

Highlight struct field access as a field - #1378

Open
integraledelebesgue wants to merge 1 commit into
mainfrom
fix/semantic-highlighting-field-access
Open

Highlight struct field access as a field#1378
integraledelebesgue wants to merge 1 commit into
mainfrom
fix/semantic-highlighting-field-access

Conversation

@integraledelebesgue

@integraledelebesgue integraledelebesgue commented Jul 24, 2026

Copy link
Copy Markdown
Member

The right-hand side of a member access like p.x is not a resolved item nor a
pattern, so it was left unhighlighted (or painted as the macro inside an inline
macro). Resolve it through the semantic member access expression and highlight it
as a field.

@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-macro-declaration-name branch from a5eee47 to 1ab9c6e Compare July 24, 2026 11:50
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-field-access branch from 06ff0df to a1958f2 Compare July 24, 2026 11:50
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-macro-declaration-name branch from 1ab9c6e to c9672ca Compare July 24, 2026 14:24
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-field-access branch from a1958f2 to ae1c220 Compare July 24, 2026 14:24
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-macro-declaration-name branch from c9672ca to e886929 Compare August 4, 2026 10:29
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-field-access branch from ae1c220 to f858ae7 Compare August 4, 2026 10:29
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-macro-declaration-name branch from e886929 to 6360f02 Compare August 4, 2026 10:36
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-field-access branch from f858ae7 to 58273e2 Compare August 4, 2026 10:36
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-macro-declaration-name branch from 6360f02 to b630e6b Compare August 4, 2026 10:41
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-field-access branch from 58273e2 to e83f2ba Compare August 4, 2026 10:41
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-macro-declaration-name branch from b630e6b to 06e3200 Compare August 5, 2026 09:31
Base automatically changed from fix/semantic-highlighting-macro-declaration-name to main August 5, 2026 10:06
The right-hand side of a member access like `p.x` is not a resolved item nor a
pattern, so it was left unhighlighted (or painted as the macro inside an inline
macro). Resolve it through the semantic member access expression and highlight it
as a field.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@integraledelebesgue
integraledelebesgue force-pushed the fix/semantic-highlighting-field-access branch from e83f2ba to 92c617a Compare August 5, 2026 10:15
@integraledelebesgue
integraledelebesgue marked this pull request as ready for review August 5, 2026 10:15
@integraledelebesgue
integraledelebesgue requested a review from a team as a code owner August 5, 2026 10:15
@integraledelebesgue
integraledelebesgue requested review from maciektr, piotmag769 and wawel37 and removed request for a team and maciektr August 5, 2026 10:15
@Arcticae
Arcticae self-requested a review August 12, 2026 10:34

/// Resolves the right-hand side of a struct member access expression (e.g. the `x` in `p.x`)
/// to a [`SemanticTokenKind::Field`].
fn from_member_access(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially a copy of what we already have in finder.rs:409 (try_member function). Please try to reuse that, i think it's applicable here.

let expr_id = db.lookup_expr_by_ptr(function_id, binary_expr.stable_ptr(db).into()).ok()?;
let member_access = match db.expr_semantic(function_id, expr_id) {
Expr::MemberAccess(member_access) => member_access,
Expr::Snapshot(snapshot) => match db.expr_semantic(function_id, snapshot.inner) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably have tests that cover snapshots behavior if we support those paths.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants