[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

@@ -209,6 +209,9 @@ UID_KEYS = [
KEY('IsSynthesized', 'key.is_synthesized'),
KEY('BufferName', 'key.buffer_name'),
KEY('BarriersEnabled', 'key.barriers_enabled'),
KEY('Expansions', 'key.expansions'),
KEY('MacroRoles', 'key.macro_roles'),
KEY('ExpandedMacroReplacements', 'key.expanded_macro_replacements'),
]
@@ -274,6 +277,8 @@ UID_REQUESTS = [
REQUEST('Compile', 'source.request.compile'),
REQUEST('CompileClose', 'source.request.compile.close'),
REQUEST('EnableRequestBarriers', 'source.request.enable_request_barriers'),
REQUEST('SyntacticMacroExpansion',
'source.request.syntactic_macro_expansion'),
]
@@ -491,4 +496,12 @@ UID_KINDS = [
KIND('StatInstructionCount', 'source.statistic.instruction-count'),
KIND('Swift', 'source.lang.swift'),
KIND('ObjC', 'source.lang.objc'),
KIND('MacroRoleExpression', 'source.lang.swift.macro_role.expression'),
KIND('MacroRoleDeclaration', 'source.lang.swift.macro_role.declaration'),
KIND('MacroRoleCodeItem', 'source.lang.swift.macro_role.codeitem'),
KIND('MacroRoleAccessor', 'source.lang.swift.macro_role.accessor'),
KIND('MacroRoleMemberAttribute', 'source.lang.swift.macro_role.member_attribute'),
KIND('MacroRoleMember', 'source.lang.swift.macro_role.member'),
KIND('MacroRolePeer', 'source.lang.swift.macro_role.peer'),
KIND('MacroRoleConformance', 'source.lang.swift.macro_role.conformance'),
]