mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
map semantic refactoring kinds to specific LSP code action kinds
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user