diff --git a/Sources/SwiftLanguageService/SemanticRefactorCommand.swift b/Sources/SwiftLanguageService/SemanticRefactorCommand.swift index 97671413..868ba0aa 100644 --- a/Sources/SwiftLanguageService/SemanticRefactorCommand.swift +++ b/Sources/SwiftLanguageService/SemanticRefactorCommand.swift @@ -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 { diff --git a/Sources/SwiftLanguageService/SwiftLanguageService.swift b/Sources/SwiftLanguageService/SwiftLanguageService.swift index 639a5a64..e213ab0e 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 19e09397..e224d44d 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)