Skip to content

[5.1][IDE][Index] Property wrapper rename support #25871

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

Conversation

nathawes
Copy link
Contributor

Cherry-pick of #25758 for swift-5.1-branch

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

Nathan Hawes added 6 commits June 28, 2019 14:57
…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.
…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
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes merged commit 9c07772 into swiftlang:swift-5.1-branch Jun 29, 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.

1 participant