Commit Graph

490 Commits

Author SHA1 Message Date
Xi Ge
5f8c122a79 [CodeComplete] Perform function name lookup to complete unresolved members.
For completing unresolved members, if constraint solver does not have solutions, we
look up the function names appearing in the same line of the code completion tokens,
and use their parameters that are of enum/optionset type to deliver the code
completion results.

Swift SVN r31256
2015-08-15 20:34:38 +00:00
Xi Ge
5a16d37dbf [CodeComplete] Address Ben's comments on r31063, r31083 and r31195.
Swift SVN r31254
2015-08-14 23:48:56 +00:00
Xi Ge
a450a08723 [CodeCompletion] Collect the identifiers appearing before unresolved members.
We can use these identifiers to perform manual look up.

Swift SVN r31250
2015-08-14 21:16:41 +00:00
Xi Ge
e55cdc1fb6 [CodeComplete] Avoid unnecessary walk path.
Swift SVN r31208
2015-08-13 05:36:37 +00:00
Xi Ge
0bab23961a [CodeComplete] Refine the code completion results for unresolved members by using constraint solver.
Before this commit, for unresolved members, code completion suggests all visible enum elements
 and option set types. To refine the results, this commit uses constraint solver to infer
the type of unresolved members by analyzing parental expressions. If the solver has solutions,
we complete the unresolved member, otherwise abort.
rdar://16659653

Swift SVN r31195
2015-08-13 00:19:58 +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
65cb6bc1bd [CodeCompletion] Don't show editor placeholders as completions
rdar://problem/21797815

Swift SVN r31089
2015-08-07 23:03:37 +00:00
Xi Ge
c260dc810c [CodeCompletion] Add visible option set type to the code completion results of unresolved members.
Swift SVN r31083
2015-08-07 20:28:09 +00:00
Xi Ge
0df10311a0 [CodeCompletion] Add the initial support for unresolved members.
This commit completes an unresolved member with all visible enum elements.
We need future work to reduce the list to those that are guaranteed to be
resolved under the current context.

Swift SVN r31063
2015-08-06 23:15:14 +00:00
Xi Ge
21e8a93761 [CodeCompletion] Add specific semantic context kind to 'super', 'self' and 'nil'.
This change gives these keywords a boost of priority when SourceKit sorts code completion
results.
rdar://21796980

Swift SVN r31037
2015-08-06 01:03:16 +00:00
Jordan Rose
0dbf9b2780 Add 'try?' (and 'try!') as statement-level completions.
Also, if 'else' is a statement-keyword, so is 'catch'.

More rdar://problem/21692467

Swift SVN r31033
2015-08-05 22:17:39 +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
Xi Ge
87018e516f [CodeCompletion] No crashing when function name is empty. rdar://21149908
Swift SVN r31011
2015-08-04 22:09:58 +00:00
Xi Ge
d7e07b1d4d [CodeCompletion] When code completing import decls, we only show the module names that are not yet imported in previous import decls.
Swift SVN r30964
2015-08-03 22:54:58 +00:00
Chris Willmore
7f12c9ffd5 [CodeCompletion] Add the initial support for code completing import declaration.
When a user invoke code completion after import keywords, the names of
visible top level clang modules were recommended for finishing the import decl.

(Undoing revert r30961 of r30957, which just required lockstep commit to
SourceKit -- cwillmore)

Swift SVN r30962
2015-08-03 21:08:32 +00:00
Chris Willmore
e4d1ac9c24 Revert "[CodeCompletion] Add the initial support for code completing import declaration."
This reverts r30957 because it broke the following tests on Jenkins:

    SourceKit :: CodeComplete/complete_open.swift
    SourceKit :: CodeComplete/complete_test.swift

<rdar://problem/22120345> swift-incremental-RA #8289 failed to build

Swift SVN r30961
2015-08-03 21:04:46 +00:00
Xi Ge
5e0014bcc4 [CodeCompletion] Add the initial support for code completing import declaration.
When a user invoke code completion after import keywords, the names of
visible top level clang modules were recommended for finishing the import decl.

Swift SVN r30957
2015-08-03 20:02:17 +00:00
Xi Ge
7b6b26a46d [CodeCompletion] Only filter out non-required inits for class type.
Swift SVN r30893
2015-08-01 00:05:03 +00:00
Xi Ge
29fcee3f0b [CodeCompletion] Show only required init() as members of dynamic metatype.
rdar://22074073

Swift SVN r30888
2015-07-31 22:49:55 +00:00
Xi Ge
c5ebe153d1 [CleanUp] Use DC as the abbreviation of DeclContext.
Swift SVN r30804
2015-07-30 17:16:28 +00:00
Xi Ge
5a1946eb53 [CodeCompletion] Add init() to the code completion results after metatype + dot.
rdar://21474100

Swift SVN r30781
2015-07-30 00:10:43 +00:00
Xi Ge
903bf976b2 Chop overly long lines.
Swift SVN r30780
2015-07-30 00:10:39 +00:00
Xi Ge
0743f07150 [CodeCompletion] Address Argyrios' and Ben's comments.
Swift SVN r30772
2015-07-29 18:01:40 +00:00
Xi Ge
32667fdbf9 [CodeCompletion] Add "super" keyword to code completion results when "super" is meaningful in the current decl context.
rdar://20401979

Swift SVN r30749
2015-07-29 01:37:23 +00:00
Xi Ge
3e9357a9bb [CodeCompletion] When completing init calls, stick to the type alias name given by the user instead of (smartly) showing the underlying type name. rdar://18586415
Swift SVN r30723
2015-07-28 20:45:12 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Xi Ge
c783def2f5 [CodeCompletion] Add code completion for platform names inside #available() condition.
The code for generating the code completion string reuses that of the @available attribute.
rdar://21467109

Swift SVN r30346
2015-07-18 00:10:37 +00:00
Dmitri Hrybenko
7ee84ed6b3 stdlib: rename Reflectable.{getMirror() -> _getMirror()}
Start removing the old mirrors.

rdar://21428474

Swift SVN r29823
2015-07-01 00:31:32 +00:00
Dmitri Hrybenko
ec9af44fe8 Adjust for new macro API in Clang
Swift SVN r29706
2015-06-25 22:01:45 +00:00
Ben Langmuir
1be2a778c1 [CodeCompletion] Avoid choking on a doubly-typechecked expr
First, fix a case of type checking an expression twice, which is against
the design of the type checker. We hit this because we can type check
the "context" in
  let x = foo.#^COMPLETE^#
and then type check the "parsed expression", which is contained in the
context here.

Second, make the hack from rdar://20738314 more robust so that if we
*do* double typecheck for some reason we won't just choke on an
AutoClosureExpr.  I filed rdar://21466394 to audit for other cases of
double typechecking and remove this hack.

Fixes rdar://21346928

Swift SVN r29527
2015-06-19 22:16:07 +00:00
Ben Langmuir
3f9ef14dab [CodeCompletion] Don't try to add enum cases with missing names
If a case has no name, just exit.  This avoids crashing when trying to
use the name.

Swift SVN r29030
2015-05-26 16:47:20 +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
Ben Langmuir
0d2fce4dd3 [CodeCompletion] Add throw/catch/try keywords to completions
We don't seem to be exhaustive about expression keywords.

Swift SVN r28719
2015-05-18 20:22:32 +00:00
Ben Langmuir
882959b60d [CodeCompletion] Remove incorrect special-casing for throw/catch
It's not okay to filter to only ErrorType results, since we may be
trying to chain to an error type result foo.bar.getError().  And the
existing logic had no way to handle results from other modules, so we
were missing key results like 'NSError'.

Eventually we'll want to bring back something like this that handles all
modules, but as a way to bump the priority of ErrorType results rather
than to filter out everything else.

rdar://problem/20985515

Swift SVN r28716
2015-05-18 19:00:04 +00:00
Ben Langmuir
0fbbe1807b [CodeCompletion] Fix crash completing method with associated type
protocol P { typealias T; func foo() -> T }
    func invalid(x: P) { x.#^COMPLETE^#

We were trying to access a null Type created because the associated type
doesn't make sense in the protocol type P (we can only use P as a
generic constraint, but it shouldn't crash code completion if we use it
incorrectly).

For rdar://problem/20305938

Swift SVN r28588
2015-05-14 22:46:59 +00:00
Ben Langmuir
69fdca43da Fix assertion failure code completing after nil literal
We were asserting (and doing the wrong thing) when trying to code
complete
    nil #^HERE^#

The issue is that we tried to apply a solution to the expression that
contained free type variables (converted to generic parameters). This
trips us up when we expect the new type to conform to protocols. In code
completion we generally only need the type of the expression, so this
commit switches to getting that more explicitly.  That said, this did
cause us to drop non-API parameter names in call patterns after an
opening '(' in some cases (covered by rdar://20962472).

Thanks to Doug for suggesting this solution!

rdar://problem/20891867

Swift SVN r28584
2015-05-14 22:22:37 +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
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
Doug Gregor
103526b771 Remove code completion's dependencies on getProtocols().
Swift SVN r27976
2015-04-30 16:13:43 +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
Doug Gregor
126e404fe5 Reimplement inference of type witnesses with a separate non-recursive pass.
Inference of type witnesses for associated types was previously
implemented as part of value witness matching in the constraint
solver. This led to a number of serious problems, including:
  - Recursion problems with the solver hunting for a type witness,
  which triggers more attemts to match value witnesses...
  - Arbitrarily crummy attempts to break the recursion causing
  type-check failures in fun places.
  - Ordering dependencies abound: different results depending on which
  value witnesses were satisfied first, failures because of the order
  in which we attempted to infer type witnesses, etc.

This new implementation of type witness inference uses a separate pass
that occurs whenever we're looking for any type witness, and solves
all of the type witnesses within a given conformance
simultaneously. We still look at potential value witnesses to infer
type witnesses, but we match them structurally, without invoking the
constraint solver.

There are a few caveats to this implementation:
  * We're not currently able to infer type witnesses from value
  witnesses that are global operators, so some tricks involving global
  operators (*cough* ~> *cough*) might require some manually-specified
  type witnesses. Note that the standard library doesn't include any
  such cases.

  * Yes, it's another kind of solver. At simple one, fortunately.

On the other hand, this implementation should be a big step forward:
  * It's far more predictable, order-invariant, and non-recursive.
  * The diagnostics for failures to infer type witnesses have
  improved.

Fixes rdar://problem/20598513.

Swift SVN r27616
2015-04-23 00:20:05 +00:00
Argyrios Kyrtzidis
5f6d091efc [AST] Keep track of the type decl that the type witness came from, for protocol conformances.
Swift SVN r27352
2015-04-16 06:23:54 +00:00
Ben Langmuir
f778836934 Add initializers to postfix-expr code completions
Previously, the only way to get initializers was completing after the
name of the type:
    Foo#^complete_here^#
    Foo(#^or_here^#

And now it will also work in unadorned expressions:
    #^a_top_level_completion^#
    bar(a, #^walked_into_a_bar^#

Unfortunately, not all our clients handle this well yet, so it's
protected by a language option.
    -code-complete-inits-in-postfix-expr

Swift SVN r27275
2015-04-14 14:54:08 +00:00
Ben Langmuir
70a93e0bfe Add code completion overload for defaulted arguments
When a call (func, method, initializer) has default arguments, produce
both the *with* and *without* default argument versions as if they were
overloaded.

rdar://problem/18573874

Swift SVN r27118
2015-04-08 02:41:20 +00:00