Commit Graph

490 Commits

Author SHA1 Message Date
Ben Langmuir
de822415ef [CodeCompletion] Be more defensive about null type in RHS of assignment
This crashed until recently, and although I couldn't find a case where
the RHS had a null type anymore, I also couldn't see a reason it
couldn't happen, since we don't always assign types to every expression
in code-completion type-checking.

rdar://problem/23111219

Swift SVN r32793
2015-10-21 18:27:38 +00:00
Ben Langmuir
83cfbae905 [CodeCompletion] Add labels for first argument when not showing patterns
When not completing a full call pattern for the first argument, such as
here:
  foo(<here>, arg2: blah)

we now show the argument label if appropriate.

For rdar://problem/22804670

Swift SVN r32774
2015-10-20 16:28:45 +00:00
Ben Langmuir
923079c814 [CodeCompletion] Fix r32765 when completing at EOF
Swift SVN r32767
2015-10-19 22:48:35 +00:00
Ben Langmuir
a2c7298af5 [CodeCompletion] Don't complete entire call patterns inside existing calls
Peek at the token following the code completion location to decide
whether or not to provide completions for entire call patterns.  When
the next token looks like it's part of an existing call we don't show
the patterns because they will "push out" the existing arguments.

We should now get:
  Foo<here> =>  (blah, blah)
  Foo(<here> =>  ['(']blah, blah)
  Foo(<here>) => ['(']blah, blah[')']
  Foo(<here>, blah) => just complete the values for arg1**
  Foo(<here>blah, blah) => just complete the values for arg1

** A further improvement will be to add the argument label completion
for the first argument (if applicable) when we aren't showing a full
call pattern.

rdar://problem/22804670

Swift SVN r32765
2015-10-19 21:47:01 +00:00
Xi Ge
fd94ce676f [CodeComplete] Start using TypeSubstitutionMap to transform generic type parameters. NFC
Swift SVN r32713
2015-10-15 20:57:22 +00:00
Ben Langmuir
dc910fe53b [CodeCompletion] Handle sequence expression where the LHS type-checks
Now we can handle simple cases like
  1 + 1 == 2 <here>

and correctly suggest both + on the 2 and || on the boolean. When the
LHS doesn't type-check we fallback to using only the operand immediately
to the left.

Swift SVN r32489
2015-10-07 07:30:11 +00:00
Ben Langmuir
f969a9941b [CodeCompletion] Handle simple cases of space in front of postfix completions
This is pretty crude, but handles the common cases of there being 0 or 1
space between the LHS and an operator completion.

Swift SVN r32472
2015-10-06 23:35:39 +00:00
Ben Langmuir
d871c9a529 [CodeCompletion] Split code completion operator kind out
...into separate prefix, postfix and infix operators. Also incidentally
make the whitespace around operators special so we can decide when to
skip over it. Tested in SourceKit.

Swift SVN r32468
2015-10-06 22:52:16 +00:00
Ben Langmuir
9448df6fae [CodeCompletion] Add initial support for completing infix operators
This allows us to start code-completing infix operators in postfix
expressions.  As a first step, this patch only handles completing
against the immediate LHS (so for example 1 == 1 <here> doesn't suggest
boolean operators yet).

The next step is to feed the leading sequence expression from the parser
in so we can consider how the operator being completed fits into the
whole sequence expression.

For rdar://problem/22460167

Swift SVN r32465
2015-10-06 20:48:03 +00:00
Ben Langmuir
3b0c30a66a Remove dead code from r32355
Swift SVN r32370
2015-10-01 16:54:51 +00:00
Ben Langmuir
f819eb01eb [CodeCompletion] Add initial support for completing postfix operators
This allows us to start code-completing postfix operators (generally !,
++, and --), which lays some of the groundwork for completing the much
more interesting infix operators.

These only show up when in postfix position
  x<here>

For  rdar://problem/22460167

Swift SVN r32355
2015-09-30 23:48:17 +00:00
Ben Langmuir
be016aedf3 [CodeCompletion] Don't add empty code completion on invalid init
For now, just avoid adding the completion since that will assert later
when we try to sort. In the future we could actually complete something
useful here, since we can dig out the names of the parameters even if
the type is invalid.

rdar://problem/22834017

Swift SVN r32211
2015-09-24 22:13:13 +00:00
Xi Ge
c73a4e1509 [CodeComplete] Teach type context analyzer to analyzer for each statement. rdar://22831848
When completing at the sequence position of for each statment (for i in <HRER> {}),
values of sequence type should have higher priority than the rest.

Swift SVN r32202
2015-09-24 17:47:20 +00:00
Xi Ge
3ace989167 [CodeComplete] Teach type context analyzer to handle pattern initializer. rdar://22804344
Swift SVN r32154
2015-09-22 21:06:58 +00:00
Xi Ge
7a255a965e [CodeComplete] Teach type context analyzer to handle return statement. rdar://22788321
Swift SVN r32143
2015-09-22 01:18:28 +00:00
Xi Ge
8b869e1113 [CodeComplete] When completing import statements, show all visible modules without filtering out the already imported ones. rdar://22788409
Swift SVN r32127
2015-09-21 21:45:44 +00:00
Xi Ge
dfc48c8aee [CodeComplete] Add type relation descriptor when completing return statement. rdar://22788321
Swift SVN r32125
2015-09-21 21:18:26 +00:00
Xi Ge
cdabf645ea [CodeComplete] Make code completion available for returnStmt of global func decls. rdar://22282116
Swift SVN r32122
2015-09-21 20:01:22 +00:00
Ben Langmuir
3fdfd1a05a [CodeCompletion] Fix assertion failure with curried function
Remove some untested broken code that I am fairly sure could never find
the correct FunctionDecl.

rdar://problem/22688199

Swift SVN r32000
2015-09-16 18:03:32 +00:00
Ben Langmuir
64b1cd6fd3 [CodeCompletion] Treat top-level variables as local in top-level completion
Global variables from the same source file are more like locals when
writing top-level code, particularly in Playgrounds. Other declarations
(types, global functions, etc.) are unaffected.

rdar://problem/22329905

Swift SVN r31992
2015-09-16 16:35:27 +00:00
Xi Ge
2d0c1a0002 [CodeComplete] Add type relation descriptors to the member completions of assignment expressions. rdar://22706743
Swift SVN r31967
2015-09-15 19:53:43 +00:00
Ben Langmuir
242859eb5f [CodeCompletion] Avoid expensive top-level lookups in type-specific completion
We can't afford to walk all the top-level results, which includes every
type and global function in the SDK.  Instead, use the usual caching
mechanisms.

This means we never get type relations on top-level SDK symbols, but
this should be fine for most cases because:

1) For ObjC code, we don't generally care about global functions. And
in practice most of the matching global functions for common types are
not high-priority anyway (e.g. alignof for Int).

2) In a previous commit I manually added the names of types so that we
can do later code completions to get initializers and static methods.
E.g. you will still get "CGRect" if you complete inside drawInRect(...).

Top-level results from the current module should be unaffected.

Swift SVN r31961
2015-09-15 18:12:01 +00:00
Ben Langmuir
a03da9e792 [CodeCompletion] Show expected nominal types from other modules
Since other module results are cache, manually add the type names of
expected nominal types in call arguments so that we can get the type
relationship correct

For rdar://problem/22271094

Swift SVN r31959
2015-09-15 17:36:22 +00:00
Xi Ge
5fa75a2eb3 Avoid collecting type variable types as results, as an attempt to fix the following bot failures:
Swift SVN r31952
2015-09-15 00:17:22 +00:00
Chris Lattner
0780313217 remove some unused variables & member var
Swift SVN r31936
2015-09-14 21:48:56 +00:00
Xi Ge
8d67a4ad12 [CodeComplete] Propagate type relation descriptor to the first argument, or the only argument, of call exprs.
rdar://22688827

Swift SVN r31928
2015-09-14 19:43:36 +00:00
Ben Langmuir
4acbf712e7 [CodeCompletion] Expose the code completion kind NFC
This exposes the code completion kind so that SourceKit has more
information about the code completion context.

For rdar://problem/22460026

Swift SVN r31925
2015-09-14 16:19:14 +00:00
Xi Ge
d4922f3bd4 Update to more meaningful param name.
Swift SVN r31910
2015-09-12 00:54:05 +00:00
Xi Ge
1cb84686d4 [CodeComplete] Preserve call expr when code completion token appears in the first arg.
Swift SVN r31909
2015-09-12 00:28:28 +00:00
Xi Ge
ec4e469062 [CodeComplete] Introduce code completion expr to better preserve the context of the code completion token in ASTs.
Swift SVN r31908
2015-09-11 22:59:12 +00:00
Xi Ge
6dd6fff440 [CodeComplete] Rename ExpectedTypeRelation:Undetermined to ExpectedTypeRelation::Unrelated.
Swift SVN r31844
2015-09-10 01:50:04 +00:00
Xi Ge
65ce0a36b8 [CodeComplete] Add type relation descriptor to member access syntax. rdar://22629291
By analyzing the context of a member access expression, we can prioritize the member
completion results by the expected type. As the initial step, we support call arguments
as context.

Swift SVN r31837
2015-09-10 00:28:14 +00:00
Michael Gottesman
0606d5843a Remove calls to raw_svector_ostream::flush()
This function is deleted since LLVM r244928.

Swift SVN r31798
2015-09-09 04:37:13 +00:00
Xi Ge
f820972697 [CodeComplete] Avoid resetting code completion kind except for expected cases. rdar://22619751
Swift SVN r31789
2015-09-08 23:43:55 +00:00
Xi Ge
92ea1fa085 [CodeComplete] Update enclosed archetypes to the protocols they conform to.
Swift SVN r31723
2015-09-05 23:57:37 +00:00
Xi Ge
ece9cd1cc4 [CodeComplete] Pre-compute generic type params when transforming archetypes in code completion results.
Swift SVN r31704
2015-09-05 01:34:15 +00:00
Xi Ge
b42a30df27 [CodeComplete] For an archetype that is not Self derived, use the conformed protocol type (if any) instead of the archetype itself.
Swift SVN r31681
2015-09-03 23:58:29 +00:00
Xi Ge
2fe26c966c [CodeComplete] Get singly desugared type and update tests.
Swift SVN r31674
2015-09-03 22:49:02 +00:00
Xi Ge
213c6a5c7b [CodeComplete] Teach archetype transformer to handle type alias.
Swift SVN r31670
2015-09-03 20:46:23 +00:00
Xi Ge
07a848cf64 [CodeComplete] Address Argyrios' review comments.
Swift SVN r31653
2015-09-03 02:36:11 +00:00
Ben Langmuir
0a43e5460f [CodeComplete] Don't try to lookup members of null type
rdar://problem/22012123

Swift SVN r31639
2015-09-02 21:16:48 +00:00
Xi Ge
08eda102ed [CodeComplete] Finish transforming archetypes to actual types in code completion results and update tests.
Swift SVN r31635
2015-09-02 20:18:16 +00:00
Xi Ge
f75ac75d3b [CodeComplete] Try to substitute archetypes with actual types in code completion results.
When completing type members, teach the code completion engine to
transform the archetypes appearing in code completion results to the
actual types. NFC

Swift SVN r31628
2015-09-02 06:22:20 +00:00
Xi Ge
afb46aa8e0 [CodeComplete] When completing call args, not consider those overloads that are unlikely to be selected.
rdar://22528276

Swift SVN r31613
2015-09-01 22:54:19 +00:00
Xi Ge
ef3b45871b [CodeComplete] Complete arguments of call expressions.
When users invoke code completion at an argument position, we suggest argument names,
if required however not specified, or a list of argument values. These values are annotated
with their type relation to the expected argument types, so that
Xcode can prioritize those values that apply over those that do not.
This also fixes: rdar://21727063

Swift SVN r31505
2015-08-26 22:01:25 +00:00
Doug Gregor
cab320296d Stop recording protocol lists in nominal types.
The conformance lookup table is responsible for answering queries
about the protocols to which a particular nominal type conforms, so
stop storing (redundant and incorrect) protocol lists on the ASTs for
nominal types. Protocol types still store the list of protocols that
they inherit, however.

As a drive-by, stop lying about the number of bits that ProtocolDecl
uses on top of NominalTypeDecl, and move the overflow bits down into
ProtocolDecl itself so we don't bloat Decl unnecessarily.

Swift SVN r31381
2015-08-21 17:51:23 +00:00
Xi Ge
3865a6a037 [CodeComplete] Add type relation enum to the code completion results.
We use an enum to describe the relationship between a code completion result
and the expected type at the code completion site. We can use this relationship
to prioritize candidates on the SourceKit side.

Swift SVN r31371
2015-08-20 22:57:53 +00:00
Xi Ge
c33e3efe59 [CodeComplete] Complete the right hand side of assignment expressions.
When users complete the right-hand side of an assignment expression, we only
show the results whose types are convertible to those of the left-hand side.

Swift SVN r31357
2015-08-20 01:35:30 +00:00
Xi Ge
831470c88c [CodeComplete] Properly handle extensions during name lookup. rdar://22289974
Swift SVN r31280
2015-08-17 23:08:29 +00:00
Xi Ge
40a9d61103 [CodeComplete] when completing unresolved members, we also perform name lookups for enum elements, var decls and nominal types in addition to functions.
fixes: rdar://22282057, rdar://22282116, rdar://22282224, and rdar://22282278

Swift SVN r31274
2015-08-17 21:01:54 +00:00