Commit Graph

208 Commits

Author SHA1 Message Date
Alex Hoppen
155773c38e Fix renaming enum case parameters with unnamed associated arguments
We treated enum case parameters the same way as function parameters and weren’t considering that they can be unlabeled. That caused us to insert eg. `_ ` in front of the case’s type, producing `case myCase(_ String)`, which is invalid. When we are inside an enum case parameter and the parameter label is empty, treat it the same as a function call, which will leave the label untouched if it isn’t modified and insert a label including a colon if a new label is introduced.

https://github.com/apple/sourcekit-lsp/issues/1228
2024-06-11 19:18:59 -07:00
Rintaro Ishizaki
7177055bdc [Refactoring] Skip failed witness decls in "add codable implementation"
When there are problems in the properties in the target type, witness
methods may not be synthesized. Don't try to add such methods.

https://github.com/apple/swift/issues/72387
2024-03-18 23:49:24 +09:00
Rintaro Ishizaki
39606e6269 [refactoring] Rework "add codable implementation" refactoring
* Support extensions including conditional conformance
* Correct access modifiers
* More correct lookup for the synthesized declarations
* Avoid printing decls in nested types (rdar://98025945)
2024-03-13 13:34:32 +09:00
Alex Hoppen
63aeedecbd [SourceKit] Only report textual results inside comments and strings from syntactic rename ranges 2024-02-29 15:37:29 -08:00
Daniel Rodríguez Troitiño
e60785e1ef [test] Mark some tests as requiring Swift Syntax (#70493)
Some of the tests now depend on features provided by Swift Syntax, and
will fail to pass if building without Swift Syntax support.

This commits marks all the tests I know fail to pass when Swift Syntax
is disabled.

- #70281 modified `ASTGen/verify-parse.swift`
- #70287 created `refactoring/SyntacticRename/operator.swift` and `SourceKit/RelatedIdents/operator.swift`
- #70389 modified `SourceKit/Refactoring/basic.swift` and indirectly
  modified all `refactoring/ExtractFunction/*` tests.
2023-12-15 13:33:14 -08:00
Alex Hoppen
6db68cb1e8 [SourceKit] Adjust test case since we now consider argument labels in comments
Companion of https://github.com/apple/swift-syntax/pull/2401
2023-12-12 09:36:28 -08:00
Alex Hoppen
516836cb98 [SourceKit] Don't handle labels when renaming operators
This allows us to at least rename the base of operators. The labels don’t matter too much since they only occur on the function definition.
2023-12-07 13:12:12 -08:00
Alex Hoppen
5cae50a1a6 [SourceKit] Refactor addSyntacticRenameRanges
Refactor `addSyntacticRenameRanges`, adding comments to make it easier to follow and remove its dependency on the `IsFunctionLike` parameter in `RenameLoc`.
2023-12-06 14:31:47 -08:00
Alex Hoppen
a710111001 [SourceKit] Support building sourcekitd without building swift-syntax
This allows building sourcekitd and swift-refactor with `SWIFT_BUILD_SWIFT_SYNTAX=NO`. In these builds, the `relatedidents` and `find-syntactic-rename-ranges` requests will always return an error.
2023-12-04 19:14:01 -08:00
Alex Hoppen
8fd025625b [SourceKit] Use NameMatcher that is rewritten in Swift for syntactic rename 2023-11-17 09:30:04 -08:00
Alex Hoppen
4103ad8cea [SourceKit] Change tests to use find-rename-ranges instead of syntactic-rename
I will remove the `syntactic-rename` refactoring action in a follow-up commit. Clients should always ask for rename ranges and perform the rename by themselves instead of asking for a renamed file.
2023-11-15 11:20:27 -08:00
Alex Hoppen
5ed83ff616 [SourceKit] Update tests to use find-local-rename-ranges instead of invoking the local rename refactoring action
The local rename refactoring action will be removed in a follow-up commit.
2023-11-15 11:20:26 -08:00
Michael Spencer
b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
Allan Shortlidge
8079d9cf45 AST: Fix whitespace for switch statements under -print-ast.
No test changes because the tests for `-print-ast` don't match whitespace.
2023-07-31 21:27:46 -07:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Alex Hoppen
8abe38f9e2 [Rename] Also syntactically rename a macro’s definition
Previously we were skipping the macro’s definition (i.e. the part after `=` in a macro declaration if it wasn’t type checked. Since syntactic rename doesn’t type-check anything, it was thus skippin the macro definition. Add a flag to `ASTWalker` that allows `NameMatcher` to opt-out of this behavior.
2023-04-24 13:33:57 -07:00
Ben Barham
d2de8ed83c [SourceKit] Merge local refactoring implementations
Retrieving local rename ranges and the local rename refactoring both had
almost identical methods, except for the addition of retrieving the
outermost shadowed decl that was added a couple months back. Merge them.

Resolves rdar://106529370.
2023-03-13 15:36:47 -07: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
Anthony Latsis
fa3a95e7b8 Gardening: Migrate test suite to GH issues: refactoring 2022-09-02 01:44:24 +03:00
Alex Hoppen
ff129c3677 [test] Prepend 'python' to 'refactor-check-compiles.py' call
This fixes a test execution failure on Windows where the `refactor-check-compiles.py` is not an executable.
2022-06-22 09:27:34 +02:00
Alex Hoppen
db26e7fc28 [refactoring] Run refactoring tests on Linux
Refactoring tests have been disabled on Linux but I can’t find a reason why that should be the case. Enable them on all platforms.

rdar://92982631
2022-06-21 10:58:06 +02:00
Alex Hoppen
ca4abab9a9 Merge pull request #58746 from ahoppen/pr/enum-assoc-value-is-call
[Index] Consider construction of enums with associated values as a function call
2022-05-13 16:39:07 +02:00
Alex Hoppen
74cd03b098 [Index] Consider construction of enums with associated values as a function call
For enum cases with associated values, their construction is modelled by a function. E.g. if you have
```swift
enum Foo {
  case first(associated: Int)
}
```

then `Foo.first` is a function of type `(Int) -> Foo`. But if you write `Foo.first(associated: 2)` in source code, we consider this construct as a referenced, not a call. This causes us to miss renaming of associated value labels during local refactoring.

rdar://84061868
2022-05-09 22:22:31 +02:00
Alex Hoppen
379ad6cbde Merge pull request #58718 from ahoppen/pr/generate-memberwise-property-wrapper
[Refactoring] Several improvements to memberwise initializer generation
2022-05-09 17:05:36 +02:00
Alex Hoppen
d2f7d518ed [Refactoring] Always walk parent decl context of value decl for local rename
Previously, we only walked the parent scope of the decl context that declared the value to rename if it was a TopLevelCodeDecl. But also functions can have locally declared types that can be used in sibling scopes. Thus, we always need to walk the parent DeclContext of the one declaring the value we are renaming.

rdar://89836229
2022-05-09 17:04:36 +02:00
Alex Hoppen
4f970b4eed [Refactoring] Add memberwise initializer generation test cases for properties with getter and setter 2022-05-06 21:31:09 +02:00
Alex Hoppen
3b5dfbe638 [Refactoring] Maintain backticks from type members when generating memberwise initializer
Previously, we were dropping backticks, which might lead to invalid code if the type member was a keyword.

rdar://81888671
2022-05-06 20:57:12 +02:00
Alex Hoppen
8862e0153b [Refactoring] If type has no memberwise initializable members, generate an empty initializer instead of failing 2022-05-06 20:03:49 +02:00
Alex Hoppen
acf80829f0 [Refactoring] Add members with property wrappers to generated memberwise init
Generating a memberwise init would skip over properties with property wrappers. Switch the implementation of memberwise init generation closer to the one that generates the implicit memberwise init by also using `getMembers()` instead of `getStoredProperties()`.

rdar://89057767
2022-05-06 19:55:55 +02:00
Alex Hoppen
c9eb2d508e Merge pull request #58613 from ahoppen/pr/refactor-misses-prefix-operator
[Refactoring] Fix an issue where refactoring misses to refactor references after prefix operators
2022-05-05 14:31:46 +02:00
Alex Hoppen
6d2582f5b8 [Refactoring] Fix an issue where refactoring misses to refactor references after prefix operators
The removed `else if` branch caused the argument to the `-` operator to be be reported as `Mismatch`. I couldn’t figure out what that branch was for, so I removed it.

rdar://91588948
2022-05-04 09:04:30 +02:00
Alex Hoppen
e835c4a031 [Refactoring] Fix a crash that occurred when converting if/else of enum with raw value to switch statement
If the enum has a raw value, `E` passed in to `BinaryExpr` is a `DeclRefExpr`, not a `DotSyntaxCallExpr`, so we crashed on `dyn_cast<DotSyntaxCallExpr>(E->getFn())->getFn()`.

Only look through `DotSyntaxCallExpr` if `E` is indeed a `DotSyntaxCallExpr`. While at it, fix a few other potential sources of nullptr crashes.

rdar://84707973
2022-05-02 15:52:24 +02:00
Josh Soref
6fd6b13c56 spelling: unwrapped
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
925a7b973c spelling: transform
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
c816df5fa8 spelling: separate
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
bb8674df51 spelling: optional
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
353e4f09ed spelling: multi
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
f7236bc2e9 spelling: handler
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
edf494fa1f spelling: extract
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
5bbb9489a5 spelling: capture
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Rintaro Ishizaki
1cfffb8094 [CodeSynthesis] Improve synthesized Decodable.init(from:) for enums
Since this implementation is exposed to users, we want to make it nice.

* Don't use 'unsafelyUnwrapped' which is usually not recommended to use
* Don't access 'container.allKeys' multiple times as it's a computed
  property

rdar://89150202
2022-03-08 15:56:22 -08:00
Anthony Latsis
6e8dcbe745 ConformanceChecker: Resolve value witnesses unless they depend on invalid type witnesses 2022-02-26 01:06:53 +03:00
Louis D'hauwe
5d36507a2f [Refactoring] Add Codable refactoring action
Inserts the synthesized implementation.
As part of this, fix some ASTPrinter bugs.

rdar://87904700
2022-02-02 14:14:23 -08:00
Hamish Knight
97a1653863 Merge pull request #39159 from hamishknight/conditions-apply
[Async Refactoring] Drop bool flag parameter binding
2021-09-07 13:35:22 +01:00
Hamish Knight
72070b7d41 [Async Refactoring] Bind known bool param in fallback
Generalize the logic to handle different BlockKinds,
and add binding logic that lets us assign `true` or
`false` to the given bool success param in the
fallback case.
2021-09-06 21:25:09 +01:00
Hamish Knight
00977afc7b [Async Refactoring] Placeholder dropped params in fallback case
Make sure to convert any references to parameters
that get dropped in the fallback case to
placeholders.
2021-09-06 21:25:09 +01:00
Hamish Knight
1e34f31545 [Async Refactoring] Drop bool flag parameter binding
If we have a known bool flag parameter, drop it
from the success parameters being bound in a
refactored await call, as the async variant drops
it.

rdar://81896460
2021-09-06 21:25:08 +01:00
Hamish Knight
9b493970aa [Aync Refactoring] Better handle comment trailing whitespace
Use `getCommentRange` to trim off the comment's
trailing whitespace, avoiding outputting
extraneous empty lines.

rdar://82072147
2021-09-06 17:51:39 +01:00
Michael Gottesman
e2c1db5b64 [test] Change swift-refactor tooling to specify a resource-dir. 2021-09-02 14:08:24 -07:00
Ben Barham
9b8d9e22ef Merge pull request #38981 from apple/skip-underscore
[Refactoring] Do not try to unique '_'
2021-08-24 11:33:15 +10:00