Commit Graph

212 Commits

Author SHA1 Message Date
Alex Hoppen
ee99666f91 [CodeComplete] Return result sink as code completion results
Previously the code completion methods just returned an `ArrayRef` that pointed into the result sink that contained the results but no effort was made to actually keep that that result sink alive, e.g. when transforming results in `transformAndForwardResults`.

Instead, return the `CodeCompletionResultSink` from the code compleiton methods now and adopt that sink from the inner results created in `transformAndForwardResults`.
2022-01-11 14:41:35 +01:00
Rintaro Ishizaki
2795a19ed6 Merge pull request #40163 from rintaro/ide-completion-enumbitfield
NFC: [CodeCompletion] Use enums in bit fields as-is
2021-12-21 09:40:00 -08:00
Ben Barham
65ef8020de [CodeComplete] Add option to add calls with no defaults (or not)
Now that arguments are marked up with whether they have a default or
not, clients may not need the extra call (that has no default
arguments). Add an option to allow not adding this item.

Resolves rdar://85526214.
2021-12-15 13:30:57 +10:00
Ben Barham
4187875ac6 [CodeComplete] Markup default arguments
Add `<callarg.default />` nodes to the annotated description of a
completion result for all arguments that have defaults.

Resolves rdar://85904660.
2021-12-15 13:30:57 +10:00
Rintaro Ishizaki
f8e10bbed4 [CodeCompletion] Add static_assert to limit the max values of enums 2021-12-03 15:33:28 -08:00
Rintaro Ishizaki
94a372e8ca [CodeCompletion] Use enums in bit fields as-is
We don't need to convert them from/to integer
2021-12-03 15:33:28 -08:00
Rintaro Ishizaki
73be942082 [CodeCompletion] NFC: Make enums in CodeCompletionResult scoped 2021-11-11 11:30:04 -08:00
Alex Hoppen
76f2dbe5e8 [swift-ide-test] Use dedicated method for code completion on CompletionInstance instead of generic performOperation 2021-10-28 11:10:30 +02:00
Alex Hoppen
163ccf9184 [SourceKit] Move invocation of code completion second pass for code completion from SoruceKit to CompletionInstance 2021-10-28 11:10:30 +02:00
Rintaro Ishizaki
afc24dfd4b [CodeCompletion] Remove two completion options from LangOptions
"add inits to toplevel" and "call pattern heuristics" are only used in
code completion. Move them from LangOptions to CodeCompletionContext so
that they don't affect compiler arguments.
2021-09-22 16:49:50 -07:00
Rintaro Ishizaki
1656eed597 Revert "[CodeCompletion] Provide known module source file information"
This effectively reverts commit f8751d466e.
2021-09-22 10:06:19 -07:00
Rintaro Ishizaki
bd5b3012f4 Merge pull request #38453 from rintaro/ide-completion-overrideannotation-rdarrdar62617558
[CodeCompletion] Annotate override completions
2021-09-02 15:50:26 -07:00
Rintaro Ishizaki
7e7b2c3557 [CodeCompletion] Annotate override completions
* "description" for override completion is now annotatable
* "description" doesn't include attributes and decl introducer, but it
  includes generic paramters, effects specifiers, result type clause,
  and generic where clauses
* "name" now only include the name and the parameter names
* "sourcetext" should be the same

rdar://63835352
2021-09-02 12:12:26 -07:00
Ben Barham
8ae8f1d204 [Completion] Remove unused DocWords
The various keyword/recommended/etc fields were parsed and added to
completions, but never actually plumbed through SourceKit. Since they're
still unused and the implementation is not particularly lightweight,
just remove for now.

Resolves rdar://82464220
2021-08-28 14:05:01 +10:00
Rintaro Ishizaki
df2b9715ba [CodeCompletion] Add "soft deprected" diagnostics for code completion
'available(..., deprecated: <version>)'. If the version is larger than the
current active version, the declaration is "soft deprecated". Emit a
relevant diagnostics for those items. If the version is equal to or
larger than '100000.0', it means the distant future without specifying
the version.

rdar://76122625
2021-08-10 17:11:14 -07:00
Rintaro Ishizaki
ed1db1bed2 [CodeCompletion] Explain why results aren't recommended
* Implement 'getDiagnosticSeverity()' and 'getDiagnosticMessage()' on
  'CodeCompletionResult'
* Differentiate 'RedundantImportIndirect' from 'RedundantImport'
* Make non-Sendable check respects '-warn-concurrency'

rdar://76129658
2021-08-10 17:11:14 -07:00
Rintaro Ishizaki
f8751d466e [CodeCompletion] Provide known module source file information
* 'CodeCompletionContext' now has 'requiresSourceFileInfo()' flag
* When 'true', 'SourceFiles' is populated.
* 'SourceFiles' is a list of pairs of a known module source
  file path and its up-to-date-ness
* Clients (i.e. 'CodeCompletionConsumer') can retrieve it from
  'CodeCompletionContext' in 'handleResults'
* Each completion item now has 'SourceFilePath' property
* C-APIs to get those informations
2021-08-10 17:11:14 -07:00
Ben Langmuir
d6eec880cb [completion] Update CodeCompletionConsumer::handleResults()
Receive 'CodeCompletionContext' so that consumers can get more
information from it.
2021-08-10 14:14:15 -07:00
Rintaro Ishizaki
5559d9406f [CodeCompletion] NFC: rename CallParameter* to CallArgument*
Since these chunks are for call sites, the correct term is "argument".
2021-07-19 16:30:12 -07:00
Rintaro Ishizaki
18dc9c1c27 [CodeCompletion] Remove CodeComletionString::getName()
`CodeCompletioString::getName()` was used only as the sorting keys in
`CodeCompletionContext::sortCompletionResults()` which is effectively
deprecated. There's no reason to check them in `swift-ide-test`. Instead,
check `printCodeCompletionResultFilterName()` that is actually used for
filtering.
2021-07-16 13:24:19 -07:00
Rintaro Ishizaki
f553826ab2 [CodeCompletion] Don't modify CodeCompletionResult in place for cached results
Instead, allocate new `CodeCompletionResult` in the current sink.
2021-06-09 13:05:41 -07:00
Rintaro Ishizaki
5d5b93df8e [CodeCompletion] Make lookupCodeCompletionResultsFromModule() only accept
SourceFile as the decl context.
2021-06-08 16:06:10 -07:00
Rintaro Ishizaki
1855e1a143 [CodeCompletion] Add flairs to cached items
* Starting a statement with a protocol name is rare
* Starting a statemnet at top-level of non-script file is invalid

rdar://77934897
2021-06-08 14:09:39 -07:00
Rintaro Ishizaki
a2b59688b0 [CodeCompletion] Add decl context dependent 'Flair' to decl keywords
* 'super' in a overriding decl is "common".
* type decl introducers (e.g. 'struct', 'enum') at top-level in library
  files are "common"
* type decl introducers in 'protocol' are invalid, hence "rare"
* top-level only decl introducer (e.g. 'import', 'extension') are invalid
  at non-top-level, hence "rare"
* nested types in function bodies are "rare"
* member only decls (e.g. 'subscript', 'deinit') are invalid in function
  body, hence "rare"
* some modifiers (e.g. 'public', 'private', 'override') are invalid for
  local decls, hence "rare"

rdar://77934651
2021-06-07 17:52:00 -07:00
Rintaro Ishizaki
154cd88c86 [CodeCompletion] Use 'Flair' to describe "is argument labels" 2021-06-07 17:25:01 -07:00
Rintaro Ishizaki
6dd5d9482f [CodeCompletion] Introduce "Flair" in code completion
To describe fine grained priorities.

Introduce 'CodeCompletionFlair' that is a set of more descriptive flags for
prioritizing completion items. This aims to replace '
SemanticContextKind::ExpressionSpecific' which was a "catch all"
prioritization flag.
2021-06-07 17:25:01 -07:00
Rintaro Ishizaki
5096ab7bc4 [CodeCompletion] Complete type attributes
Complete type attributes after '@' in a type position

rdar://44917341
2021-05-19 20:44:40 -07:00
Rintaro Ishizaki
861bbcc5d6 Merge pull request #37330 from rintaro/ide-completion-rdar75620636
[CodeCompletion] Make object literals optional
2021-05-10 13:47:10 -07:00
Rintaro Ishizaki
da96ef1f51 [CodeCompletion] Make object literals optional
For example, non-Darwin platforms probably don't want
`#colorLiteral(red:green:blue":alpha:)` and `#imageLiteral(named:)`.
Add an completion option to include them, which is "on" by default.

rdar://75620636
2021-05-07 16:27:13 -07:00
Rintaro Ishizaki
b348bf60e1 [CodeCompletion] Complete pattern introducer for 'for'
After 'for', suggest 'try', 'await', 'var' and 'case'.

rdar://76355581
2021-05-06 18:13:43 -07:00
Rintaro Ishizaki
3c2433c942 [CodeCompletion] Prioritize call argument pattern
struct Foo {
    init(_ arg1: String, arg2: Int) {}
    init(label: Int) {}
  }
  func test(strVal: String) {
    _ = Foo(<HERE>)
  }

In this case, 'strVal' was prioritized because it can use as an argument
for 'init(_:arg2:)'. However, argument labels are almost always
preferable, and if the user actually want 'strVal', they can input a few
characters to get it at the top. So we should always prioritize call
argument patterns.

rdar://77188260
2021-04-29 13:23:15 -07:00
Ben Langmuir
fa476b0a8d [completion] Make NotRecommendedReason an enum class 2021-04-19 13:22:13 -07:00
Ben Langmuir
be7b5a7179 [completion] Clarify and simplify not-recommended state
Combine IsNotRecommended with NotRecommendedReason and improve the names
of the existing cases to more clearly identify the cases they apply to.
Now all not-recommended completions are required to have a reason.
2021-04-19 09:43:28 -07:00
Rintaro Ishizaki
b2174da15b [CodeCompletion] Update for actor isolation
For cross actor references:
* Annotate with 'async'
* "Not recommended" if there're non-'Sendable' arguments or return types

rdar://72200120
2021-03-24 15:52:44 -07:00
Ben Langmuir
222e2c7f4c Lift ImportDepth utility out of SourceKit into IDE (NFC) 2021-03-09 13:52:56 -08:00
Rintaro Ishizaki
b856c15513 [CodeCompletion] Mark async calls "NotRecommended" in non-async context
rdar://problem/72198532
2021-01-13 11:46:54 -08:00
Rintaro Ishizaki
8ef504acf3 Merge pull request #35050 from rintaro/ide-completion-rdar72198530
[CodeCompletion] Annotate 'async' functions/initializers in results
2020-12-18 09:29:07 -08:00
Rintaro Ishizaki
4284a51589 [Parse/CodeCompletion] Implement effects specifier completion
Rewrote and rename 'parseAsyncThrows' to 'parseEffectsSpecifiers'.
Implemented 'CodeCompletionCallbacks::completeEffectsSpecifier()'
2020-12-14 12:38:15 -08:00
Rintaro Ishizaki
4286c44e72 [CodeCompletion/SourceKit] Consolidate some chunk kinds
Consolidate ThrowsKeyword, RethrowsKeyword, and AsyncKeyword to
EffectsSpecifierKeyword.
Abolish 'key.throwsoffset' and 'key.throwslength' as they aren't used.
2020-12-14 12:25:30 -08:00
Rintaro Ishizaki
be7466eb3f [CodeCompletion] Annotate 'async' functions/initializers in results
Similar to how it shows "throws" today.

Introduced CodeCompletionStringChunk::ChunkKind::AsyncKeyword

rdar://problem/72198530
2020-12-14 11:03:24 -08:00
Doug Gregor
51baa57c51 [Code completion] Add doc comments for function builder build functions
Add brief documentation comments to each of the code completions
produced for a build* function in a code completion.
2020-09-16 12:59:04 -07:00
Ben Barham
107ba0bab4 Merge pull request #33884 from bnbarham/completion-copy-cleanup
[Gardening] Add re-usable copy* utility methods to use in code completion
2020-09-11 08:22:28 +10:00
Ben Barham
4f5d4d80bb [Gardening] Add re-usable copy* utility methods to use in code completion
Various copy* methods were re-implemented in a bunch of files, move them
to CodeCompletion.h so they can be re-used everywhere that needs them.
2020-09-10 11:42:33 +10:00
Nathan Hawes
6e657e8615 [CodeCompletion] Fix incorrect type relations in complete_enum_elements test.
We were reporting methods that return function types that return void (rather
than returning void directly) as being invalid in contexts that expect non-void
expressions and testing for that incorrect behavior.
2020-08-28 22:24:24 -07:00
Rintaro Ishizaki
ecfd369f35 [CodeCompletion] Typo: 'getAnnnoateResult' -> 'getAnnotateResult' 2020-05-12 10:33:45 -07:00
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
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
1cbb1e76d4 [CodeCompletion] Update for braceless multiple trailing closure 2020-05-06 01:56:41 -04: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