Commit Graph

212 Commits

Author SHA1 Message Date
Ben Langmuir
ece29ccfa4 Add a module name field to code completion results
For decls, we get the most specific submodule from clang modules.  For
macros, we don't yet have a way to get this information, since the
mapping from module ID to submodule is burried in the ClangImporter.
Having submodule information for macros would also help reduce the space
cost of storing the module names, since we would hit the single-element
module name cache more often.

There is no special handling of imported headers, which currently come
through with their internal clang module name '__ObjC'.  Possibly these
should be treated as part of the current module.

A future commit will add the module name to swift-ide-test's output and update
the tests.

Swift SVN r26260
2015-03-18 16:14:11 +00:00
Argyrios Kyrtzidis
ed9f34fc16 [IDE] Add some helper functions in CodeCompletionString::Chunk, NFC.
Swift SVN r26254
2015-03-18 08:35:08 +00:00
Xi Ge
566e54a81c [CodeCompletion] Supporting auto-completion of declaration attribute keywords. When a
developer inputs @, the code completion engine recommends built-in attributes.

Swift SVN r25785
2015-03-05 19:35:27 +00:00
Xi Ge
e71588a414 [CodeCompletion] The second step to complete @availability. Adding the second
or the later parameters in this attribute. rdar://19541135

Swift SVN r25762
2015-03-04 20:55:30 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Dmitri Hrybenko
6a5f59831b Code completion: include access control keywords in override completion
When trying to implement deduplication of results, found and fixed an issue
with loose checks for generic overload checking.

rdar://17995317


Swift SVN r21276
2014-08-19 11:00:10 +00:00
Sonny Falk
64e5c0b6a6 [IDE/CodeComplete] Add associated USRs to CodeCompletionResult.
If the completion result is a declaration, it contains the USR of the specified declaration and all overridden declarations.

Additional tests on SourceKit side.

This addresses <rdar://problem/17600891>.

Swift SVN r20877
2014-08-01 02:21:02 +00:00
Sonny Falk
efa1ff8ab4 [IDE/CodeComplete] Add CallParameterClosureType chunk, which resolves
optional & alias types for closure type parameters.

This allows code completion placeholder expansion to properly expand
closure parameters utilizing a typealias, e.g. dispatch_block_t.

Update and add test for the above.

Work for <rdar://problem/15860693>.

Swift SVN r20206
2014-07-19 03:18:29 +00:00
Dmitri Hrybenko
3f4436a272 Code completion: add simplistic support for keywords
rdar://15992120


Swift SVN r20082
2014-07-17 12:02:21 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Ben Langmuir
b31a6d125d Preserve vararg... syntax in code completions
Int... should now be shown as Int... rather than [Int].

Swift SVN r19464
2014-07-02 15:05:59 +00:00
Dmitri Hrybenko
b0eb481bff Code completion: display correct syntax and type when using an @optional member
on a value


Swift SVN r18742
2014-06-09 13:06:18 +00:00
Dmitri Hrybenko
69b12ea388 Code completion: update comments
Swift SVN r18405
2014-05-19 08:49:39 +00:00
Sonny Falk
a2680240c0 [IDE/CodeCompletion] Teach code completion to display the local parameter name
if there's no parameter API name. This is for display purposes only.
Update all relevant tests accordingly.
This addresses <rdar://problem/16768768>.

For example:
  class X {
    func f(a: Int, b: Int) { }
  }

Would previously display like this in code completion in Xcode:
  f(<#Int#>, b: <#Int#>)

The local parameter name, while not API, often still conveys meaning
to the user. So it's now included like this:
  f(<#a: Int#>, b: <#Int#>)

Swift SVN r18403
2014-05-19 08:31:10 +00:00
Dmitri Hrybenko
88dde39473 Code completion: fix use-after-free
A use-after-free could happen in the following scenario:

- code completion caches results from module A;
- code completion returns cached results -- result set 1;
- module is rebuilt;
- another code completion request arrives, cache is invalidated and re-filled.
  Old results are freed, even though someone could be still using the result
  set.

rdar://16953614


Swift SVN r18329
2014-05-18 16:55:45 +00:00
Sonny Falk
a19a0d1133 [IDE] Make CodeCompletionContext::sortCompletionResults() sort by full name.
This addresses <rdar://problem/16877804>.

Swift SVN r17991
2014-05-13 02:38:48 +00:00
Argyrios Kyrtzidis
a0fa68b072 [IDE/CodeCompletion] Expose the getFirstTextChunk() function via a CodeCompletionString method.
Swift SVN r17388
2014-05-04 17:30:07 +00:00
Argyrios Kyrtzidis
5f24181015 [IDE/CodeComplete] Create a separate chunk for the 'override' keyword.
Swift SVN r17387
2014-05-04 17:29:59 +00:00
Argyrios Kyrtzidis
1a7e6485f4 [IDE/CodeCompletion] For override completions, separate the introducer keywords like "override func" in
a new chunk kind, so that we can sort/filter based on the name of the function.

Swift SVN r17369
2014-05-04 07:20:57 +00:00
Dmitri Hrybenko
0cb8ddd213 Code completion for overrides: use a special chunk BraceStmtWithCursor for
braces

This allows clients to process it in a special way, for example, to indent the
resulting code.


Swift SVN r16884
2014-04-26 17:52:16 +00:00
Dmitri Hrybenko
e36baf4123 Code completion: add basic support for completing overriding decls
rdar://16539292


Swift SVN r16755
2014-04-24 15:59:05 +00:00
Argyrios Kyrtzidis
2b25af65ff [IDE/CodeComplete] Reduce 'MaxNumBytesToErase' in code-completion result to 127.
It saves some space downstream in SourceKit.

Swift SVN r16689
2014-04-23 06:25:59 +00:00
Argyrios Kyrtzidis
9bd10774b0 [IDE/CodeCompletion] Mark a code-completion result as 'not-recommended' if the declaration
that it refers to is unavailable.

rdar://16675550

Swift SVN r16687
2014-04-23 04:26:14 +00:00
Dmitri Hrybenko
236c581de7 Code completion: complete "?.member" on T?, and ".member" on @unchecked T?
In order for Xcode to use these completions, we complete "?.member" when the
user has typed "anOptional.", but we also say that in order to apply this
result, N bytes to the left of the cursor should be erased first.

rdar://16579657 rdar://15233283


Swift SVN r16409
2014-04-16 10:50:14 +00:00
Dmitri Hrybenko
0aeb095416 Code completion: change the spelling of DynamicLookupMethodCallTail chunk to "!"
This is the "!" in method calls on AnyObject:

  var a: AnyObject = get()
  a.doFoo!()

rdar://15233283


Swift SVN r16366
2014-04-15 09:36:50 +00:00
Dmitri Hrybenko
efa2f3b896 Code completion: add brief comments to code completion results
Swift SVN r15059
2014-03-14 17:53:22 +00:00
Dmitri Hrybenko
06be7781f8 Fix code completion for 'inout' by completing '&' in the function argument
Partially addresses rdar://15999689


Swift SVN r14299
2014-02-24 12:48:56 +00:00
Argyrios Kyrtzidis
408cff5dea [IDE] Make CodeCompletionResult::getCodeCompletionDeclKind() public.
Swift SVN r12475
2014-01-17 07:33:50 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Dmitri Hrybenko
fb08372e10 Code completion tests: check declaration kind, it is computed with non-trivial logic now
These tests revealed this bug: rdar://15353073


Swift SVN r9800
2013-10-30 18:05:55 +00:00
Dmitri Hrybenko
a927afa412 Remove unused #includes
Swift SVN r9662
2013-10-24 22:54:34 +00:00
Dmitri Hrybenko
0cafcee4c0 Code completion: add more assertions
Swift SVN r9659
2013-10-24 22:20:05 +00:00
Dmitri Hrybenko
b7d3a23518 Code completion result cache: use libcache
Swift SVN r9653
2013-10-24 20:59:28 +00:00
Argyrios Kyrtzidis
d64313d169 [IDE] Use a switch to convert to CodeCompletionDeclKind, to make sure we cover every decl kind.
Also add the GenericTypeParam for kind.

Swift SVN r9640
2013-10-24 17:47:26 +00:00
Argyrios Kyrtzidis
881e646632 [IDE] Introduce CodeCompletionDeclKind enum to encapsulate a bit more info than the DeclKind (e.g. whether the function is an instance/static method).
Swift SVN r9635
2013-10-24 04:33:51 +00:00
Dmitri Hrybenko
8d8b60f973 Code completion: implement result caching per-imported module across muptiple
ASTContexts

This introduces swift::ide::CodeCompletionCache, which is a persistent code
completion result cache.

Right now REPL happens to use it (try importing Cocoa and doing code
completion), and the difference is noticeable.  But completion in REPL is
still slow, because Cocoa goes through the AST Verifier on every completion
(for unknown reasons).

This commit does not implement cache invalidation yet, and it does not use
libcache to evict cache entries under memory pressure.

This commit also introduces two regressions:
- We get fewer Cocoa results that expected.  Module::isModuleVisible in Clang
does not incorrectly reports that that ObjectiveC.NSObject submodule is not
visible from Cocoa.

- We are not implementing the decl hiding rules correctly.  We used to rely on
visible decl lookup to do it for us, but now we have a different data structure
we have real decls from the current module and we have a text-only cache, so we
are forced to reimplement this part of name lookup in code completion.


Swift SVN r9633
2013-10-24 02:13:34 +00:00
Dmitri Hrybenko
4ce90a83a9 Code completion: move result builder to a private header
Swift SVN r9485
2013-10-18 18:13:23 +00:00
Dmitri Hrybenko
4e29c56cdd Code completion: don't copy static strings into a separate allocator
Swift SVN r9484
2013-10-18 18:04:41 +00:00
Dmitri Hrybenko
0f93a9277d Code completion: complete '!' and '?' on Optional<T>
rdar://14848266


Swift SVN r9377
2013-10-15 21:36:42 +00:00
Doug Gregor
939f24aa12 Code completion: Generic parameter name chunks have text.
Swift SVN r9108
2013-10-09 23:16:41 +00:00
Doug Gregor
f7b84d4f41 Code completion: add chunks for <, >, and generic parameters.
Swift SVN r9107
2013-10-09 23:11:42 +00:00
Dmitri Hrybenko
6895c34741 Code completion: report "semantic context" for every code completion result
Semantic context describes the origin of the declaration and serves the same
purpose as opaque numeric "priority" in Clang -- to determine the most likely
completion.

This is the initial implementation.  There are a few opportunities to bump the
priority of a certain decl by giving it SemanticContextKind::ExprSpecific
context that are not implemented yet.


Swift SVN r9052
2013-10-09 02:08:05 +00:00
Dmitri Hrybenko
6f4cb05603 Code completion: basic support for completing memebrs of DynamicLookup (id)
Only tested with functions (instance/class functions) declared in swift
classes.  Need more testcases.


Swift SVN r8800
2013-10-01 02:14:25 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Dmitri Hrybenko
2786c30dd8 Code completion: add a parser hook to inform code completion about generic
parameters while parsing the function signature.  Generic parameters are not
accessible at that time through the AST node, because the FuncDecl AST node was
not constructed yet.


Swift SVN r7222
2013-08-14 02:16:55 +00:00
Dmitri Hrybenko
a6519a907d Code completion: implement code completion for dot member access on clang modules
Because we don't want FooModule.#^A^# to show completion results for other
clang modules, global completion cache was replaced with a per-module cache.


Swift SVN r6951
2013-08-06 21:15:23 +00:00
Dmitri Hrybenko
99b626e8dd Fix indentation
Swift SVN r6844
2013-08-02 17:35:31 +00:00
Argyrios Kyrtzidis
df96177b36 [IDE] Add hasText() convenience method in the code-completion chunk.
Swift SVN r6839
2013-08-02 16:56:02 +00:00