Skip to content

Classify function assignment names as function semantic tokens - #756

Open
wmsci wants to merge 1 commit into
REditorSupport:masterfrom
wmsci:semantic-function-assignment
Open

Classify function assignment names as function semantic tokens#756
wmsci wants to merge 1 commit into
REditorSupport:masterfrom
wmsci:semantic-function-assignment

Conversation

@wmsci

@wmsci wmsci commented Aug 29, 2026

Copy link
Copy Markdown

Hi,

I noticed this issue with the syntax highlighting while using languageserver with the R extension for Visual Studio Code in Cursor. I tried fixing it myself and it works on my machine, so I'm opening this PR in case it is useful.

Problem

When a function is defined with fn <- function() {} and later used as a function call, fn(), those two uses of fn get different semantic token types.

The function call is a SYMBOL_FUNCTION_CALL, so it is marked function. The name on the left of the assignment is only a SYMBOL, so it is marked variable.

Themes colour those types separately, so the same name is coloured differently at the definition and at the function call.

Completion already treats these assigned names as functions (scope_completion_functs_xpath in R/completion.R).

Before

SCR-20260829-spjr

After

SCR-20260829-sqxl

Fix

After the default parse-data map, reclassify a SYMBOL as a function token with the declaration modifier when it is the left-hand name of:

  • fn <- function() {}
  • fn = function() {}
  • fn <- \(x) {}

The same rule is applied on the XML fallback path.

Testing

  • Added cases in tests/testthat/test-semantic-tokens.R

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.

1 participant