diff --git a/Sources/SwiftLanguageService/SemanticRefactorCommand.swift b/Sources/SwiftLanguageService/SemanticRefactorCommand.swift index 97671413c..b2e920075 100644 --- a/Sources/SwiftLanguageService/SemanticRefactorCommand.swift +++ b/Sources/SwiftLanguageService/SemanticRefactorCommand.swift @@ -72,6 +72,22 @@ 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.") || actionString.contains(".move.") { + return .refactorExtract + } else if actionString.contains(".inline.") { + return .refactorInline + } else if actionString.contains(".convert.") { + return .refactorRewrite + } else { + return .refactor + } + } } extension Array where Element == SemanticRefactorCommand { diff --git a/Sources/SwiftLanguageService/SwiftLanguageService.swift b/Sources/SwiftLanguageService/SwiftLanguageService.swift index 639a5a64a..e213ab0e7 100644 --- a/Sources/SwiftLanguageService/SwiftLanguageService.swift +++ b/Sources/SwiftLanguageService/SwiftLanguageService.swift @@ -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 { diff --git a/Tests/SourceKitLSPTests/CodeActionTests.swift b/Tests/SourceKitLSPTests/CodeActionTests.swift index 19e093978..e224d44da 100644 --- a/Tests/SourceKitLSPTests/CodeActionTests.swift +++ b/Tests/SourceKitLSPTests/CodeActionTests.swift @@ -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)