Skip to content

Provide semantic highlighting for operators in declarations #610

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
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/SourceKitD/sourcekitd_uids.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public struct sourcekitd_values {
public let syntaxtype_doccomment: sourcekitd_uid_t
public let syntaxtype_doccomment_field: sourcekitd_uid_t
public let syntaxtype_keyword: sourcekitd_uid_t
public let syntaxtype_operator: sourcekitd_uid_t
public let syntaxtype_number: sourcekitd_uid_t
public let syntaxtype_string: sourcekitd_uid_t
public let syntaxtype_string_interpolation_anchor: sourcekitd_uid_t
Expand Down Expand Up @@ -388,6 +389,7 @@ public struct sourcekitd_values {
syntaxtype_doccomment = api.uid_get_from_cstr("source.lang.swift.syntaxtype.doccomment")!
syntaxtype_doccomment_field = api.uid_get_from_cstr("source.lang.swift.syntaxtype.doccomment.field")!
syntaxtype_keyword = api.uid_get_from_cstr("source.lang.swift.syntaxtype.keyword")!
syntaxtype_operator = api.uid_get_from_cstr("source.lang.swift.syntaxtype.operator")!
syntaxtype_number = api.uid_get_from_cstr("source.lang.swift.syntaxtype.number")!
syntaxtype_string = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string")!
syntaxtype_string_interpolation_anchor = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string_interpolation_anchor")!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ struct SyntaxHighlightingTokenParser {
values.ref_function_destructor,
values.ref_function_subscript:
return (.method, [])
case values.syntaxtype_operator:
return (.operator, [])
case values.decl_function_operator_prefix,
values.decl_function_operator_postfix,
values.decl_function_operator_infix:
Expand Down
15 changes: 15 additions & 0 deletions Tests/SourceKitLSPTests/SemanticTokensTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ final class SemanticTokensTests: XCTestCase {
Token(line: 3, utf16index: 0, length: 3, kind: .keyword),
Token(line: 3, utf16index: 4, length: 1, kind: .identifier),
Token(line: 3, utf16index: 8, length: 1, kind: .variable),
Token(line: 3, utf16index: 10, length: 1, kind: .operator),
Token(line: 3, utf16index: 12, length: 1, kind: .variable),
// func a() {}
Token(line: 5, utf16index: 0, length: 4, kind: .keyword),
Expand Down Expand Up @@ -488,6 +489,20 @@ final class SemanticTokensTests: XCTestCase {
])
}


func testOperatorDeclaration() {
let text = """
infix operator ?= :ComparisonPrecedence
"""
let tokens = openAndPerformSemanticTokensRequest(text: text)
XCTAssertEqual(tokens, [
Token(line: 0, utf16index: 0, length: 5, kind: .modifier),
Token(line: 0, utf16index: 6, length: 8, kind: .keyword),
Token(line: 0, utf16index: 15, length: 2, kind: .operator),
Token(line: 0, utf16index: 19, length: 20, kind: .identifier),
])
}

func testEmptyEdit() {
let text = """
let x: String = "test"
Expand Down