Commit Graph

212 Commits

Author SHA1 Message Date
danra
6ea2bfcac9 Remove C-style for loop example comment
Remove C-style for loop example from the comment demonstrating the ExpressionSpecific code completion context; C-style have been deprecated and will be removed.
2016-04-01 02:40:49 +03:00
danra
71f354e151 Cosmetic fixes (NFC)
- Minor comment fixes
- Split line longer than 80 chars
- Apply conventional header ifdef guard name convention
2016-03-31 21:45:22 +03:00
Xi Ge
c452f9640f [CodeCompletion] Add a field NotRecommendedReason to code completion result to indicate why an item is not recommended, NFC. rdar://25415947
As implied in rdar://24818863, striking through a module name may be an overkill to suggest the module is redundant to import. We try to
fine-grain not-recommended-reason so that proper UI cue can be adopted in the future.
2016-03-30 16:23:33 -07:00
Ben Langmuir
8f9299cc97 [CodeCompletion] Add assignment to experimental operator completion
When the LHS is an lvalue/assignable tuple and there is no leading
sequence of binary expressions.

It's a bit hacky right now since we don't have a good way to
differentiate general pattern completions from builtin operators.

rdar://problem/23209683
2016-03-02 18:21:37 -08:00
Jordan Rose
66189ffac9 Convert many more classes to use llvm::TrailingObjects.
I only intend to do SIL instructions after this; I'm leaving the runtime alone.
2016-02-09 08:57:19 -08:00
Chris Lattner
8dedfb31e3 Add support for #file/#line, etc according to SE-0028. __FILE__ and friends
are still accepted without deprecation warning as of this patch.
2016-02-04 14:22:22 -08:00
Ben Langmuir
a927dc8a5a [CodeCompletion] Hide literals that don't match the type context in SourceKit
If there is a type context, hide literal suggesetions that don't match
it, unless they are keywords and we have filtered to their names.

Incidentally fix an output buffering issue when combining filtering with
the -raw flag in complete-test.

Part of rdar://problem/23865118
2016-02-03 10:51:07 -08:00
Ben Langmuir
9ae6846ac7 [CodeCompletion] Remove more vestiges of 0.0 literal suggestion
Obviously dead code.
2016-02-03 08:29:20 -08:00
Ben Langmuir
e75402e49e [CodeCompletion] Add image literal similar to color
Part of rdar://problem/23865118
2016-02-03 07:55:07 -08:00
Ben Langmuir
d16e4b0467 [CodeCompletion] Add rudimentary support for configuring allowable completions
On a per-request basis. Allows hiding/showing at multiple granularities
* everything
* module
* API by name
* keywords (by uid or all of them)
* literals (by uid or all of them)

With more specific rules overriding less specific ones (so you can hide
everything and then selectively show certain API for example).

rdar://24170060
2016-01-25 08:45:48 -08:00
practicalswift
a3f857ca7b [gardening] Add "-*- C++ -*-" to header files currently missing it 2016-01-23 11:53:05 +01:00
Xi Ge
0f4e7a5ea5 [CodeCompletion] Add code completion for where clauses. rdar://24245022
When completing at "extension A where #^HERE^#", we suggest the generic params of A to users.
2016-01-19 14:17:15 -08:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
149b50d901 Fix typos in code (non-comment/documentation typos). 2015-12-28 11:42:15 +01:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
practicalswift
c75590d6c5 Fix typo: implementetion → implementation 2015-12-14 00:11:53 +01: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
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
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
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
Ben Langmuir
20bcd65cd7 [CodeCompletion] Remove now-incorrect assertion
Swift SVN r32894
2015-10-26 21:05:49 +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
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
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
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
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
6dd6fff440 [CodeComplete] Rename ExpectedTypeRelation:Undetermined to ExpectedTypeRelation::Unrelated.
Swift SVN r31844
2015-09-10 01:50:04 +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
71953ddc7a [CodeComplete] Add a new decl kind for module and update the code completion results of import decl to belong to this kind.
This allows Xcode to add special icons for completing module names.

Swift SVN r31109
2015-08-10 18:20:57 +00:00
Ben Langmuir
c011b9f54c Add method to get first chunk in code completion string with punctuation
The client may or may not want to include the leading punctuation in a
result e.g. in "?.foo()".

Swift SVN r31013
2015-08-04 22:13:25 +00:00
Ben Langmuir
f777b59336 Remove unnecessary 'const' from CodeCompletionString
The code completion string is already immutable (outside of the builder
object), so be less annoying about using it.

Swift SVN r30737
2015-07-29 00:06:22 +00:00
Ben Langmuir
7fcd0eeae5 [CodeCompletion] Add 'throws' and 'rethrows' to call descriptions
Completions for calling functions will now show 'throws' in the
description text so that users can differentiate throwing and
non-throwing calls. We don't insert this into the source text, since
it's not part of the call syntax.

rdar://problem/20978869

Swift SVN r28791
2015-05-19 21:46:20 +00:00
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Ben Langmuir
3a9020fae4 Add an on-disk code completion cache
When we miss the in-memory (libcache-based) code completion cache, we
can now chain to an on-disk code completion cache. This drastically
improves the time and peak memory usage it takes to do the first code
completion (ie. before the in-memory cache is warm) if we've done the
same lookup before.

The on-disk cache, like the in-memory cache is tied to the specific
compiled swift and clang module files (.swiftmodule and .pcm), and will
consider itself out of date if they are modified. Responsibility for
deleting completely dead/unreachable cache files falls to the client.

Most of this commit is adding a simple serialization and deserialization
for CodeCompletionResults and CodeCompletionStrings.  The format is very
simple, using an array of fixed size CodeCompletionResults, with offsets
into two blobs: one for CodeCompletionString::Chunks, and one for
strings.  Currently that gives us about 5.8 MB for all the results in
Cocoa, but it's very compressible if we decide we want to reduce it
(gzip'd it is ~1.2 MB for the same data).

Swift SVN r28369
2015-05-09 19:32:37 +00:00
Ben Langmuir
59533a1973 Split off CodeCompletionCache into its own file
Swift SVN r28367
2015-05-09 19:03:22 +00:00
Ben Langmuir
f3ecb63f30 Move caching logic into the code completion consumer
This will let us implement caching in the client (e.g. SourceKit) at
some point and simplifies adding more levels of caching. Requires a
corresponding SourceKit change.

Swift SVN r28365
2015-05-09 18:51:30 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Ben Langmuir
e603126dc0 Factor out copying code completion results from one sink to another
We'll need to be able to do this in the client once we expose caching.

Swift SVN r28176
2015-05-05 19:02:17 +00:00
Ben Langmuir
c40100af66 Factor use of the CodeCompletion sys::Cache into get() and set() methods
Now get() and set() manage determining whether the results are stale,
and getResults() can just rely on that.

Also drive-by fix a data race where we were inserting our results sink
into the cache before it was finished being modified.

Swift SVN r28175
2015-05-05 19:02:16 +00:00
Ben Langmuir
563cd0acf0 Lift the code completion cache interface into the header
The only part that's hidden is the sys::Cache itself now.

Swift SVN r28174
2015-05-05 19:02:15 +00:00
Ben Langmuir
e39fb7224e Expose a libIDE function to lookup the completions for a module
We'll need this in order to move code completion result caching into the
client.

Swift SVN r28173
2015-05-05 19:02:13 +00:00
Ben Langmuir
fc53b6e355 [CodeCompletion] Expose some result creation APIs for SourceKit
We want to be able to synthesize new results inside SourceKit. At this
point, the simplest way to do that is to expose the constructors for
CodeCompletionResult and a create() function for CodeCompletionString.

The expectation that any strings are stored properly inside a
CodeCompletionResultSink is documented.

Swift SVN r27822
2015-04-27 22:27:48 +00:00