Skip to content

Commit 74b2921

Browse files
authored
Merge pull request #226 from benlangmuir/support-the-unsupported
[codeActions] Ignore "supportedKinds", which isn't really an opt-in list
2 parents 798befa + a88ab45 commit 74b2921

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

Sources/LanguageServerProtocol/Requests/CodeActionRequest.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,11 @@ public enum CodeActionRequestResponse: ResponseType, Codable, Equatable {
5656
case commands([Command])
5757

5858
public init(codeActions: [CodeAction], clientCapabilities: TextDocumentClientCapabilities.CodeAction?) {
59-
if let literalSupport = clientCapabilities?.codeActionLiteralSupport {
60-
let supportedKinds = literalSupport.codeActionKind.valueSet
61-
self = .codeActions(codeActions.filter {
62-
if let kind = $0.kind {
63-
return supportedKinds.contains(kind)
64-
} else {
65-
// The client guarantees that unsupported kinds will be treated,
66-
// so it's probably safe to include unspecified kinds into the result.
67-
return true
68-
}
69-
})
59+
if clientCapabilities?.codeActionLiteralSupport != nil {
60+
// The client guarantees that unsupported kinds will be handled, and in
61+
// practice some clients use `"codeActionKind":{"valueSet":[]}`, since
62+
// they support all kinds anyway.
63+
self = .codeActions(codeActions)
7064
} else {
7165
self = .commands(codeActions.compactMap { $0.command })
7266
}

Tests/SourceKitTests/CodeActionTests.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ final class CodeActionTests: XCTestCase {
7777
XCTAssertEqual(commands, [command])
7878
}
7979

80-
func testCodeActionResponseRespectsSupportedKinds() {
80+
func testCodeActionResponseIgnoresSupportedKinds() {
81+
// The client guarantees that unsupported kinds will be handled, and in
82+
// practice some clients use `"codeActionKind":{"valueSet":[]}`, since
83+
// they support all kinds anyway. So to avoid filtering all actions, we
84+
// ignore the supported kinds.
85+
8186
let unspecifiedAction = CodeAction(title: "Unspecified")
8287
let refactorAction = CodeAction(title: "Refactor", kind: .refactor)
8388
let quickfixAction = CodeAction(title: "Quickfix", kind: .quickFix)
@@ -103,7 +108,7 @@ final class CodeActionTests: XCTestCase {
103108
from: data)
104109

105110
response = .init(codeActions: actions, clientCapabilities: capabilities)
106-
XCTAssertEqual(response, .codeActions([unspecifiedAction, refactorAction]))
111+
XCTAssertEqual(response, .codeActions([unspecifiedAction, refactorAction, quickfixAction]))
107112

108113
capabilityJson =
109114
"""
@@ -121,7 +126,7 @@ final class CodeActionTests: XCTestCase {
121126
from: data)
122127

123128
response = .init(codeActions: actions, clientCapabilities: capabilities)
124-
XCTAssertEqual(response, .codeActions([unspecifiedAction]))
129+
XCTAssertEqual(response, .codeActions([unspecifiedAction, refactorAction, quickfixAction]))
125130
}
126131

127132
func testCodeActionResponseCommandMetadataInjection() {

Tests/SourceKitTests/XCTestManifests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension CodeActionTests {
1919
static let __allTests__CodeActionTests = [
2020
("testCodeActionResponseCommandMetadataInjection", testCodeActionResponseCommandMetadataInjection),
2121
("testCodeActionResponseLegacySupport", testCodeActionResponseLegacySupport),
22-
("testCodeActionResponseRespectsSupportedKinds", testCodeActionResponseRespectsSupportedKinds),
22+
("testCodeActionResponseIgnoresSupportedKinds", testCodeActionResponseIgnoresSupportedKinds),
2323
("testCommandEncoding", testCommandEncoding),
2424
("testEmptyCodeActionResult", testEmptyCodeActionResult),
2525
("testSemanticRefactorLocalRenameResult", testSemanticRefactorLocalRenameResult),

0 commit comments

Comments
 (0)