Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions Sources/SwiftLanguageService/SemanticRefactorCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ package struct SemanticRefactorCommand: SwiftCommand {
CodingKeys.textDocument.stringValue: textDocument.encodeToLSPAny(),
])
}

/// Maps the SourceKit action string to an appropriate LSP CodeActionKind.
///
/// SourceKit uses identifiers like `source.refactoring.kind.extract.expr`
/// which this property maps to LSP kinds like `refactor.extract`.
package var lspKind: CodeActionKind {
if actionString.contains(".extract.") {
return .refactorExtract
} else if actionString.contains(".inline.") {
return .refactorInline
} else {
return .refactor
}
}
}

extension Array where Element == SemanticRefactorCommand {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftLanguageService/SwiftLanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ extension SwiftLanguageService {
canInlineMacro = $0.actionString == "source.refactoring.kind.inline.macro"
}

return CodeAction(title: $0.title, kind: .refactor, command: lspCommand)
return CodeAction(title: $0.title, kind: $0.lspKind, command: lspCommand)
}

if canInlineMacro {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/CodeActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ final class CodeActionTests: SourceKitLSPTestCase {
)
let expectedCodeAction = CodeAction(
title: "Extract Method",
kind: .refactor,
kind: .refactorExtract,
command: expectedCommand
)
var resultActions = try XCTUnwrap(result?.codeActions)
Expand Down