Commit Graph

293 Commits

Author SHA1 Message Date
Rintaro Ishizaki
7086ffb79f [CodeCompletion] Annotated result type
Introduced 'TypeAnnotationBegin' chunk kind for grouping the result type
name chunks.

rdar://problem/62617558
2020-05-11 22:56:22 -07:00
Rintaro Ishizaki
f80fdfca83 [CodeCompletion] Simplify a FileCheck test
Only check lines we really care about.
2020-05-11 14:48:28 -07:00
Rintaro Ishizaki
75a0c9f819 [CodeCompletion] Add 'IsSystem' flag to code completion result item
'key.is_system: 1' is added if the associated declaration is from a
system module.

rdar://problem/62617558
2020-05-11 12:24:36 -07:00
Ben Langmuir
37b98af4e6 [CodeCompletion] Pre-expand closures in argument completion
When completing a single argument for a trailing closure, pre-expand the
closure expression syntax instead of using a placeholder. It's not valid
to pass a non-closure anyway.

rdar://62189182
2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
71f4cfc68c Merge pull request #31474 from rintaro/sourcekit-completion-invalidtyperelation-rdar57726512
[CodeCompletion] Dont mark type mismatching items 'not recommended'
2020-05-05 13:14:51 -07:00
Rintaro Ishizaki
e9c438cdd5 [CodeCompletion] Dont mark type mismatching items 'not recommended'
func foo() {}
let a: Int = #^HERE^#

Previously, we marked 'foo()' as 'NotRecommented' because 'Void' doesn't
have any member hence it cannot be 'Int'. But it wass confusing with
'deprecated'.

Now that we output 'typerelation' which is 'invalid' in this case. So clients
can deprioritize results, or even filter them out.

rdar://problem/57726512
2020-05-05 10:40:05 -07:00
Rintaro Ishizaki
af5daed144 [CodeCompletion] Tweak fast completion dependency checking
- Detect same file with bufferID instead of the file name
- Compare virtual in-memory filesystem content with hash value
2020-05-04 16:35:41 -07:00
Rintaro Ishizaki
e32de789ff [Tests] Mark check dependency tests cases 'REQUIRES: shell'
These test cases use shell variables etc.
2020-05-04 13:02:09 -07:00
Rintaro Ishizaki
df8fa09d8e [CodeCompletion] Added check dependency test for complete.open 2020-05-04 13:02:09 -07:00
Rintaro Ishizaki
05a87e86c4 [CodeCompletion] Give up fast-completion if dependent files are modified
Check if dependencies are modified since the last checking.
Dependencies:

 - Other source files in the current module
 - Dependent files collected by the dependency tracker

When:

 - If the last dependency check was over N (defaults to 5) seconds ago

Invalidate if:

 - The dependency file is missing
 - The modification time of the dependecy is greater than the last check
 - If the modification time is zero, compare the content using the file
   system from the previous completion and the current completion

rdar://problem/62336432
2020-05-04 13:02:09 -07:00
Rintaro Ishizaki
e947512875 [CodeCompletion] Prioritize type matching overload for unresovled member
For exmaple:

    func foo(_: Int, _: IntOption)
    func foo(_: Float, _: FloatOption)

    foo(intVal, .<HERE>)

Previously code completion suggests static member from 'IntOption' and
'FloatOption' without any prioritization. Prioritize members from
'IntOption' because the user probably wants to input them.

In such cases, 'CodeCompletionExpr' at the cursor position is
pre-typechecked to 'IntOption'. So mark results with matching type with
'ExprSpecific'.

rdar://problem/62121221
2020-04-24 18:01:59 -07:00
Rintaro Ishizaki
a5fa431af4 Merge pull request #30890 from rintaro/sourcekit-test-diff
[SourceKit/Testing] Add %diff as an alias for 'diff --strip-trailing-cr'
2020-04-08 19:44:28 -07:00
Rintaro Ishizaki
aee280ad65 [SourceKit/Testing] Add %diff as an alias for 'diff --strip-trailing-cr' 2020-04-08 11:23:48 -07:00
Rintaro Ishizaki
496c303ab5 Merge pull request #30865 from rintaro/sourcekit-completion-rdar61367416
[SourceKit] Don't use diagnostics to indicate fast-completion
2020-04-07 17:58:19 -07:00
Rintaro Ishizaki
4870d1c017 [SourceKit] Don't use diagnostics to indicate fast-completion
Add 'key.reusingastcontext: 1' to the response instead.
Using diagnostics can be a noise to indexing log clients.

rdar://problem/61367416
2020-04-07 16:26:00 -07:00
Rintaro Ishizaki
837fa0d250 [CodeCompletion] Use --strip-trailing-cr for diff test 2020-04-07 13:15:41 -07:00
Rintaro Ishizaki
28de43b7ca [CodeCompletion] Trim whitespaces around the content 2020-04-07 00:50:43 -07:00
Rintaro Ishizaki
773a464e83 [CodeCompletion] Add an option to emit annotated description 2020-04-07 00:46:14 -07:00
Rintaro Ishizaki
49d72d77d1 Merge pull request #30653 from rintaro/sourcekit-completion-optionalsort-rdar60799439
[SourceKit] Add an option to sort completion result
2020-03-27 09:26:56 -07:00
Rintaro Ishizaki
429467288e [SourceKit] Add an option to sort completion result
Defaults to false

rdar://problem/60799439
2020-03-26 17:39:36 -07:00
Rintaro Ishizaki
7b7599a28d [CodeCompletion] Don't run second pass for decls in closures
For instance:
--
let globalVar = {
    func something(arg: Int) -> Int {
        #^HERE^#
    }
    return something(12)
}()
--
We want to consider this as a top-level completion, not a function body
completion.

rdar://problem/60838686
2020-03-26 00:42:39 -07:00
Rintaro Ishizaki
d0d17114b7 [SourceKit] Disable Windows testing for build_session test cases 2020-03-24 15:29:16 -07:00
Rintaro Ishizaki
22f048e637 [SourceKit] Save clang module validation time
Pass '-fbuild-session-timestamp' and '-fmodules-validate-once-per-build-sessio'
to ClangImporter so that module validation happens only once for the
SourceKit lifetime.

rdar://problem/59567281
2020-03-24 13:38:57 -07:00
Argyrios Kyrtzidis
4d337f2db2 [SourceKit] Turn-on by default the fast completion mode
rdar://59830963
2020-02-26 18:16:07 -08:00
Rintaro Ishizaki
0a0cde92a4 [CodeCompletion] Fast completion for top-level code in single file script
e.g. Playground.
A single file script is like a single function body; the interface of
the file does not affect any other files.
So when a completion happens in a single file script, re-parse the whole
file. But we are still be able to reuse imported modules.

rdar://problem/58378157
2020-02-25 15:56:28 -08:00
Rintaro Ishizaki
63772d04a8 Merge pull request #29789 from rintaro/ide-completion-rdar58851121
[CodeCompletion] Enable fast-completion at the top of implicit getter
2020-02-13 10:34:57 -08:00
Rintaro Ishizaki
ff2ccd485c [CodeCompletion] Workaround fast-completion issue in UnqualifiedLookup
In fast-completion, a function body can be replaced with another function
body parsed from a new buffer. In such cases, during typechecking the
expressions in the *new* function body, a source location range check in
UnqualifiedLookup didn't work well because they are not from the same
buffer.

This patch workaround it by skipping the source range checks and returns
'success' in such cases.

rdar://problem/58881999
2020-02-12 10:41:43 -08:00
Rintaro Ishizaki
7b4db904a1 [CodeCompletion] Complete at the top of accessor block in body parsing
If a CC token is right after the '{' we still don't know it's an implicit
getter or a start of a accessor block. Previously, the parser used to
parse it as an accessor block, but it prevents fast-completion kicks in.

Instead handle it as a part of function body parsing so the
fast-completion works.

rdar://problem/58851121
2020-02-12 10:19:18 -08:00
Saleem Abdulrasool
ced1c2b3d1 test: repair the SourceKit test for Windows (NFC)
Ignore the line ending as in the rest of the SourceKit tests.
2020-02-09 11:13:56 -08:00
Rintaro Ishizaki
cc8d4965f8 [CodeCompletion] Ensure cached results have 'unknown' type relation 2020-02-05 17:05:23 -08:00
Rintaro Ishizaki
e9c51a0755 [CodeCompletion] Report 'Unrelated' type relation for keywords 2020-02-05 15:09:14 -08:00
Rintaro Ishizaki
c31bfaeeed [CodeCompletion] Introduce 'Unknown' type relation
Now

* NotApplicable: The result is not relevant for type relation (e.g.
  keywords, and overloads)
* Unknown: the relation was not calculated (e.g. cached results), or the
  context type is unknown.
* Invalid: The result type is invalid for this context (i.e. 'Void' for
  non-'Void' context)
* Unrelated: The result type has no relation to the context type
* Convertible: The result type is convertible to the context type
* Identical: The result type is identical to the context type
2020-02-05 14:23:59 -08:00
Rintaro Ishizaki
17abedf1ef [CodeCompletion] Introduce 'NotApplicable' type relation
For keywords, and overrides.
2020-02-05 14:23:59 -08:00
Rintaro Ishizaki
7d498b1d81 [SourceKit] Add test cases for type relation in code completion 2020-02-03 17:45:22 -08:00
Rintaro Ishizaki
71aeffdf17 [CodeCompletion] Calculate type relation for EnumElementDecl 2020-02-03 17:20:50 -08:00
Rintaro Ishizaki
1e74c39956 [SourceKit] Expose ExpectedTypeRelation for the completion results
So that clients can sort the results using this.

rdar://problem/59066560
2020-02-03 15:57:43 -08:00
Rintaro Ishizaki
7b4466f400 [CodeCompletion] Ignore implicit decl when finding equivalent decl
TypeChecker sometimes (e.g. property wrappers) inserts implicit decls
(e.g. 'PatternBindingDecl's and 'VarDecl's) between decls in the AST.
This used to confuse 'getEquivalentDeclContextFromSourceFile()'. It
canceled fast-completion, caused crashes, or completed in a wrong
context.

Ignore implicit decls in the AST so that we can find the correct decl
context.

rdar://problem/58665268
2020-01-22 22:28:33 -08:00
Ben Langmuir
0b93a247c6 [test] Remove now-redundant %mcp_opt from sourcekit tests
Remove `%mcp_opt` from commands that use `%sourcekitd-test` and
`%complete-test`, as they are now redundant with the lit substitution.
2020-01-22 11:12:25 -08:00
Rintaro Ishizaki
9eeb96c5ba [CodeCompletion] Handle cases where PersistentParserState is not created
For example, if stdlib is not found, CompilerInstance simply returns
before creating PersistentParserState. In such cases, completion should
just return empty result.

Previously, it caused SourceKit crash.

rdar://problem/58663066
2020-01-17 00:10:50 -08:00
Rintaro Ishizaki
13e865c11c Merge pull request #29245 from rintaro/ide-completion-fastaccessor-rdar58632889
[CodeCompletion] Enable fast completion within accessors
2020-01-16 09:08:12 -08:00
Rintaro Ishizaki
3018b55914 [CodeCompletion] Enable fast completion within accessors
'getEquivalentDeclContextFromSourceFile()' didn't work for accessors
because DeclContext hierarchy and AST hierarhy are not the same.

AST hierarchy:
    (TypeDecl or SourceFile) > AbstractStorageDecl > AccessorDecl
DeclContext hierarchy:
    (TypeDecl or SourceFile) > AccessorDecl

Handle them specially.

rdar://problem/58632889
2020-01-15 21:33:49 -08:00
Saleem Abdulrasool
2265d6e891 tests: adjust the SourceKit tests for line endings (NFCI)
This adjusts the tests for the difference between line endings on
different platforms.  Windows uses CRLF while most Unicies use LF.  This
was exposed during the update to the new LLVM snapshot.
2020-01-14 08:05:34 -08:00
Rintaro Ishizaki
7bb01ed271 Merge pull request #28896 from rintaro/ide-completion-rdar58098222
[CodeCompletion] Always look into decls to find the parsed expression
2020-01-13 16:48:34 -08:00
Rintaro Ishizaki
046c9148ec [CodeCompletion] Use getBodySourceRange() instead of getSourceRange()
To check if the completion is happening in the AFD body.
Otherwise, local variables are sometimes not suggested because the body
and its range is from another file.

rdar://problem/58175106
2020-01-02 12:18:47 -08:00
Rintaro Ishizaki
a7064617b2 [CodeCompletion] Always look into decls to find the parsed expression
In fast completion scenario, 'AbstractFunctionDecl' may have the body
from the different file than the decl itself. Thay may confuses source
range checking.

As a workaround, always look into decls regardless of the range. This
should not regress the speed of the searching much because
statements/expressions (including nested function bodies) in the decl
is still skipped if it's outside the range.

rdar://problem/58098222
2019-12-19 21:50:08 -08:00
Rintaro Ishizaki
2aec5d4d28 [CodeCompletionn] Block completions in other threads
if fast-completion is enabled. So they have higher chance to use the cached
completion instance.
If it's disabled, don't block, use an ephemeral instance so we can peform
multiple completions simultaneously.
2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
044477e7a3 [SourceKit/CodeCompletion] Use callback function to run the second pass
To controls the lifetime of CompilerInstance within CompletionIntance.

- Prevent from using the same CompilerInstance from multiple completion
  requests
- Separate the stacktrace between "fast" and "normal" completions
- Further code consolidation between various completion-like requests
2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
fcb50d6354 [SourceKit] Add more test cases for fast completions 2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
2160134dc3 [SourceKit] Add test file for fast completion 2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
3e1de28c85 [complete-test] Stop inserting \0 in complete-test
Using \0 as a representation of the cursor position is a implementation
detail and is done by SourceKit. Client including complete-test should
not do it.

This inserted test used to be treated as EOF in compiler so the code
after the completion position is completely ignored.
2019-11-21 14:14:22 +09:00