Commit Graph

3981 Commits

Author SHA1 Message Date
Rintaro Ishizaki
6ac87ba4f1 Merge pull request #58809 from rintaro/ide-completion-rdar91892610
[CodeCompletion] Don't print '_' external parameter name in filterName
2022-05-11 11:05:41 -07:00
Alex Hoppen
2b364930fc [CursorInfo] Report values shadowed using shorthand syntax as secondary results
When a variable is re-declared using shorthand syntax (`[foo]` closure capture or `if let foo {`), the user doesn’t perceive this as a new variable declaration. Thus, we should return the original declaration as a secondary result.

rdar://91311033
rdar://75455650
2022-05-11 08:05:26 +02:00
Rintaro Ishizaki
9e493e3490 [CodeCompletion] Don't print '_' external parameter name in filterName
in override completions. '_' as a filterName is not something clients
expect. This align with function call completions.

But, unlike call-site completions, we do need '_' in the source text. So
instead of mark the chunk "annotation", make an exception in
'printCodeCompletionResultFilterName()'.

rdar://91892610
2022-05-10 16:53:06 -07:00
Rintaro Ishizaki
1e018989c8 [CodeCompletion] Suggest 'in' after expression in closure
func test(value: [Int]) {
    value.map { value <HERE> }
  }

In this case 'value' in the closure is ambiguous between an expression
referring the outer function parameter, or a parameter declaration in
the closure. Previously, code completion only considered the former and
suggest the members of '[Int]', but not 'in' keyword. As a result, when
the user actually want to type 'in' here, they needed to hit 'esc' to
cancel the code completion.

In this change, suggest 'in' keyword even without a newline, as long as
the current decl context is a closure and it doesn't have 'in' in it.

Also previously 'in' was suggested even outside the closure and even it
already had the explict 'in'. This PR limit suggesting 'in' inside
closures without explicit 'in'.

rdar://80489548
2022-05-10 11:49:12 -07:00
Alex Hoppen
00423540f7 Merge pull request #58690 from ahoppen/pr/attribute-type-relation
[CodeCompletion] Mark types that can’t be used as attributes as having an invalid type relation when used after '@'
2022-05-09 22:00:52 +02:00
Rintaro Ishizaki
6a08f1498a Merge pull request #58698 from rintaro/ide-completion-rdar92511769
[CodeCompletion] Suggest 'actor' decl introducer keyword
2022-05-09 10:19:26 -07: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
11266ebb25 [CodeCompletion] Look through @dynamicMemberLookup key path functions
This enables us to provide proper code completion for the function that is being referenced by the dynamic key path.

rdar://79092371
2022-05-08 12:58:24 +02:00
Alex Hoppen
9dbd5829de [CodeCompletion] Support type checking attributes even if they are not part of the AST
The code completion might occur inside an attriubte that isn’t part of the AST because it’s missing a `VarDecl` that it could be attached to. In these cases, record the `CustomAttr` and type check it standalone, pretending it was part of a `DeclContext`.

This also fixes a few issues where code completion previously wouldn’t find the attribute constructor call and thus wasn’t providing code completion inside the property wrapper.

rdar://92842803
2022-05-07 08:58:52 +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
df605d479d [CodeCompletion] Mark types that can’t be used as attributes as having an invalid type relation when used after '@'
When completing after `@`, record what kind of attributes are applicable here (property wrapper, result builder, global actor), mark types that are marked as property wrapper etc. as having a 'Convertible' type relation and mark all other types as having an invalid type relation.

rdar://78239501
2022-05-06 20:09: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
Rintaro Ishizaki
2805864bb5 [CodeCompletion] Suggest 'actor' decl introducer keyword
Previously 'actor' keyword was suggested as (deprecated) 'actor' decl
modifier, and it was gated by '-enable-experimental-concurrency'
compiler argument.
Add 'actor' as a type decl introducer. This causes duplicated 'actor' in
code completion if '-enable-experimental-concurrency', but that option
is basically useless at this point, so I assume not many people is using
it. Also 'actor' as a modifier will be removed soon.

[#58520] rdar://92511769
2022-05-05 14:37:44 -07: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
eb8df860e8 Merge pull request #58522 from ahoppen/pr/no-circular-supertypes
[CodeCompletion] Avoid creating circles in the USRBasedType supertype hierarchy
2022-05-03 09:43:08 +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
Alex Hoppen
b4fca1a40e [CodeCompletion] Avoid creating circles in the USRBasedType supertype hierarchy
You would think that superclass + conformances form a DAG. You are wrong!
We can achieve a circular supertype hierarcy with

```swift
protocol Proto : Class {}
class Class : Proto {}
```

USRBasedType is not set up for this. Serialization of code completion results from global modules can't handle cycles in the supertype hierarchy
because it writes the DAG leaf to root(s) and needs to know the type offsets. To get consistent results independent of where we start
constructing USRBasedTypes, ignore superclasses of protocols. If we kept track of already visited types, we would get different results depending on
whether we start constructing the USRBasedType hierarchy from Proto or Class.
Ignoring superclasses of protocols is safe to do because USRBasedType is an under-approximation anyway.

rdar://91765262
2022-04-29 12:53:17 +02:00
Egor Zhdan
d0f81417d5 [IDE] NFC: remove unnecessary const_cast 2022-04-22 23:36:22 +01:00
Ben Barham
f66d9bdf9b Merge pull request #42529 from ahoppen/pr/no-duplicate-results-from-other-modules
[CodeCompletion] Only include results from other modules once
2022-04-21 11:20:09 -07:00
Alex Hoppen
310ec6eb8d [CodeCompletion] Only include results from other modules once
In case of ambigous expression/global completions, we call `getValueCompletionsInDeclContext` multiple times for the amigous solutions to the constraint system. This can cause modules to be included multiple times in `RequestedCachedResults` and thus global results from these modules are reported multiple times. Make `RequestedCachedResults` a set so we don’t get duplicate results.

rdar://92048610
2022-04-21 10:48:40 +02:00
Doug Gregor
4116d7a3d7 Rename the -strict-concurrency= options to be more descriptive.
The three options are now:

* `explicit`: Enforce Sendable constraints where it has been explicitly adopted and perform actor-isolation checking wherever code has adopted concurrency. (This is the default)
* `targeted`: Enforce Sendable constraints and perform actor-isolation checking wherever code has adopted concurrency, including code that has explicitly adopted Sendable.
* `complete`: Enforce Sendable constraints and actor-isolation checking throughout the entire module.
2022-04-20 18:17:33 -07:00
Josh Soref
38c0de0598 Spelling frontend (#42465)
* spelling: calculated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: compilations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: containing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependency

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnose

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicitly

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: feature

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: fulfill

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: fulfillment

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: invoke

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: module

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonexistent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: omitted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: optimization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: performing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: primaries

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: sacrifices

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: scanned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: substitution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: successful

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: typecheck

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unobtrusive

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: utilities

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-20 15:18:37 -07:00
Doug Gregor
12a11e5416 Merge pull request #42445 from DougGregor/strict-concurrency-flag 2022-04-19 08:07:30 -07:00
Doug Gregor
d20064443f Use the strict concurrency level to make decisions.
`isConcurrencyChecked()` was being used as a proxy for
`-warn-concurrency` that didn't account for Swift 6. Replace
checks against it within the current module with checks against the
strict concurrency level, which subsumes the Swift 6 check and can
account for the difference between "limited" and "on".

`isConcurrencyChecked()` is used now used exclusively to mean "treat a
missing Sendable conformance as an explicitly-non-Sendable type".
2022-04-18 23:52:07 -07:00
Ben Barham
6aca5e5bca Merge pull request #42406 from bnbarham/skip-internal-types
[IDE] Skip walking serialized internal top level decls in SemaAnnotator
2022-04-18 11:22:25 -07:00
Ben Barham
fec7a0b79b [IDE] Skip walking serialized internal top level decls in SemaAnnotator
`SemaAnnotator` always attempts to retrieve the location of the decl. This
requires generating the USR, which needs to resolve the type. But that's
invalid in the presence of `@_implementationOnly`.

This most commonly comes up during index while building as even though
it skip internal decls, by that point it's too late (`SemaAnnotator` has
already tried retrieving the location). Other uses of
`SourceEntityWalker` should be unaffected as they only run over the
current decls in the current module.

For now skip walking internal top level decls from serialized modules in
`SemaAnnotator`. Consider expanding this to most, if not all,
`ASTWalker` clients in the future - it's unlikely `SemaAnnotator` is the
only one with this problem.

Resolves rdar://91279771.
2022-04-15 17:08:47 -07:00
Rintaro Ishizaki
4e621408aa [CodeCompletion] Ensure synthesized members are available before lookup
In ExprContextAnalyzer, when looking up members, some implicit
members weren't populated. Ensure all implicit members available by
force synthesizing them.

rdar://89773376
2022-04-15 11:47:36 -07:00
Alex Hoppen
11c3ff0534 Merge pull request #42211 from ahoppen/pr/dont-distinguish-identical-convertible-type-relation
[CodeCompletion] Don't distinguish convertible and identical type relation
2022-04-13 12:01:25 +02:00
Alex Hoppen
5d01a097e1 [CodeCompletion] Don't distinguish convertible and idenical type relation
I think that preferring identical over convertible makes sense in e.g. C++ where we have implicit user-defined type conversions but since we don’t have them in Swift, I think the distinction doesn’t make too much sense, because if we have a `func foo(x: Int?)`, want don’t really want to  prioritize variables of type `Int?` over `Int` Similarly if we have `func foo(x: View)`, we don’t want to prioritize a variable of type `View` over e.g. `Text`.

rdar://91349364
2022-04-13 08:28:17 +02:00
Rintaro Ishizaki
624c07b13a Merge pull request #42200 from rintaro/ide-completion-rdar89051832
[CodeCompletion] Don't mark some undesirable imported default values
2022-04-12 11:34:44 -07:00
Ben Barham
e2c9836a1d [CursorInfo] Add Clang documentation to SymbolGraph output
This currently doesn't check for inherited docs, ie. either the
imported declaration has docs or it doesn't. There's also a few odd
cases with mixed doc types and when each line is prefixed with '*', but
it's good enough for an initial implementation.

Moves UTF8 sanitisation out of ASTPrinter.h and into Unicode.h so that
it can be used here as well.

Resolves rdar://91388603.
2022-04-08 13:46:38 -07:00
Rintaro Ishizaki
2b9ee76677 [CodeCompletion] Don't mark some undesirable imported default values
For ObjC NS_OPTIONS/NSDictionary parameters with some specific names,
ClangImporter implicitly adds default values. However, that behavior is
sometimes not really desirable. For example, for:

  -(void)addAttributes:(NSDictionary *)attrs;

'attrs' is defaulted, but calling 'addAttributes()' doesn't make any sense.
In code-completion, consider such paramters non-defaulted.

rdar://89051832
2022-04-06 09:58:49 -07:00
Alex Hoppen
c21a75def4 [CodeCompletion] Migrate CaseStmtBeginning to solver-based 2022-04-06 09:59:33 +02:00
Rintaro Ishizaki
0dad5ff24e [NFC][CodeCompletion] Prepend 'should' to 'addItemWithoutDefaultArgs'
Rename 'addItemWithoutDefaultArgs' to 'shouldAddItemWithoutDefaultArg'
because this function only returns bool indicating "should or not".
2022-04-05 16:53:37 -07:00
Rintaro Ishizaki
cd4bc88443 Merge pull request #42145 from rintaro/ide-completion-rdar90399603
[CodeCompletion] Update for SE-0345 shorthand optional binding
2022-04-05 16:30:29 -07:00
Rintaro Ishizaki
bcc003bd2d [CodeCompletion] Update for SE-0345 shorthand optional binding
Suggest visible optional values after 'if let'.

rdar://90399603
2022-04-05 09:56:14 -07:00
Alex Hoppen
9456fa12ed Merge pull request #41922 from ahoppen/pr/migrage-accessorbeginning-solver-based
[CodeCompletion] Migrate AccessorBeginning to solver-based
2022-04-05 17:50:48 +02:00
Alex Hoppen
cbbca3801f [CodeCompletion] Teach TypeCheckASTNodeAtLocRequest to check initializers
This simplifies the logic in `ide::typeCheckContextAt` and fixes an issue that prevent code completion from working inside variables that are initialized by calling a closure.

Fixes rdar://90455154 [SR-16012]
Fixes rdar://85600167 [SR-15495]
2022-04-04 14:41:59 +02:00
Alex Hoppen
8cd5bbd5e6 [CodeCompletion] Migrate AccessorBeginning to solver-based 2022-04-03 16:46:23 +02:00
Alex Hoppen
0ded798ceb Merge pull request #42006 from ahoppen/pr/prepare-for-migrate-postfixexprparen
[CodeCompletion][Sema] Multiple improvements to prepare for migration of PostfixExprParen to solver-based
2022-04-03 16:43:36 +02:00
Ben Barham
ff5f1b9bff Merge pull request #41929 from bnbarham/ast-manager-use-overlays
[SourceKit] Make sure to use overlays when reading files
2022-03-25 10:02:32 -07:00
Alex Hoppen
2d7dbd3f4e [CodeCompletion] Check if type is function before making call pattern suggestions 2022-03-25 10:42:08 +01:00
Alex Hoppen
080410521c [CodeCompletion] Don't fail in ArgumentCompltion if no overload was found 2022-03-25 10:42:08 +01:00
Alex Hoppen
2392117a2d [CodeCompletion] Record solution-specific variable types in argument completion
We are doing global completion for function arguments, so we should also record the variable types determined by the solution.
2022-03-25 10:42:08 +01:00
Alex Hoppen
f2230502e4 [CodeCompletion] Compute semantic context based on where the called fucntion is defined 2022-03-25 09:36:06 +01:00
Alex Hoppen
237376b980 [CodeCompletion] Call into simplifyTypeImpl when simplifying a type for code completion
This makes sure we e.g. resolve dependent member types after we perform type variable to generic parameter substitutions for code completion
2022-03-25 09:36:05 +01:00
Alex Hoppen
32dc26139b [CodeCompletion] Don't crash in CompletionLookup if function type has no extInfo 2022-03-25 09:36:05 +01:00