Skip to content

[IDE][Index] Property wrapper rename support #25758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 28, 2019

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Jun 25, 2019

This PR fixes up rename support for property wrappers. There were three main issues this addresses:

  1. Renaming an @propertyWrapper struct was failing due to rename's NameMatcher using the range of a Decl itself, not including its attributes, to decide if it contained a location that needed to be resolved.
  2. Renaming a constructor of a @propertyWrapper struct would not pick up occurrences of that constructor's argument labels used in custom attributes, e.g. renaming MyWrapper's init(initialValue:minValue:maxValue) constructor would miss the argument labels in custom attributes like @MyWrapper(initialValue: 50, minValue: 0, maxValue: 100). This is because the indexer didn't report an occurrence of the constructor call in custom attributes. Rename's NameMatcher also needed to be updated to handle resolving these newly-added occurrences, since the call expression in the AST doesn't have an explicit base (MyWrapper is not part of the call expression, but is where the index reports the call taking place).
  3. Renaming a wrapped property (e.g. foo) wasn't updating the corresponding synthesized $-prefixed backing property ($foo). The synthesized backing property declarations were implicit, so the index wasn't recording them, and even if it did, it's a different property so wouldn't be picked up automatically.

    To resolve this, the index now records an occurrence of the wrapped property within the synthesized backing property occurrences (i.e. on the foo within each $foo) so that rename on the wrapped property updates the synthesized backing property occurrences too. To support rename being invoked via an occurrence of a synthesized property, the CusorInfo request that determines which symbol is renamed for a given location now treats occurrences of synthesized properties as if they were the corresponding wrapped properties. The FindRelatedIdents request was also similarly updated so that rename-like features that are based on it (like Xcode's edit-all-in-scope) can get both the underlying and synthesized property ranges, regardless of which is was invoked on.

This PR also includes some small and/or incidental IDE issue fixes around custom attributes:

  • syntax coloring wasn't working for the custom attribute type occurrences (only semantic highlighting)
  • interleaving of availability attributes, custom attributes and built-in attributes would sometimes result in incorrect syntax highlighting.

Resolves rdar://problem/49036613
Resolves rdar://problem/50073641
Resolves rdar://problem/51695783
Resolves rdar://problem/52053678

@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes changed the title [IDE][Index] Property wrapper rename [IDE][Index] Property wrapper rename support Jun 25, 2019
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 443f13a969ba842c8ba8952b81d44c1fc0677511

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 443f13a969ba842c8ba8952b81d44c1fc0677511

@nathawes nathawes force-pushed the property-wrapper-rename branch from 443f13a to d571fca Compare June 25, 2019 21:28
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 443f13a969ba842c8ba8952b81d44c1fc0677511

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 443f13a969ba842c8ba8952b81d44c1fc0677511

@nathawes nathawes requested a review from benlangmuir June 25, 2019 23:13
@nathawes nathawes marked this pull request as ready for review June 25, 2019 23:13
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - d571fca6ad5eca38f242ee389c66faeb768aa3e9

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - d571fca6ad5eca38f242ee389c66faeb768aa3e9

Nathan Hawes added 5 commits June 26, 2019 18:37
…m attributes

This fixes custom attribute syntax highlighting on parameters and functions
(where function builders can be applied). They weren't being walked in
the function position previously and were walked out of source order in the
parameter position.

It also fixes rename of the property wrapper and function builder type
names that can appear in custom attributes, as well as rename of property
wrapper constructors, that can appear after the type names, e.g.
`@Wrapper(initialValue: 10)`. The index now also records these constructor
occurrences, along with implicit occurrences whenever a constructor is
called via default value assignment, e.g. `@Wrapper var foo = 10`, so that
finding calls/references to the constructor includes these locations.

Resolves rdar://problem/49036613
Resolves rdar://problem/50073641
…esized $-prefixed backing property

This patch achieves this by updating indexing to reporting the position of
`foo` in occurrences of `$foo` as an occurrence of the `foo` symbol, so
that renames initiated on occurrences of the `foo` symbol will also result
in occurrences of the `$foo` symbol being updated correctly. This also means
find-references on foo will show places where $foo is used.

Making rename work in the other direction (invoking rename on $foo upating foo
occurrences too) is still todo.
…er backing properties as the underlying property

This is the final piece to get rename and findRelatedIdents to include all foo
and $foo occurrences, for example, in the set of occurrences to be renamed or
shown, regardless of whether they were initiated on a foo or $foo.

Resolves rdar://problem/51695783.
…Value rather than value

Plus other small cleanups to comments and variable names.
…pers

Make sure they handle the case when a property wrapper type's constructor is
called with the first argument coming from the var initializer, and the rest
from the custom attribute's argument.
@nathawes nathawes force-pushed the property-wrapper-rename branch from 69abb28 to b1787d9 Compare June 28, 2019 01:00
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 69abb28136006197010bff4cb567d9fe989e3c08

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 69abb28136006197010bff4cb567d9fe989e3c08

@nathawes nathawes force-pushed the property-wrapper-rename branch from b1787d9 to 9b0844e Compare June 28, 2019 01:44
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - b1787d998b31f87761de8a420556af6f9928ccbe

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - b1787d998b31f87761de8a420556af6f9928ccbe

…rty wrapper changes

The backing property for 'foo' is now '_foo', and the projected value '$foo'.
This updates Indexing to report occurrences of foo within both $foo and
_foo occurrences (rather than just $foo - the old _foo).

FindRelatedIdents was similarlar updated, so it reports 'foo' ranges in both
_foo and $foo.

CursorInfo now reports the USR, documentation, and location of foo when invoked
occurrences of $foo or _foo, but now leaves the name, type, and annotated
declaration of _foo/$foo as is. Having the same USR ensures rename invoked on
any of them will still rename via foo. Reporting foo's documentation comment
instead is just to present something more useful to the user.
@nathawes nathawes force-pushed the property-wrapper-rename branch from 9b0844e to e08a6c1 Compare June 28, 2019 17:15
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9b0844e21c7375252da145636d571704f1c7fd8d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9b0844e21c7375252da145636d571704f1c7fd8d

@nathawes
Copy link
Contributor Author

@swift-ci please test OS X Platform

@nathawes nathawes requested a review from benlangmuir June 28, 2019 21:10
@nathawes nathawes merged commit a0052c9 into swiftlang:master Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants