Commit Graph

209 Commits

Author SHA1 Message Date
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Suyash Srijan
b1b60fbbda [Refactoring] Create 'AddEquatableContext' with extension only when there is an extended nominal declaration (#32435) 2020-06-17 21:33:22 +01:00
Robert Widmann
0d1f6ae8bb Print @escaping For Closures In Generated Memberwise Initializer
Augment the "generate memberwise initializer" refactoring action to
automatically print @escaping in parameter position. Closures as stored
properties always escape.

rdar://62202381
2020-06-09 17:21:28 -07:00
Nathan Hawes
78b7bce3a0 [IDE][Refactoring] Update syntactic rename to support braceless multiple trailing closures. 2020-05-06 01:56:41 -04:00
Nathan Hawes
0f8619b943 [IDE][SourceKit] Support escaped identifiers for the syntactic rename and related idents requests.
Resolves rdar://problem/46409010
Resolves rdar://problem/48256383
2020-04-30 13:08:23 -07:00
Andrew Tkachuk
d0ac023dbc Apply requested changes 2020-04-25 21:13:14 +03:00
Andrew Tkachuk
18606ad891 Fix failing tests 2020-04-20 21:15:24 +03:00
Andrew Tkachuk
fc382d2085 Merge branch 'master' into add-equatable-conformance 2020-04-17 19:14:20 +03:00
Nathan Hawes
bce68fa4e5 [IDE][Refactoring] Handle 'callAsFunction' specially in syntactic rename.
This change makes us treat it exactly as we do 'init'. We don't allow renaming the base name,
and don't fail if the basename doesn't match for calls.

Also:
  - explicit init calls/references like `MyType.init(42)` are now reported with
    'init' as a keywordBase range, rather than nothing.
  - cursor info no longer reports rename as available on init/callAsFunction
    calls without arguments, as there's nothing to rename in that case.
  - Improved detection of when a referenced function is a call (rather than
    reference) across syntactic rename, cursor-info, and indexing.

Resolves rdar://problem/60340429
2020-04-12 17:14:15 -07:00
Andrew Tkachuk
ad15f21cde [SR-7293] Refactoring action to add Equatable Conformance 2020-02-14 19:31:58 +02:00
Vlasov Anton
6013431ecd SR-5740 Refactoring action to convert if statement to switch 2020-02-08 16:23:41 +03:00
Vlasov Anton
904bd0bf63 SR-5740 Refactoring action to convert if statement to switch 2020-02-02 12:44:48 +03:00
Vlasov Anton
b52a0929c4 SR-5741 Refactoring action to convert from field initialization to computed property 2019-12-08 21:17:39 +03:00
Robert Widmann
c75af38a7a Drop ConformanceContexts out of the TypeChecker 2019-11-06 11:41:03 -08:00
Robert Widmann
546734aea8 Move and expand the memberwise initializer test 2019-08-03 22:36:15 -07:00
Nathan Hawes
306584339e Merge pull request #26016 from cltnschlosser/SR-11077-inner-rename-nested-type
[refactoring] Fix error when renaming nested type at constructor - init() has no declaration location
2019-07-11 17:49:12 -07:00
Colton Schlosser
07675a75e0 [refactoring] Fix error when renaming nested type at constructor - init() has no declaration location
Resolves SR-11077
2019-07-10 21:02:00 -04:00
Власов Антон Вячеславович
8acd794935 SR-5744 Refactoring action to convert if-let to guard-let and vice versa 2019-07-09 16:21:25 +03:00
Nathan Hawes
e08a6c1994 [IDE][Index][test] Update sourcekit/indexing support for latest property 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.
2019-06-28 10:15:00 -07:00
Nathan Hawes
c547e6885e [test] Add more index/refactoring/cursor-info tests for property wrappers
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.
2019-06-26 18:37:47 -07:00
Nathan Hawes
c7e8b3f693 [test] Update Index/refactoring property wrapper tests to use wrappedValue rather than value
Plus other small cleanups to comments and variable names.
2019-06-26 18:37:47 -07:00
Nathan Hawes
d389652998 [IDE][Index] Renaming a wrapped property should also rename the synthesized $-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.
2019-06-26 18:37:47 -07:00
Nathan Hawes
a565430239 [IDE][Index] Fix syntax coloring, index, and rename support for custom 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
2019-06-26 18:37:47 -07:00
Parker Schuh
d0779bd771 Convert ArrayExpr to not use callWitness() or generate a SemanticExpr. 2019-03-27 23:21:08 -04:00
Nathan Hawes
9291201e32 [sourcekitd][Refactoring] Fix renaming of var decls in fallthrough case statements
We weren't renaming all occurrences of 'x' in the cases like the below:

  case .first(let x), .second(let x):
    print("foo \(x)")
    fallthrough
  case .third(let x):
    print("bar \(x)")

We would previously only rename occurrences within the case statement the query
was made in (ignoring fallthroughs) and for cases with multiple patterns (as in
the first case above) we would only rename the occurrence in the first pattern.
2019-03-20 14:38:08 -07:00
Parker Schuh
b12fcb50db IntegerLiteralExpr now is lowered directly into SIL.
For context, String, Nil, and Bool already behave this way.

Note: Before it used to construct (call, ... (integer_literal)), and the
call would be made explicit / implicit based on if you did eg: Int(3) or
just 3. This however did not translate to the new world so this PR adds
a IsExplicitConversion bit to NumberLiteralExpr. Some side results of
all this are that some warnings changed a little and some instructions are
emitted in a different order.
2019-02-14 11:54:16 -08:00
Nathan Hawes
43c2f27783 [Refactoring][Migrator] Fix rename of callsites with a trailing closure argument
A label range of 0 length was being reported as the label of trailing closure
arguments, just before the opening '{'.

For the rename refactoring, this meant that if the corresponding parameter had
an external label (e.g. 'a') the occurrence would be treated as not matching the
expected symbol name, and so not be updated at all.

For the migrator, when renaming a function with an unlabelled closure for its
last parameter to have a label, it would incorrectly insert the new label in
front of the opening '{' on all of that function's callsites with trailing
closures.

Resolves rdar://problem/42162571
2018-12-19 16:24:14 -08:00
gregomni
ff04fbdae8 Fix name lookup and parser so that where clauses decl refs in case statements correctly bind to the current pattern instead of always to the first pattern. Thus the hacky var decl juggling in where clauses in SILGen can be deleted. 2018-08-28 19:18:56 -07:00
Xi Ge
bff3f8adcc Merge pull request #16983 from mohitathwani/SR-7292
[WIP] Generating member wise initializer with local refactoring
2018-07-26 13:05:08 -07:00
Mohit Athwani
ce1122921a SR-7292 - Refactoring tool for generating member wise init 2018-07-26 11:31:30 -07:00
Rintaro Ishizaki
711cef6869 [Refactoring] Fix crasher in switch with non-nominal subject type
rdar://problem/42098130
2018-07-24 18:07:07 +09:00
Rintaro Ishizaki
1ca88478a8 [Refactoring] Handle TupleShuffleExpr in "convert to trailing closure"
Fixes crash in "Convert To Trailing Closure" action if call has
defaulted parameters. Handle `TupleShuffleExpr` properly.

rdar://problem/41093898
2018-06-18 16:18:58 +09:00
Rintaro Ishizaki
db3020f031 [Refactoring] Disallow several kinds of decl to move to extension
* AccessorDecl and EnumElementDecl aren't independent decls
* DestructorDecl and EnumCaseDecl can't be put in extension
2018-05-25 19:04:01 +09:00
Rintaro Ishizaki
025f4dde55 Merge pull request #16789 from rintaro/refactoring-nested-if
[Refactoring] Re-implement "collapse nested if" action
2018-05-24 07:56:02 +09:00
Rintaro Ishizaki
70ff0c013b [Refactoring] Disallow extracting partial statement
`BraceStmt`, `CatchStmt` and `CaseStmt` cannot be independent
statement, thus unextractable.

rdar://problem/38390401
2018-05-23 18:03:27 +09:00
Rintaro Ishizaki
639fb85c5f [Refactoring] Rename CollapseNestedIfExpr to CollapseNestedIfStmt
'if' is not expression, but statement.
2018-05-23 17:13:35 +09:00
Rintaro Ishizaki
f1c8230b2a [Refactoring] Re-implement "collapse nested if" action
Narrowed `isApplicable()` condition to ensure that we don't emit this
action when it's not safe to apply this action.

Fixes rdar://problem/39516354
2018-05-23 17:13:35 +09:00
Rintaro Ishizaki
a6f7a8ea35 [Parser] Set local discriminator to ParamDecls
We have to discriminate between params and local variables.
2018-05-11 15:37:40 +09:00
Rintaro Ishizaki
dc76149150 [IDE] Use getStartLoc() for matching pattern ranges
For Example `getLoc()` for `foo as Ty`(`IsPattern`) is at 'as'. We
should try to resolve this at position of 'foo'.
2018-05-11 15:34:42 +09:00
Rintaro Ishizaki
df10afd1a2 [Parse] Discriminate local variables
Set local discriminator for all local `VarDecl`s. Otherwise, they cannot
be discriminated with USRs. This change is needed for rename refactoring which
uses USR for discrimiating variable names.

https://bugs.swift.org/browse/SR-7205,
rdar://problem/34701880
2018-05-11 15:34:42 +09:00
Rintaro Ishizaki
b984789ee5 [AST] Initialize Target of break/continue with nullptr
Otherwise, it's never initialized. This doesn't affect normal compilation
because it doensn't reach only-user SILGen due to typecheck error. However,
IDE refactoring uses this regardless of the error.

rdar://problem/33972653
2018-04-20 15:25:09 +09:00
Huon Wilson
75313cfed5 [IDE] make replace.bodies.with.fatalError an internal refactoring.
This shouldn't be exposed to general users.
2018-04-17 09:05:26 +10:00
Huon Wilson
fac1a529fe [IDE] Tweak replace.bodies.with.fatalError.
The menu item should be capitalised, and it's nicer if the fatalError is on its
own line in the new function body.
2018-04-16 12:58:55 +10:00
Huon Wilson
8056102ee5 [IDE] Refactoring to change function bodies to "fatalError()".
This is immensely useful when working on generic code, where the signatures
of (many) functions are all that is required, and removing the bodies makes
things compile faster, allows tools like creduce to work better and results in
less noise in a debugger.

Unfortunately the design of refactoring means this currently only works on a
single top-level decl, or multiple decls inside a type.
2018-04-13 15:56:56 +10:00
Rintaro Ishizaki
53be298f1f [IDE] Don't emit “Convert to Trailing Closure” for trailing closure (#15824)
rdar://problem/39253640
2018-04-09 15:30:52 +09:00
Saleem Abdulrasool
b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00
Xi Ge
2f47af6c7c refactoring: don't assume every pattern binding has an initializer. rdar://38062772 2018-03-05 16:14:09 -08:00
Xi Ge
cf36346021 refactoring: when RangeInfo is of kind PartOfExpression, we should use the dedicated field to get the parent expression. rdar://36755861 (#14088) 2018-01-23 12:53:50 -08:00
Roman Roibu
b2d122c4a7 [IDE] Refactoring: Expand a ternary operator into an if statement and vice-versa (#12554) 2017-12-21 12:40:30 -08:00
Nathan Hawes
340d9089a0 [Refactoring] Local rename in lazy block failing
Some of the implicit decls generated for lazy vars have invalid source ranges.
For now, just always walk into implicit decls when looking for name locations.

Resolves rdar://problem/35255644.
2017-12-14 10:52:13 -08:00