Commit Graph

16 Commits

Author SHA1 Message Date
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
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
18dc9c1c27 [CodeCompletion] Remove CodeComletionString::getName()
`CodeCompletioString::getName()` was used only as the sorting keys in
`CodeCompletionContext::sortCompletionResults()` which is effectively
deprecated. There's no reason to check them in `swift-ide-test`. Instead,
check `printCodeCompletionResultFilterName()` that is actually used for
filtering.
2021-07-16 13:24:19 -07:00
Alex Hoppen
917fdc9fc0 [Sema] Check completion key path component to determine if completion node was type checked in multi expression closure
To check whether the code completion node was type checked in a multi statement closure, we were assuming that we had a code completion *expression* and not considering that we could also complete in a key path component. When applicable, check if the completion key path component has a type to determine if the completion node was type checked as part of a multi-statement closure.

Resolves rdar://80271598 [SR-14891]
2021-07-08 00:24:14 +02:00
Alex Hoppen
78a7fe8438 [Sema] Record type of identity key paths in the constraint system
If we are completing e.g. `\.self.#^COMPLETE^#` we use the type of `self` as the base type for the completion. In order to retrieve that, we need to record the type.

Fixes rdar://80271346 [SR-14887]
2021-07-07 23:47:09 +02:00
Alex Hoppen
d64b8ecea6 [CodeCompletion] Migrate key path completion to be solver based
This commit essentially consistes of the following steps:
- Add a new code completion key path component that represents the code completion token inside a key path. Previously, the key path would have an invalid component at the end if it contained a code completion token.
- When type checking the key path, model the code completion token’s result type by a new type variable that is unrelated to the previous components (because the code completion token might resolve to anything).
- Since the code completion token is now properly modelled in the constraint system, we can use the solver based code completion implementation and inspect any solution determined by the constraint solver. The base type for code completion is now the result type of the key path component that preceeds the code completion component.

This resolves bugs where code completion was not working correctly if the key path’s type had a generic base or result type. It’s also nice to have moved another completion type over to the solver-based implementation.

Resolves rdar://78779234 [SR-14685] and rdar://78779335 [SR-14703]
2021-06-25 23:19:35 +02:00
Rintaro Ishizaki
75a0c9f819 [CodeCompletion] Add 'IsSystem' flag to code completion result item
'key.is_system: 1' is added if the associated declaration is from a
system module.

rdar://problem/62617558
2020-05-11 12:24:36 -07:00
Rintaro Ishizaki
315f65f962 [CodeCompletion] Use AnyFunctionType::Param::getParameterType()
instead of getOldType() in KeyPath as funtions completion.
Also, don't think keypath's are convertible to functions that receives
variadic parameters.
2020-04-10 15:55:32 -07:00
Rintaro Ishizaki
bfa385c0b7 [CodeCompletion] Update for SE-0249 KeyPath as functions
If the context type is a function type that receives one argument, infer
the key path expressions root type from the context.

rdar://problem/59302416
2020-02-13 13:11:36 -08:00
Arnold Schwaighofer
1386af04a2 Revert "stdlib: Add custom .first to Array"
This reverts commit 3e932c075d.

The compiler does not support @_alwaysEmitIntoClient properties
specially wrt property descriptors. The revert commit would introduce an
ABI incompatability when a keypath to Array.first is formed:

    let greetings = ["hello", "hola"]
    let count = greetings[keyPath: \[String].first?.count]

Runmning on an older runtime would lead to linker errors against $sSa5firstxSgvpMV
the property descriptor for Array.first.

rdar://58484319
2020-01-13 13:07:00 -08:00
Erik Eckstein
3e932c075d stdlib: Add custom .first to Array
This makes Array.first much small and more efficient.
Without this, Array.first compiled down to RandomAccessCollection.first, which ended up in pretty unefficient code.

rdar://problem/46291397
2019-11-27 09:55:27 +01:00
Rintaro Ishizaki
65d8d29d2a [CodeCompletion] Infer keypath root type from the context type
So that this works:

```
func foo(_: KeyPath<SomeObject, Int>) {}
foo(\.<HERE>)
```

rdar://problem/46102807
2019-03-25 16:29:19 -07:00
Rintaro Ishizaki
489a53864c [CodeCompletion] Display mapped type for subscript result 2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
c99af83901 [CodeCompletion] Consolidate parameter list processing funcitons
There were 2 functions to output argument list. Consolidate them and
consistently use it from every call like production (i.e. function call,
constructor call, enum with associated values, subscript)
2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
1ac6afb3cf [CodeCompletion] Improve completion for Swift keypath expression
* Handle completion in 'parseExprKeyPath()' instead of
  'parseExprPostfixSuffix()'.
* Fix a crash for implicit type keypath. e.g. '\.path.<complete>'. (SR-8042).
* Use 'completeExprKeyPath()' callback.
* Implement completion without '.'. e.g. '\Ty.path<complete>'
* Improved handling for 'subscript' in completion.
* Improved handling for optional unwrapping in completion.

https://bugs.swift.org/browse/SR-8042
rdar://problem/41262612
2018-08-22 11:08:53 +09:00
Xi Ge
e997128129 [CodeCompletion] Provide basic code completion support for Swift KeyPath. rdar://31768743 (#9467) 2017-05-10 21:48:50 -07:00