Commit Graph

22 Commits

Author SHA1 Message Date
Ben Barham
edb980eb55 Merge pull request #64095 from bnbarham/do-not-change-refactoring
[Macros] Do not edit macro buffer or position when refactoring
2023-03-06 08:43:30 -08:00
Doug Gregor
1ba67b9cac Update test cases for generic macros 2023-03-05 23:12:24 -08:00
Ben Barham
80d27128d8 [Macros] Do not edit macro buffer or position when refactoring
Rather than editing the macro buffer in refactoring, add appropriate
padding and braces when creating the macro.

Don't edit the insertion location - we should update this in a later PR
as well.
2023-03-03 19:48:06 -08:00
Ben Barham
f3a6ce144c Merge pull request #63906 from bnbarham/add-nested-expansion
[Refactor] Allow expanding nested macros
2023-03-02 20:43:35 -08:00
Doug Gregor
f88d2c638f Clean up feature flags for macros.
Enable expression macros by default, and add separate feature flags for
attached and freestanding macros.
2023-03-02 14:34:59 -08:00
Ben Barham
bb7760b9e0 [Refactor] Allow expanding nested macros
This adds a new `primary_file` key, which defaults to `sourcefile`. For
nested expansions, `primary_file` should be set to the containing file
and `sourcefile` to the name of the macro expansion buffer.
2023-03-02 14:04:46 -08:00
Doug Gregor
eb06129463 [SourceKit] Add macro expansion support for conformance macros 2023-03-01 22:07:25 -08:00
Ben Barham
f7aaf02065 [SourceKit] Add an optional path and name to refactoring edits
Add two new fields to refactoring edits:
  - A file path if the edit corresponds to a buffer other than the
    original file
  - A buffer name when the edit is actually source of generated buffer

Macro expansions allow the former as a macro could expand to member
attributes, which may eg. add accessors to each member. The attribute
itself is inside the expansion, but the edit is to the member in the
original source.

The latter will later allow clients to send requests with these names to
allow semantic functionality inside synthesized buffers.
2023-02-22 16:24:02 -08:00
Ben Barham
b2849551cc Merge pull request #63739 from bnbarham/add-sg-macros
[SymbolGraph] Generate symbol graphs for macro declarations
2023-02-17 10:23:22 -08:00
Ben Barham
0c3f538822 [AST] Allow ignoring macro expansions
Various requests expect to be walking over the current source file.
While we could add checks to all these to skip decls outside of the
current buffer, it's a little nicer to handle this during the walk
instead.

Allow ignoring nodes that are from macro expansions and add that flag to
the various walks that expect it.

Also add a new `getOriginalAttrs` that filters out attributes in
generated source.
2023-02-16 18:04:56 -08:00
Ben Barham
72fb01c0e1 [SymbolGraph] Generate symbol graphs for macro declarations 2023-02-16 17:59:29 -08:00
Holly Borla
f4b2b60446 [Macros] Enable global peer macros.
Global peer macro expansions are not injected into the AST. Instead, they
are visited as "auxiliary declarations" when needed, such as in the decl
checker and during SILGen. This is the same mechanism used for local property
wrappers and local lazy variables.
2023-02-14 16:24:25 -08:00
Doug Gregor
3b42b96db7 [Macros] Adjust whitespace for macro expansions that get returned 2023-02-13 16:08:28 -08:00
Doug Gregor
b882e0cb1e Add SourceKit support for expanding peer macros 2023-02-11 12:17:39 -08:00
Doug Gregor
a75b64e034 Add refactoring support for accessor macros 2023-02-11 11:23:28 -08:00
Doug Gregor
96380624db [SourceKit] Implement macro expansion for (some) attached macros.
Extend the macro-expansion refactoring to work with member and
member-attribute attached macros. These expansions can return several
different changes, e.g., adding new members, sprinkling member
attributes around, and so on.
2023-02-11 11:23:28 -08:00
Alex Hoppen
75771c1579 Merge pull request #63387 from ahoppen/ahoppen/macros-swift-5
[Macros] Compile Macros tests with swift-version 5 instead of swift-version 4
2023-02-07 09:16:44 +01:00
Richard Wei
01e4c8df26 [Macros] Use name lookup for lazy declaration macro expansion (#63411)
- Use the name lookup table instead of adding members from a macro expansion to the parent decl context.
- Require declaration macros to specify introduced names and used the declared names to guide macro expansions lazily.
2023-02-07 11:24:42 +08:00
Alex Hoppen
ba5a727983 [Macros] Compile Macros tests with swift-version 5 instead of swift-version 4 2023-02-04 11:10:08 +01:00
Doug Gregor
f78f5729c3 Start requiring expression macros to be marked with @expression 2022-12-22 09:18:05 -08:00
Alastair Houghton
da51c04116 Two of the macros tests are failing to import SwiftDiagnostics.
Disabling these for now, pending a fix.
2022-12-22 09:45:59 +00:00
Rintaro Ishizaki
9f137074af [SourceKit/Refactoring] Macro expansion
Add refactoring "Expand Macro" that expands macro expressions.

rdar://102739026
2022-12-06 16:20:07 -08:00