Skip to content

Commit be00bd2

Browse files
committed
Manually inject ExpandMacroCommand into retrieveRefactorCodeActions upon an "Inline Macro" from sourcekitd
1 parent 02f166b commit be00bd2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,15 +799,27 @@ extension SwiftLanguageService {
799799
additionalParameters: additionalCursorInfoParameters
800800
)
801801

802-
return cursorInfoResponse.refactorActions.compactMap {
802+
var canInlineMacro = false
803+
804+
var refactorActions = cursorInfoResponse.refactorActions.compactMap {
803805
do {
804806
let lspCommand = try $0.asCommand()
807+
canInlineMacro = $0.title == "Inline Macro"
805808
return CodeAction(title: $0.title, kind: .refactor, command: lspCommand)
806809
} catch {
807810
logger.log("Failed to convert SwiftCommand to Command type: \(error.forLogging)")
808811
return nil
809812
}
810813
}
814+
815+
if (canInlineMacro) {
816+
let expandMacroCommand = try! ExpandMacroCommand(positionRange: params.range, textDocument: params.textDocument)
817+
.asCommand()
818+
819+
refactorActions.append(CodeAction(title: expandMacroCommand.title, kind: .refactor, command: expandMacroCommand))
820+
}
821+
822+
return refactorActions
811823
}
812824

813825
func retrieveQuickFixCodeActions(_ params: CodeActionRequest) async throws -> [CodeAction] {

0 commit comments

Comments
 (0)