-
Notifications
You must be signed in to change notification settings - Fork 314
Add support for clangd's semantic highlighting #388
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
DavidGoldman
merged 5 commits into
swiftlang:main
from
DavidGoldman:semantichighlighting
Apr 12, 2021
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
63ef2c1
Add support for clangd's semantic highlighting
DavidGoldman 06e2a0a
Update CMakeLists.txt for semantic token additions
DavidGoldman fb8a7a9
Add support for the `workspace/semanticTokens/refresh` request
DavidGoldman aea4d70
Add simple clangd semantic highlighting test
DavidGoldman b620657
Minor semantic highlighting fixes for review
DavidGoldman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
Sources/LanguageServerProtocol/Requests/DocumentSemanticTokensDeltaRequest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
public struct DocumentSemanticTokensDeltaRequest: TextDocumentRequest, Hashable { | ||
public static let method: String = "textDocument/semanticTokens/full/delta" | ||
public typealias Response = DocumentSemanticTokensDeltaResponse? | ||
|
||
/// The document to fetch semantic tokens for. | ||
public var textDocument: TextDocumentIdentifier | ||
|
||
/// The result identifier of a previous response, which acts as the diff base for the delta. | ||
/// This can either point to a full response or a delta response, depending on what was | ||
/// last received by the client. | ||
public var previousResultId: String | ||
|
||
public init(textDocument: TextDocumentIdentifier, previousResultId: String) { | ||
self.textDocument = textDocument | ||
self.previousResultId = previousResultId | ||
} | ||
} | ||
|
||
public enum DocumentSemanticTokensDeltaResponse: ResponseType, Codable, Equatable { | ||
case tokens(DocumentSemanticTokensResponse) | ||
case delta(SemanticTokensDelta) | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
if let tokens = try? container.decode(DocumentSemanticTokensResponse.self) { | ||
self = .tokens(tokens) | ||
} else if let delta = try? container.decode(SemanticTokensDelta.self) { | ||
self = .delta(delta) | ||
} else { | ||
let error = "DocumentSemanticTokensDeltaResponse has neither SemanticTokens or SemanticTokensDelta." | ||
throw DecodingError.dataCorruptedError(in: container, debugDescription: error) | ||
} | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
switch self { | ||
case .tokens(let tokens): | ||
try container.encode(tokens) | ||
case .delta(let delta): | ||
try container.encode(delta) | ||
} | ||
} | ||
} | ||
|
||
public struct SemanticTokensDelta: Codable, Hashable { | ||
/// An optional result identifier which enables supporting clients to request semantic token deltas | ||
/// subsequent requests. | ||
public var resultId: String? | ||
|
||
/// The edits to transform a previous result into a new result. | ||
public var edits: [SemanticTokensEdit] | ||
|
||
public init(resultId: String? = nil, edits: [SemanticTokensEdit]) { | ||
self.resultId = resultId | ||
self.edits = edits | ||
} | ||
} | ||
|
||
public struct SemanticTokensEdit: Codable, Hashable { | ||
/// Start offset of the edit. | ||
public var start: UInt | ||
|
||
/// The number of elements to remove. | ||
public var deleteCount: UInt | ||
|
||
/// The elements to insert. | ||
public var data: [UInt]? | ||
DavidGoldman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public init(start: UInt, deleteCount: UInt, data: [UInt]? = nil) { | ||
self.start = start | ||
self.deleteCount = deleteCount | ||
self.data = data | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Sources/LanguageServerProtocol/Requests/DocumentSemanticTokensRangeRequest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
public struct DocumentSemanticTokensRangeRequest: TextDocumentRequest, Hashable { | ||
public static let method: String = "textDocument/semanticTokens/range" | ||
public typealias Response = DocumentSemanticTokensResponse? | ||
|
||
/// The document to fetch semantic tokens for. | ||
public var textDocument: TextDocumentIdentifier | ||
|
||
/// The range to fetch semantic tokens for. | ||
@CustomCodable<PositionRange> | ||
public var range: Range<Position> | ||
|
||
public init(textDocument: TextDocumentIdentifier, range: Range<Position>) { | ||
self.textDocument = textDocument | ||
self.range = range | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Sources/LanguageServerProtocol/Requests/DocumentSemanticTokensRequest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
public struct DocumentSemanticTokensRequest: TextDocumentRequest, Hashable { | ||
public static let method: String = "textDocument/semanticTokens/full" | ||
public typealias Response = DocumentSemanticTokensResponse? | ||
|
||
/// The document to fetch semantic tokens for. | ||
public var textDocument: TextDocumentIdentifier | ||
|
||
public init(textDocument: TextDocumentIdentifier) { | ||
self.textDocument = textDocument | ||
} | ||
} | ||
|
||
public struct DocumentSemanticTokensResponse: ResponseType, Hashable { | ||
/// An optional result identifier which enables supporting clients to request semantic token deltas | ||
/// subsequent requests. | ||
public var resultId: String? | ||
|
||
/// Raw tokens data. | ||
public var data: [UInt] | ||
DavidGoldman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public init(resultId: String? = nil, data: [UInt]) { | ||
self.resultId = resultId | ||
self.data = data | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Sources/LanguageServerProtocol/Requests/WorkspaceSemanticTokensRefreshRequest.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// Sent from the server to the client. Servers can use this to ask clients to | ||
/// refresh semantic tokens for editors for which this server provides semantic | ||
/// tokens, useful in cases of project wide configuration changes. | ||
public struct WorkspaceSemanticTokensRefreshRequest: RequestType, Hashable { | ||
public static let method: String = "workspace/semanticTokens/refresh" | ||
public typealias Response = VoidResponse | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.