Skip to content

Commit 1bd0bc4

Browse files
committed
Wrap the entire feature under ExperimentalFeatures
1 parent b858e82 commit 1bd0bc4

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Sources/SKCore/ExperimentalFeatures.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ public enum ExperimentalFeature: String, Codable, Sendable, CaseIterable {
1818

1919
/// Add `--experimental-prepare-for-indexing` to the `swift build` command run to prepare a target for indexing.
2020
case swiftpmPrepareForIndexing = "swiftpm-prepare-for-indexing"
21+
22+
/// Enable showing macro expansions via `ShowDocumentRequest`
23+
case showMacroExpansions = "show-macro-expansions"
2124
}

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,18 @@ extension SwiftLanguageService {
819819

820820
var canInlineMacro = false
821821

822+
let showMacroExpansionsIsEnabled = await self.sourceKitLSPServer?.options.experimentalFeatures.contains(
823+
.showMacroExpansions
824+
)
825+
822826
var refactorActions = cursorInfoResponse.refactorActions.compactMap {
823827
let lspCommand = $0.asCommand()
824828
canInlineMacro = $0.actionString == "source.refactoring.kind.inline.macro"
829+
830+
if !(showMacroExpansionsIsEnabled != nil && showMacroExpansionsIsEnabled!) {
831+
canInlineMacro = false
832+
}
833+
825834
return CodeAction(title: $0.title, kind: .refactor, command: lspCommand)
826835
}
827836

@@ -951,7 +960,10 @@ extension SwiftLanguageService {
951960
public func executeCommand(_ req: ExecuteCommandRequest) async throws -> LSPAny? {
952961
if let command = req.swiftCommand(ofType: SemanticRefactorCommand.self) {
953962
return try await semanticRefactoring(command)
954-
} else if let command = req.swiftCommand(ofType: ExpandMacroCommand.self) {
963+
} else if let command = req.swiftCommand(ofType: ExpandMacroCommand.self),
964+
let experimentalFeatures = await self.sourceKitLSPServer?.options.experimentalFeatures,
965+
experimentalFeatures.contains(.showMacroExpansions)
966+
{
955967
return try await expandMacro(command)
956968
} else {
957969
throw ResponseError.unknown("unknown command \(req.command)")

Tests/SourceKitLSPTests/ExecuteCommandTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ final class ExecuteCommandTests: XCTestCase {
177177
}
178178
""",
179179
],
180-
manifest: SwiftPMTestProject.macroPackageManifest
180+
manifest: SwiftPMTestProject.macroPackageManifest,
181+
serverOptions: .init(swiftPublishDiagnosticsDebounceDuration: 0, experimentalFeatures: [.showMacroExpansions])
181182
)
182183
try await SwiftPMTestProject.build(at: project.scratchDirectory)
183184

0 commit comments

Comments
 (0)