[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

@@ -55,6 +55,7 @@ namespace ide {
class IDEInspectionInstance;
class OnDiskCodeCompletionCache;
class SourceEditConsumer;
class SyntacticMacroExpansion;
enum class CodeCompletionDeclKind : uint8_t;
enum class SyntaxNodeKind : uint8_t;
enum class SyntaxStructureKind : uint8_t;
@@ -366,6 +367,7 @@ class SwiftLangSupport : public LangSupport {
llvm::StringMap<std::unique_ptr<FileSystemProvider>> FileSystemProviders;
std::shared_ptr<swift::ide::IDEInspectionInstance> IDEInspectionInst;
std::shared_ptr<compile::SessionManager> CompileManager;
std::shared_ptr<swift::ide::SyntacticMacroExpansion> SyntacticMacroExpansions;
public:
explicit SwiftLangSupport(SourceKit::Context &SKCtx);
@@ -756,6 +758,11 @@ public:
ConformingMethodListConsumer &Consumer,
Optional<VFSOptions> vfsOptions) override;
void expandMacroSyntactically(llvm::MemoryBuffer *inputBuf,
ArrayRef<const char *> args,
ArrayRef<MacroExpansionInfo> expansions,
CategorizedEditsReceiver receiver) override;
void
performCompile(StringRef Name, ArrayRef<const char *> Args,
Optional<VFSOptions> vfsOptions,