File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
Sources/SourceKitLSP/Swift Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -1300,21 +1300,20 @@ extension SwiftLanguageServer {
1300
1300
}
1301
1301
1302
1302
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
+ let refactor = try await semanticRefactoring ( command)
1310
1311
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`.
1312
+ guard let newText = refactor. edit. changes ? [ req. textDocument. uri] ? . first? . newText else {
1313
+ return nil
1314
+ }
1316
1315
1317
- return nil
1316
+ return MacroExpansion ( sourceText : newText )
1318
1317
}
1319
1318
1320
1319
public func executeCommand( _ req: ExecuteCommandRequest ) async throws -> LSPAny ? {
You can’t perform that action at this time.
0 commit comments