Commit Graph

1275 Commits

Author SHA1 Message Date
Alex Hoppen
803e667024 [CodeCompletion] Rename DotExprCompletion -> PostfixCompletion 2022-07-01 15:57:54 +02:00
Alex Hoppen
795be6c2bb Merge pull request #58734 from ahoppen/pr/fix-completion-in-property-attribute
[CodeCompletion] Support type checking attributes even if they are not part of the AST
2022-05-13 09:39:00 +02: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
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
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
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
c21a75def4 [CodeCompletion] Migrate CaseStmtBeginning to solver-based 2022-04-06 09:59:33 +02: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
8cd5bbd5e6 [CodeCompletion] Migrate AccessorBeginning to solver-based 2022-04-03 16:46:23 +02:00
Alex Hoppen
2a96221d44 [CodeCompletion] Migrate AfterPoundExprCompletion to solver-based 2022-03-24 18:10:28 +01:00
Alex Hoppen
56ea3341f5 [CodeCompletion] Migrate ForEachSequence and PostfixExprBeginning to solver-based 2022-03-23 13:03:56 +01:00
Alex Hoppen
03d819f442 [CodeCompletion] Check whether surrounding context supports async in all solver-based completion kinds 2022-03-21 20:04:32 +01:00
Alex Hoppen
51777d5ff7 [CodeCompletion] Move TypeCheckCompletionCallbacks to IDE 2022-03-21 20:04:32 +01:00
Alex Hoppen
e2a62f1a60 [CodeCompletion] Migrate expression completions to solver-based 2022-03-21 13:00:33 +01:00
Alex Hoppen
f538d33e5f [CodeCompletion][Sema] Migrate CallArgurment position completion to the solver-based implementation
This hooks up call argument position completion to the typeCheckForCodeCompletion API to generate completions from all the solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any).

Co-authored-by: Nathan Hawes <nathan.john.hawes@gmail.com>
2022-03-17 15:15:54 +01:00
Alex Hoppen
e40fc772c1 Merge pull request #41667 from ahoppen/pr/complete-expr-after-if
[CodeCompletion] Complete code completion tokens after if-statement as top-level
2022-03-16 15:07:27 +01:00
Alex Hoppen
82cb46c8b0 [CodeCompletion] Complete code completion tokens after if-statement as top-level
Instead of setting the code completion position when parsing the if-statement, which doesn’t create a `CodeCompletionExpr`, parse it as a new top-level expression.

As far as test-cases are concerned, this removes the “RareKeyword” flair from top-level completions in the modified test case. This makes sense IMO.
2022-03-14 14:40:11 +01:00
Konrad `ktoso` Malawski
13cc8b3157 [Distributed] Enable no-longer-experimental distributed by default 2022-03-11 22:14:49 +09:00
Rintaro Ishizaki
92b9df0725 [CodeCompletion] Remove 'declTypeContext' field from the result builder
This field is not used anymore
2022-03-03 11:47:33 -08:00
Alex Hoppen
a02c7e7346 Merge pull request #41601 from ahoppen/pr/prepare-for-solver-based-arg-completion
[CodeCompletion] Some more code cleanup
2022-03-03 09:43:41 +01:00
Alex Hoppen
94351a2f82 [CodeComplete] Compute type relations for global cached results
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
2022-03-02 23:13:09 +01:00
Hamish Knight
1f5845d9d9 Revert "[CodeComplete] Compute type relations for global cached results" 2022-03-02 21:43:31 +00:00
Alex Hoppen
d9f3324aff [CodeCompletion] Make CodeCompletionCallbacksImpl::addSuperKeywords a static method
This matches the other add*Keywords methods.
2022-03-01 09:36:57 +01:00
Alex Hoppen
1baa1f4d9c [CodeCompletion] Extract common implementation of sawSolution and fallbackTypeCheck to TypeCheckCompletionCallback 2022-03-01 09:36:57 +01:00
Alex Hoppen
640cfac61c [CodeComplete] Compute type relations for global cached results
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
2022-03-01 09:16:23 +01:00
Alex Hoppen
5bfa9ca026 [CodeCompletion] Make deliver*Result functions members on their TypeCheckCompletionCallback 2022-02-28 11:55:25 +01:00
Alex Hoppen
36c0bcc305 [CodeCompletion] Rename postProcessResults to postProcessCompletionResults 2022-02-28 11:45:51 +01:00
Alex Hoppen
8340abd8b1 [CodeCompletion] Move solver-based key path completion to its own file 2022-02-23 17:08:27 +01:00
Alex Hoppen
c8aba81978 [CodeCompletion] Move solver-based unresolved member completion to its own file 2022-02-23 17:08:27 +01:00
Alex Hoppen
471b24f459 [CodeCompletion] Move solver-based DotExpr completion to its own file 2022-02-23 17:08:27 +01:00
Alex Hoppen
7e043159f3 [CodeCompletion] Move ImportDepth to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
48179ad01e [CodeCompletion] Split CodeCompletionConsumer into its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
faa8fd3db2 [CodeCompletion] Move CodeCompletionContext.h to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
e37796dc88 [CodeCompletion] Move CompletionOverrideLookup to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
67815f14f5 [CodeCompletion] Move implementation of CodeCompletionResultBuilder into its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
e1809ecafe [CodeCompletion] Split CodeCompletionResult and ContextFreeCodeCompletionResult into their own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
ab5b360e0b [CodeCompletion] Split CodeCompletionString into its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
b8be2794a3 [CodeCompletion] Move CompletionLookup to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
4ff14d2986 [CodeCompletion] Extract CodeCompletionStringPrinter.h to its own file 2022-02-23 17:05:51 +01:00
Rintaro Ishizaki
3c33debd61 [CodeCompletion] Make all result's string fields null terminated
This is convenient for clients to pass these fields values to C
functions. Introduce NullTerminatedStringRef to guarantee that.
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
7ef93b2a67 [Basic] Move copyCString to Basic/StringExtras.
Also, use StringRef.copy() instead of copyString().
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
5ab84ae242 [CodeCompletion] Precompute and cache "filter name"
Filter name for completion item is always used. Also, for cached items,
they are used multiple times for filtering. So precomputing and caching
it improves performance.

rdar://84036006
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
33ee4d609f [CodeCompletion] 'ContextFreeCodeCompletionResult' factory method
Convert 'ContextFreeCodeCompletionResult' constructor overloads to
'create()' factory methods. This is the consistent interface with
'CodeCompletionString'. NFC
2022-02-18 09:58:26 -08:00
Rintaro Ishizaki
7893f74142 Merge pull request #41384 from rintaro/ide-completion-actorkind-rdar79733313
[CodeCompletion] Add a symbol kind for actors
2022-02-16 15:55:47 -08:00
Alex Hoppen
bac3b67f66 Merge pull request #40999 from ahoppen/pr/compute-type-relation-in-contextual-result
[SourceKit] Compute code completion type relation when wrapping a ContextFreeCodeCompletionResult in a CodeCompletionResult
2022-02-16 22:13:22 +01:00
Alex Hoppen
6bc0de94a2 [SourceKit] Compute code completion type relation when wrapping a ContextFreeCodeCompletionResult in a CodeCompletionResult
[CodeCompletion] Make ExpectedTypeContext a class with explicit getters/setters

This simplifies debugging because you can break when the possible types are set and you can also search for references to `setPossibleType` to figure out where the expected types are being set.
2022-02-16 20:28:13 +01:00
Rintaro Ishizaki
d9011e06b2 [CodeCompletion] Add a symbol kind for actors
rdar://79733313
2022-02-15 13:14:46 -08:00
Doug Gregor
a37f291c18 Remove ActorIsolation::DistributedActorInstance.
The distributed case is distinguishable from the non-distributed case
based on the actor type itself for those rare cases where we care. The
vast majority of code is simplified by treating this identically to
`ActorInstance`.
2022-02-09 11:16:23 -08:00