Skip to content

Add semantic highlighting for function parameter labels #983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Nov 29, 2023

This highlights arg in the following as a parameter.

func foo(arg: Int) {}
foo(arg: 1)

LSP doesn’t explicitly state what parameter means. clangd uses parameter for parameter declarations, Python also uses parameter for parameter labels.

Here’s how syntax coloring looks with this patch in VS Code with the GitHub light theme (underlined are the changed tokens).

Screenshot 2023-11-29 at 10 16 08

Companion of swiftlang/swift-syntax#2375.

@ahoppen
Copy link
Member Author

ahoppen commented Nov 30, 2023

swiftlang/swift-syntax#2375

@swift-ci Please test

@bnbarham
Copy link
Contributor

There's some documentation, just not in the specification itself - https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers.

IMO the argument name (first name) should be function (as it's part of the function name), the parameter name (and all its references) should be parameter, and the argument label should be the same as the call itself (presumably function too).

Is the screenshot you included just from the syntax tree, or does it include the semantic tokens?

@ahoppen
Copy link
Member Author

ahoppen commented Dec 5, 2023

Good idea with just considering the labels part of the function itself.

Is the screenshot you included just from the syntax tree, or does it include the semantic tokens?

It includes semantic tokens. The two states of syntax highlighting that we have in LSP land are

  1. Inside the editor based on TextMate grammars
  2. Semantic highlighting from the LSP server overlayed on top of the TextMate grammar, which, for Swift is highlighting from swift-syntax + semantic tokens from sourcekitd.

@ahoppen ahoppen force-pushed the ahoppen/parameter-highlighting branch from b8420eb to cb078c2 Compare December 5, 2023 03:01
Token(line: 6, utf16index: 7, length: 8, kind: .struct),
]
)
}

func testArgumentLabels() async throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a first + second name test at all? Is the second name a parameter or an identifier?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, I'd expect one here too since the sourcekitd response could add more information if it wanted to (eg. all params + references could be "parameters").

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a test case

@ahoppen
Copy link
Member Author

ahoppen commented Dec 5, 2023

swiftlang/swift-syntax#2375

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/parameter-highlighting branch from cb078c2 to 7424558 Compare December 6, 2023 18:02
@ahoppen
Copy link
Member Author

ahoppen commented Dec 6, 2023

swiftlang/swift-syntax#2375

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Dec 6, 2023

swiftlang/swift-syntax#2375

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 2d01d5d into swiftlang:main Dec 6, 2023
@ahoppen ahoppen deleted the ahoppen/parameter-highlighting branch December 6, 2023 22:25
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.

2 participants