mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SourceKit] Add request to expand macros syntactically
Expand macros in the specified source file syntactically (without any
module imports, nor typechecking).
Request would look like:
```
{
key.compilerargs: [...]
key.sourcefile: <file name>
key.sourcetext: <source text> (optional)
key.expansions: [<expansion specifier>...]
}
```
`key.compilerargs` are used for getting plugins search paths. If
`key.sourcetext` is not specified, it's loaded from the file system.
Each `<expansion sepecifier>` is
```
{
key.offset: <offset>
key.modulename: <plugin module name>
key.typename: <macro typename>
key.macro_roles: [<macro role UID>...]
}
```
Clients have to provide the module and type names because that's
semantic.
Response is a `CategorizedEdits` just like (semantic) "ExpandMacro"
refactoring. But without `key.buffer_name`. Nested expnasions are not
supported at this point.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "swift/IDE/SyntaxModel.h"
|
||||
#include "swift/IDE/Utils.h"
|
||||
#include "swift/IDETool/IDEInspectionInstance.h"
|
||||
#include "swift/IDETool/SyntacticMacroExpansion.h"
|
||||
|
||||
#include "clang/Lex/HeaderSearch.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
@@ -303,6 +304,9 @@ SwiftLangSupport::SwiftLangSupport(SourceKit::Context &SKCtx)
|
||||
// By default, just use the in-memory cache.
|
||||
CCCache->inMemory = std::make_unique<ide::CodeCompletionCache>();
|
||||
|
||||
SyntacticMacroExpansions =
|
||||
std::make_shared<SyntacticMacroExpansion>(SwiftExecutablePath, Plugins);
|
||||
|
||||
// Provide a default file system provider.
|
||||
setFileSystemProvider("in-memory-vfs", std::make_unique<InMemoryFileSystemProvider>());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user