[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:
Rintaro Ishizaki
2023-05-24 14:29:05 -07:00
parent 65e37f7c3a
commit c3d1304345
22 changed files with 1287 additions and 111 deletions

View File

@@ -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>());
}