Commit Graph

17 Commits

Author SHA1 Message Date
Hamish Knight
f7e9222145 [Completion] Tweak assert for subscript call pattern
We may not have a semantic context kind if the
subscript decl is missing, for cases such as
the implicit `keyPath` subscript.

rdar://139333904
2024-11-15 17:44:27 +00:00
Hamish Knight
b81d0e7a47 [test] Use %batch-code-completion for complete_subscript.swift 2024-11-15 17:43:24 +00:00
Alex Hoppen
278ecef284 [CodeCompletion] Don’t report a call pattern as convertible if its result type doesn’t match
To compute the expected type of a call pattern (which is the return type of the function if that call pattern is being used), we called `getTypeForCompletion` for the entire call, in the same way that we do for the code completion token. However, this pattern does not generally work. For the code completion token it worked because the code completion expression doesn’t have an inherent type and it inherits the type solely from its context. Calls, however, have an inherent return type and that type gets assigned as the `typeForCompletion`.

Implement targeted checks for the two most common cases where an expected type exists: If the call that we suggest call patterns for is itself an argument to another function or if it is used in a place that has a contextual type in the constraint system (eg. a variable binding or a `return` statement). This means that we no longer return `Convertible` for call patterns in some more complex scenarios. But given that this information was computed based on incorrect results and that in those cases all call patterns had a `Convertible` type relation, I think that’s acceptable. Fixing this would require recording more information in the constraints system, which is out-of-scope for now.
2024-04-10 16:06:47 -07:00
Alex Hoppen
32eff21977 [IDE] Remove "Begin completions" and "End completions" from test cases
These test lines weren't actually providing any value and were annoying to write. Let's jut remove them.
2023-03-22 09:07:17 -07:00
Alex Hoppen
2108674ec1 Merge pull request #63849 from ahoppen/ahoppen/equivalent-type-vars
[IDE] Inspect all equivalent type variables to replace a type variable by an archetype
2023-03-01 14:36:30 +01:00
Alex Hoppen
8951373032 [IDE] Inspect all equivalent type variables to replace a type variable by an archetype
Sometimes the type variable itself doesn't have have an originator that can be replaced by an archetype but one of its equivalent type variable does.
Search thorough all equivalent type variables, looking for one that can be replaced by a generic parameter.
2023-02-22 23:00:48 +01:00
Alex Hoppen
390d7a6882 [CodeCompletion] Compute type relations for the function calls selected by ArgumentCompletion 2023-02-22 22:33:40 +01: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
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
Rintaro Ishizaki
154cd88c86 [CodeCompletion] Use 'Flair' to describe "is argument labels" 2021-06-07 17:25:01 -07:00
Rintaro Ishizaki
6dd5d9482f [CodeCompletion] Introduce "Flair" in code completion
To describe fine grained priorities.

Introduce 'CodeCompletionFlair' that is a set of more descriptive flags for
prioritizing completion items. This aims to replace '
SemanticContextKind::ExpressionSpecific' which was a "catch all"
prioritization flag.
2021-06-07 17:25:01 -07:00
Rintaro Ishizaki
38d8b13520 [CodeCompletion] Add keypath apply subscript after open bracket
rdar://problem/61016147
2020-06-09 11:04:02 -07:00
Rintaro Ishizaki
9225cfce3d [CodeCompletion] Type annotation for call argument completions 2020-03-12 17:46:25 -07:00
Rintaro Ishizaki
f8147f72d9 [CodeCompletion] Call argument label with value placeholder
When a completion happens at a call argument position, insert
'label: <#T##TypeName#>' instead of just 'label: '.

rdar://problem/60379654
2020-03-12 11:48:15 -07:00
Rintaro Ishizaki
78d0f6aa4a [CodeCompletion] Primarily use getPossibleCallees() for call signature completion
instead of the pre-typechecked type and the referenced decl in the AST
so that we can suggests all overloads even if it happen to be
typechecked to a method. For example

    struct MyType {
      func foo() {}
      func foo(_ int: Int) {}
      func foo(name: String, value: String) {}
    }
    func test(val: MyType) {
      value.foo(#^COMPLETE^#)
    }

In this case, the call is typechecked to 'MyType.foo(_:)', but we want
to suggest all overloads.

rdar://problem/59285399
2020-02-28 16:44:03 -08:00
Rintaro Ishizaki
1b688d5e21 [CodeCompletion] Implement call signature completion for subscript
rdar://problem/28874899
2019-05-17 14:20:28 -07:00
Rintaro Ishizaki
6e0b8c2b67 [CodeCompletion] Completion support for static subscript
rdar://problem/49131687
2019-04-19 21:36:17 -07:00