Skip to content

Commit 50d4290

Browse files
committed
Wrap the entire feature under ExperimentalFeatures
1 parent bcbf634 commit 50d4290

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
@@ -833,9 +833,18 @@ extension SwiftLanguageService {
833833

834834
var canInlineMacro = false
835835

836+
let showMacroExpansionsIsEnabled = await self.sourceKitLSPServer?.options.experimentalFeatures.contains(
837+
.showMacroExpansions
838+
)
839+
836840
var refactorActions = cursorInfoResponse.refactorActions.compactMap {
837841
let lspCommand = $0.asCommand()
838842
canInlineMacro = $0.actionString == "source.refactoring.kind.inline.macro"
843+
844+
if !(showMacroExpansionsIsEnabled != nil && showMacroExpansionsIsEnabled!) {
845+
canInlineMacro = false
846+
}
847+
839848
return CodeAction(title: $0.title, kind: .refactor, command: lspCommand)
840849
}
841850

@@ -965,7 +974,10 @@ extension SwiftLanguageService {
965974
public func executeCommand(_ req: ExecuteCommandRequest) async throws -> LSPAny? {
966975
if let command = req.swiftCommand(ofType: SemanticRefactorCommand.self) {
967976
return try await semanticRefactoring(command)
968-
} else if let command = req.swiftCommand(ofType: ExpandMacroCommand.self) {
977+
} else if let command = req.swiftCommand(ofType: ExpandMacroCommand.self),
978+
let experimentalFeatures = await self.sourceKitLSPServer?.options.experimentalFeatures,
979+
experimentalFeatures.contains(.showMacroExpansions)
980+
{
969981
return try await expandMacro(command)
970982
} else {
971983
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)