Commit Graph

74 Commits

Author SHA1 Message Date
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
c385fe5e87 [CodeCompletion] Migrate PostfixExprParen to solver-based 2023-07-07 19:50:46 +02:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03: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
3ad1ac75b9 [IDE] Change -NEXT to -DAG in test cases
We don’t actually care about the order of the results here. Change `-NEXT` to `-DAG` to make the test cases more robust to changes  in code completion.
2023-02-16 09:39:01 +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
Hamish Knight
63c6f987de Merge pull request #38447 from hamishknight/fewer-substitutions-for-you 2021-07-19 18:14:09 +01:00
Hamish Knight
f90befe441 [CodeCompletion] Use substGenericArgs in getTypeOfMember
For a GenericFunctionType, use `substGenericArgs`
instead of `subst`, as the latter would form a bad
generic signature if there were UnresolvedTypes
present in the base type, causing the GSB to blow
up when attempting to canonicalize it.

rdar://80635105
2021-07-19 11:26:07 +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
Rintaro Ishizaki
154cd88c86 [CodeCompletion] Use 'Flair' to describe "is argument labels" 2021-06-07 17:25:01 -07: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
Marc Rasi
5772ddda7e fix autocomplete crash 2020-03-20 14:43:46 -07:00
Rintaro Ishizaki
62078c79dd [ASTPrinter/CodeCompletion] Stop printing base type when possible
rdar://problem/57033931
2019-12-17 16:26:37 -08:00
Rintaro Ishizaki
ad4b9df3c0 [CodeCompletion] Suggest the property name in its didSet clause
Previously, property names are hidden in the whole range of the
declarations. Now, it's only hidden in its own initializer range.

rdar://problem/49697202
2019-12-03 18:12:47 -08:00
Slava Pestov
44827bbde4 IDE: Refactor LookupVisibleDecls to use standard override/shadowing logic
There's no need to roll our own implementation here.

Fixes <rdar://problem/16724197>.
2019-09-25 22:17:56 -04:00
Rintaro Ishizaki
4353a55587 [CodeCompletion] Fix a crash in collectPossibleCalleesByQualifiedLookup
We cannot assume that 'FuncDecls' have 'AnyFunctionType' interface type
or null type. They can be 'ErrorType's.

rdar://problem/54215016
2019-08-12 12:27:30 -07:00
Rintaro Ishizaki
7b7c320bd5 [CodeCompletion] Allow ErrorType in constructor
Even if the constructor has `ErrorType` we can suggest it as long as it's
`FunctionType`.

rdar://problem/49480808
2019-05-13 01:32:57 -07:00
Ben Langmuir
e255bac6be [code-completion] Fix type context for single-expression implicit getter
This adds an implicit body so that we can dig out the return type
context the same way as a normal function. For now, we are also treating
the first expression in a multi-statement implicit getter body the same
way; we'll need to refactor how we complete in accessors to
differentiate those cases.
2019-03-26 16:45:32 -07: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
82b5f2a195 [CodeCompletion] Find parsed expression from typechecked decl context
Instead of re-typechecking parsed expression, find typechecked
expression that corresponds to the parsed expression from the
typechecked decl context, because the sub expressions of the parsed
expression can be weirdly mutated/replaced by decl context typechecking.

rdar://problem/48141174
2019-02-28 18:39:46 -08:00
Slava Pestov
f7e39447a7 LookupVisibleDecls: Find generic parameters in methods inside extensions
The logic here had diverged from UnqualifiedLookup. One day we'll merge
the two, for now clean it up a bit to match.

Note that all generic parameters now have 'Reason' reported as 'Local'.
I don't believe this really matters.

Fixes <rdar://problem/20530021>.
2019-01-08 16:51:20 -05:00
Rintaro Ishizaki
d86725cf80 [ConstraintSystem] Ignore patterns in linked expression analysis (#18487)
Fixes an assertion hit in "pattern in binary expression" case.

rdar://problem/41071587
2018-08-04 11:26:09 +09:00
Rintaro Ishizaki
bcb83acfe9 [AST] Fix a crash in UnqualifiedLookup
Add null type check for `Self` type in `UnqualifiedLookup`. It seems this
doesn't happen in normal compilation. But when code-completion happens in
inactive conditional compilation block, since surrounding context hasn't
been typechecked, `Self` type can be null.

rdar://problem/41234606
2018-07-27 15:47:26 +09:00
Rintaro Ishizaki
9e7fa99689 [CodeComplete] Use PrintOptionalAsImplicitlyUnwrapped to print IUO
Other instances of fb9c65e. Consistently use
PrintOption.PrintOptionalAsImplicitlyUnwrapped to print IUO.

rdar://problem/41046225
rdar://problem/42443512
2018-07-26 07:55:25 +09:00
Rintaro Ishizaki
2babbc3a44 [CodeComplete] Handle ternary expression in sequence completion
Follow-up to f577578a6a. The same
treatment for ternary expression (IfExpr). Plus, fix a regression
introduced in f577578a where infix operators were disappeard from
results.
2018-07-25 13:59:20 +09:00
Rintaro Ishizaki
4c0892fdc6 [CodeComplete] Strip out try and optional eval expr in operator compilation
foldSequence() may hoist these expression up by mutating their sub
expression. When completing operators, this behavior ruins reusability
of operand. Since these expression doesn't affect completion, we can
strip them out.

rdar://problem/42452085
2018-07-25 13:58:53 +09:00
Rintaro Ishizaki
fb9c65e108 [CodeComplete] Fix crasher when completing inout IUO variable
Use `PrintOptionalAsImplicitlyUnwrapped` option.

rdar://problem/40956846
2018-07-14 00:52:57 +09:00
Rintaro Ishizaki
52e3109231 [CodeComplete] Restore original type in getOperatorCompletions
In getOperatorCompletions(), for each every known operators, temporary
expressions are created and typechecked. In this process, typechecker
may set the type of the parsed expression. That may cause non-accurate
completion results or crash at worst.

rdar://problem/28188259
2018-06-27 19:35:25 +09:00
Rintaro Ishizaki
8c970ab26d [CodeComplete] Handle assign expression in sequence completion
rdar://problem/41232519
rdar://problem/41159258
2018-06-27 19:35:25 +09:00
Slava Pestov
edc3b7bfc3 Migrate IDE tests to Swift 4
I couldn't update complete_func_reference. Fixing the problem there
is tracked by rdar://problem/41496748.
2018-06-26 16:56:33 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Robert Widmann
1beb75583a Push FunctionTypeRepr Input Invariants Up
Validation of the input side of FunctionTypeRepr was previously being done in Sema because of expression folding.  If we instead push the invariant that the input TypeRepr should always be a TupleTypeRepr into the AST a number of nice cleanups fall out:

- The SIL Parser no longer accepts Swift 2-style type declarations
-  Parse is more cleanly able to reject invalid FunctionTypeReprs
- Clients of the AST can be assured the input type is always a TupleType so we can flush Swift 2 hacks
2018-06-13 18:41:20 -07:00
fischertony
7b41a41fb6 updated tests & added completions for postfixExpr 2018-05-12 09:05:57 +03:00
Pavel Yaskevich
a014842696 [CSBindings] Look through non-value types earlier to avoid producing incorrect bindings
Before checking any requirements of the binding type, let's look
through @autoclosure and/or non-variable types if source constraint
requires that, otherwise we'd end up creating bindings for types
which later on might end up causing infinite recursion like dependent
member types in result position of @autoclosure parameter.

Resolves: rdar://problem/38272904
2018-04-05 00:11:15 -07:00
Nathan Hawes
136b5eff8b [CSGen][CSDiag] Update SanitizeExpr to santize OpenExistentialExpr
They can show up when re-typechecking via diag or code-completion and were
only being sanitized out in one place in CSDiag. Moved that logic into
SanitizeExpr.

Resolves rdar://problem/38149042
2018-04-02 11:42:09 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Ben Langmuir
642ae90a86 [code-complete] Reduce the priority of function call patterns
Constructor call patterns already get a real priority, but because of
the way we do function call patterns we don't have enough information,
and previously we were setting it to "expression specific", which is
unnecessarily high, particularly since functions (unlike inits) have
other better ways to code-complete already.

rdar://31113161
2017-12-18 12:55:20 -08:00
Ben Langmuir
b6d5a1f1a5 [code-complete] Do not insert rparen after a call pattern completion
When completing
  Foo(<here>
We will now provide
  bar: <#value#>
instead of
  bar: <#value#>)

Inserting the rparen caused some problems in practice:
* the old behaviour optimized for typing Foo(<complete> instead of
  Foo(<complete>), which can conflict with user behaviours or ...
* in editors with automatic brace-matching, we often conflicted with the
  editor, leading to extraneous closing parens

And in general, it is much more predictable for tooling to either insert
matching ( and ) or to not insert either.  While this change may not be
ideal For users of editors that do not do automatic brace-matching, I
believe it is still better overall to have to type a missing paren than
to have to delete an extraneous one.

rdar://31113161
2017-12-18 11:59:49 -08:00
Slava Pestov
c197df6e7f Sema: Fix type checking without applying solution in presence of anonymous closure parameters
Even if we don't apply the solution, we still end up writing
types into ParamDecls of closures contained the expression.

Make sure this is idempotent by disabling 'cleanup', which
avoids setting them to ErrorTypes, and teaching ExprCleaner
to clear out types of VarDecls.

This is a hack that will get better once the constraint
system type map stuff is further along.

Fixes <rdar://problem/33219081>.
2017-07-11 17:00:35 -07:00
Huon Wilson
8c8f35ee78 [Parse] Don't tell CodeCompletion nonsense about protocol/AT where clauses.
This doesn't give particularly useful information yet (i.e. Self isn't
listed, see rdar://problem/31981641 ), but it does stop the completion
code from just directly crashing.

Fixes rdar://problem/31981486.
2017-05-12 16:00:00 +10:00
Xi Ge
911f7b1805 [CodeCompletion] Using the default constraints generator for TupleExpr (#5557)
[CodeCompletion] Using the default constraints generator for TupleExpr
when inferring the type of unresolved members. rdar://28991372

When code completing, we used to create a type variable to represent the type
of an entire tuple expression. However, recent improvements on parser make this
step unnecessary and crash-prone. Thus, we use the default constraint
generator to interpret tuple expressions.
2016-10-31 12:00:50 -07:00
Argyrios Kyrtzidis
69918a966d [ASTPrinter] Fix printing of nested typealias types and make it consistent with printing of nominal types.
This fixes several issues:
- By default parent types of alias types are not printed which results in
	- Erroneous fixits, for example when casting to 'Notification.Name' from a string, which ends up adding erroneous cast
	  as "Name(rawValue: ...)"
	- Hard to understand types in code-completion results and diagnostics
- When printing with 'fully-qualified' option typealias types are printed erroneously like this "<PARENT>.Type.<TYPEALIAS>"

The change make typealias printing same as nominal types and addresses the above.
2016-08-11 12:15:15 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Chris Lattner
ffcafd7c00 fix the AST printer to stop omitting parens around "simple enough" parameter
lists.
2016-07-02 20:24:58 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Dmitri Gribenko
efaa39ea79 stdlib: add first argument labels and some other changes to conform to API guidelines 2016-02-15 23:47:54 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Xi Ge
ca873a9629 [CodeCompletion] Add null check to prevent assertion violations. rdar://22769393 2016-01-14 15:31:32 -08:00