Commit Graph

1365 Commits

Author SHA1 Message Date
Xi Ge
44f4fb4a67 Simplify copy, NFC 2015-11-10 11:57:29 -08:00
Nadav Rotem
90396d8c90 Fix a few unused variable warnings.
⚠️
2015-11-09 17:17:38 -08:00
Xi Ge
22ba61bea1 Reapply "[CodeComplete] Teach code completion engine to recognize and manifest @recommended and @recommendedover." after fixing a linux failure. (thanks, Dmitri) 2015-11-09 16:36:25 -08:00
Xi Ge
0a82a6fa41 Revert "[CodeComplete] Teach code completion engine to recognize and manifest @recommended and @recommendedover."
This reverts commit 448a23c9af for failing linux bots.
2015-11-06 19:06:45 -08:00
Xi Ge
448a23c9af [CodeComplete] Teach code completion engine to recognize and manifest @recommended and @recommendedover.
Similar with @keyword, manifesting @recommended and @recommendedover content in code
completion results can help IDE users to choose the right API in the long candidate list.
This commit extract these two attributes from Clang doc comments and insert/cache them in
code completion results.

rdar://23101030 and rdar://23101029
2015-11-06 18:11:17 -08:00
Xi Ge
c022c9925c [CodeComplete] Start to support keyword-based code completion. rdar://23101032
Conventionally, code completion results are matched with user input solely by
names. However, names are limited in expressiveness. From this comments, we start to
decorate code completion results with @keywords fields extracted from Clang doc comments.
These fields are added by API authors to comment the decl with information that
is not manifested clear enough through names. Code completion users' typing of the
keyword leads to the corresponding code completion results being selected as well.
Keywords can be arbitrarily long and can be multiple.

For instance, a function called "index()" has "@keyword find" in its doc comment.
Users' typing of "find" leads to "index()" being selected in the code completion list.
2015-11-05 15:36:55 -08:00
Xi Ge
71485b318c Check if type exists before retrieving it. rdar://22871737 2015-11-04 11:47:46 -08:00
Ben Langmuir
1992bb08b2 [CodeCompletion] Add keyword kind to code completion results
This lets us reliably distinguish keywords we care about without
resorting to string comparisons.  Also driveby fix throw to be a
statement keyword.
2015-11-02 13:27:34 -08:00
Ben Langmuir
a2994d58c9 [CodeCompletion] Don't add decl and stmt keywords to expressions
With special cases for let, var and case, since we don't differentiate
places that could be the start of a pattern from expressions yet.
2015-11-02 13:27:34 -08:00
Ben Langmuir
04138e2cd0 [CodeCompletion] Add a new StmtOrExpr code completion kind
We want to distinguish keywords that are only valid at
statement/declaration context from those valid in any expression.
2015-11-02 13:27:34 -08:00
Ben Langmuir
4082355244 Split KnownProtocolKind enum case from protocol name
This avoids us using reserved identifiers as the enum case names of all
our underscored protocols like _ObjectiveCBridgeable. I used the
convention PROTOCOL_WITH_NAME to mirror how the known identifiers work.

Swift SVN r32924
2015-10-27 23:10:36 +00:00
Ben Langmuir
67563a1667 Remove use of reserved identifier from r32906
Swift SVN r32910
2015-10-27 16:50:35 +00:00
Ben Langmuir
54a28a40db [CodeCompletion] Split literals out into their own completion kind
For rdar://problem/21923069

Swift SVN r32906
2015-10-27 13:34:54 +00:00
Xi Ge
6c983366cc [CodeComplete] Show #available completion only in guard and if statements. rdar://23228191
Swift SVN r32893
2015-10-26 20:54:00 +00:00
Ben Langmuir
880ef5e9fd [CodeCompletion] Add _ColorLiteralConvertible completion
For rdar://problem/21923069

Swift SVN r32891
2015-10-26 20:41:57 +00:00
Ben Langmuir
7fda8964db [CodeCompletion] Add several more literal completions
Go beyond the existing keyword completions to include more literal
suggestions: 0, 0.0, "text", [item], [key: value], (item, item)

For rdar://problem/21923069

Swift SVN r32890
2015-10-26 20:41:56 +00:00
Ben Langmuir
ba7db29113 [CodeCompletion] Add type relation to literals
So that e.g. `true` gets prioritizied in
    let x: Bool = <complete-here>

For rdar://problem/21923069

Swift SVN r32889
2015-10-26 20:41:55 +00:00
Ben Langmuir
7d6d7c370c [CodeCompletion] Substitute the real type name if it matches an expected type
We now show the 'nil' completion with Int? in
let x: Int? = <complete-here>

For rdar://problem/21923069

Swift SVN r32888
2015-10-26 20:41:54 +00:00
Ben Langmuir
58bd3e734d [CodeCompletion] Stub in value/literal suggestions
For now just move the existing true/false/nil completions. No
type-relations yet.

For rdar://problem/21923069

Swift SVN r32887
2015-10-26 20:41:53 +00:00
Xi Ge
0f881f5ad7 [CodeComplete] Add code completion for Clang sub-modules at import decls. rdar://23244877
e.g. completing at "import Foundation.<HERE>" should give the list of the submodules of Foundation.

Swift SVN r32852
2015-10-24 00:22:25 +00:00
Xi Ge
afe90ff3c2 [CodeComplete] Suggested by Ben, deliver #available completion after # token and add placeholder to represent platform names.
Swift SVN r32847
2015-10-23 19:49:57 +00:00
Ben Langmuir
889b033964 [CodeCompletion] Add completion for property overrides
This mostly works the same as for functions. It required a slight tweak
to how we handle 'var <complete>' to avoid consuming the code completion
token prematurely.

rdar://problem/21012767

Swift SVN r32844
2015-10-23 05:38:07 +00:00
Ben Langmuir
51495c833c [CodeCompletion] Factor override decl printing into separate method NFC
Swift SVN r32843
2015-10-23 05:38:04 +00:00
Xi Ge
17ad7f702e [CodeComplete] Show #available in the list of keywords. rdar://23039417
Swift SVN r32835
2015-10-22 23:14:09 +00:00
Ben Langmuir
19c8680b81 [CodeCompletion] Complete optional tuple members
We weren't suggesting the tuple members, only the Optional members.

rdar://problem/22746820

Swift SVN r32833
2015-10-22 22:43:24 +00:00
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