@@ -1300,21 +1300,22 @@ extension SwiftLanguageServer {
13001300 }
13011301
13021302 public func macroExpansion( _ req: MacroExpansionRequest ) async throws -> MacroExpansion ? {
1303- guard let snapshot = documentManager. latestSnapshot ( req. textDocument. uri) else {
1304- let msg = " failed to find snapshot for url \( req. textDocument. uri) "
1305- log ( msg)
1306- throw ResponseError . unknown ( msg)
1307- }
1308-
1309- let syntaxTree = await syntaxTreeManager. syntaxTree ( for: snapshot)
1303+ let command = SemanticRefactorCommand (
1304+ title: " Expand Macro " ,
1305+ actionString: " source.refactoring.kind.expand.macro " ,
1306+ positionRange: req. position..< req. position,
1307+ textDocument: req. textDocument
1308+ )
1309+
1310+ log ( " Performing refactoring " , level: . warning) // DEBUG
1311+ let refactor = try await semanticRefactoring ( command)
1312+ log ( " Got \( refactor) " , level: . warning) // DEBUG
13101313
1311- // TODO: Find the moduleName, typeName and roles for the macro at the
1312- // position given in the request somehow. Use these to construct
1313- // `ExpansionSpecifier`s and pass them to SourceKitD via the
1314- // `syntacticMacroExpansion` function. Extract the text edits from the
1315- // result and wrap them in `MacroExpansion`.
1314+ guard let newText = refactor. edit. changes ? [ req. textDocument. uri] ? . first? . newText else {
1315+ return nil
1316+ }
13161317
1317- return nil
1318+ return MacroExpansion ( sourceText : newText )
13181319 }
13191320
13201321 public func executeCommand( _ req: ExecuteCommandRequest ) async throws -> LSPAny ? {
0 commit comments