map semantic refactoring kinds to specific LSP code action kinds

This commit is contained in:
loveucifer
2026-01-04 21:00:59 +05:30
parent 53ac4ca1f2
commit d64cc0b463
3 changed files with 16 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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)