Commit Graph

16 Commits

Author SHA1 Message Date
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
3c67b06780 Merge pull request #62574 from ahoppen/ahoppen/reuse-ast-context
[SourceKit] Make sure we reuse ASTContext in function bodies for solver-based cursor info
2023-02-06 14:42:31 +01:00
Alex Hoppen
a5f85ee10c [SourceKit] Make sure we reuse ASTContext in function bodies for solver-based cursor info
The main problem that prevented us from reusing the ASTContext was that we weren’t remapping the `LocToResolve` in the temporary buffer that only contains the re-parsed function back to the original buffer. Thus `NodeFinder` couldn’t find the node that we want to get cursor info for.

Getting AST reuse to work for top-level items is harder because it currently heavily relies on the `HasCodeCompletion` state being set on the parser result. I’ll try that in a follow-up PR.

rdar://103251263
2023-02-02 22:03:25 +01:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Ben Barham
4f70a7676b Merge pull request #63167 from bnbarham/fix-shadowed-rename
[Index] Handle shorthand if let/closure captures in local rename
2023-01-25 09:11:55 -08:00
Erik Eckstein
7d8bf37e5e change to the new llvm::Optional APIs
This is a follow-up of https://github.com/apple/swift/pull/62217
2023-01-25 09:18:36 +01:00
Ben Barham
4cc7167b60 [Index] Handle shorthand if let/closure captures in local rename
Update rename to pull the outermost-declaration so that references are correctly found.

Rather than keeping suppressed locations in the current parent, keep
them for the whole index. Local rename starts the lookup from the
innermost context it can, which could be a closure. In that case there
is no parent decl on the stack and thus no where to store the locations
to suppress. We could have a specific store for this case, but there
shouldn't be that many of these and they're relatively cheap to store
anyway.

Resolves rdar://104568539.
2023-01-24 11:10:38 -08:00
Valeriy Van
c48a638982 Fix assert 2022-12-18 00:28:28 +02:00
Rintaro Ishizaki
25c4c993f3 [Refactoring] Fix stack-use-after-scope in ContextFinder
Storing `llvm::function_ref` as a member field is not safe. Just use
std::function instead.

rdar://103369305
2022-12-15 10:55:47 -08: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
Alex Hoppen
652686034c [IDE] Split ResolvedCursorInfo into subclasses
This way, each kind of `ResolvedCursorInfo` can define its own set of properties and it’s obvious which properties are used for which kind. Also switch to getters and setters because that makes it easier to search for usages of properties by looking at the call hierarchy of the getter / setter.
2022-12-01 12:11:39 +01:00
Doug Gregor
3a172fb892 [Macros] Miscellaneous build fixes for macros. 2022-11-13 17:09:12 -08:00
Rintaro Ishizaki
45828af5ed [Refactoring] Separate refactoring files to its own library
IDE/Refactoring had dependencies to libswiftIndex, but libswiftIndex
also depends on libswiftIDE (SourceEntityWalker, etc.)

To break libswiftIndex <-> libswiftIDE dependency cycle, move
"refactoring" related files to a new library 'libswiftRefactoring'

rdar://101692282
2022-11-02 12:39:26 -07:00