Commit Graph

238 Commits

Author SHA1 Message Date
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Alex Hoppen
72cadecf21 [CodeCompletion] Split result delivery into a result colleciton and consumer phase
This will allow us to run two different completion kinds and deliver results from both of them.

Also: Compute a unified type context for global lookup. Previously, we always used the expected type context of the last lookup. But really, we should be considering all possible types from all constraint system solutions when computing code completion results from the cache.
2023-08-24 15:41:36 -07:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Alex Hoppen
f538d33e5f [CodeCompletion][Sema] Migrate CallArgurment position completion to the solver-based implementation
This hooks up call argument position completion to the typeCheckForCodeCompletion API to generate completions from all the solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any).

Co-authored-by: Nathan Hawes <nathan.john.hawes@gmail.com>
2022-03-17 15:15:54 +01:00
Alex Hoppen
94351a2f82 [CodeComplete] Compute type relations for global cached results
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
2022-03-02 23:13:09 +01:00
Hamish Knight
1f5845d9d9 Revert "[CodeComplete] Compute type relations for global cached results" 2022-03-02 21:43:31 +00:00
Alex Hoppen
640cfac61c [CodeComplete] Compute type relations for global cached results
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
2022-03-01 09:16:23 +01:00
Alex Hoppen
36c0bcc305 [CodeCompletion] Rename postProcessResults to postProcessCompletionResults 2022-02-28 11:45:51 +01:00
Alex Hoppen
471b24f459 [CodeCompletion] Move solver-based DotExpr completion to its own file 2022-02-23 17:08:27 +01:00
Alex Hoppen
190ee6ecc7 [CodeCompletion] Replace includes of CodeCompletion.h by more specific ones 2022-02-23 17:08:26 +01:00
Alex Hoppen
7e043159f3 [CodeCompletion] Move ImportDepth to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
48179ad01e [CodeCompletion] Split CodeCompletionConsumer into its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
faa8fd3db2 [CodeCompletion] Move CodeCompletionContext.h to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
85bf521b04 [CodeCompletion] Move CodeCompletionResultSink to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
e1809ecafe [CodeCompletion] Split CodeCompletionResult and ContextFreeCodeCompletionResult into their own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
ab5b360e0b [CodeCompletion] Split CodeCompletionString into its own file 2022-02-23 17:05:52 +01:00
Rintaro Ishizaki
3c33debd61 [CodeCompletion] Make all result's string fields null terminated
This is convenient for clients to pass these fields values to C
functions. Introduce NullTerminatedStringRef to guarantee that.
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
7ef93b2a67 [Basic] Move copyCString to Basic/StringExtras.
Also, use StringRef.copy() instead of copyString().
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
5ab84ae242 [CodeCompletion] Precompute and cache "filter name"
Filter name for completion item is always used. Also, for cached items,
they are used multiple times for filtering. So precomputing and caching
it improves performance.

rdar://84036006
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
33ee4d609f [CodeCompletion] 'ContextFreeCodeCompletionResult' factory method
Convert 'ContextFreeCodeCompletionResult' constructor overloads to
'create()' factory methods. This is the consistent interface with
'CodeCompletionString'. NFC
2022-02-18 09:58:26 -08:00
Rintaro Ishizaki
7893f74142 Merge pull request #41384 from rintaro/ide-completion-actorkind-rdar79733313
[CodeCompletion] Add a symbol kind for actors
2022-02-16 15:55:47 -08:00
Alex Hoppen
6bc0de94a2 [SourceKit] Compute code completion type relation when wrapping a ContextFreeCodeCompletionResult in a CodeCompletionResult
[CodeCompletion] Make ExpectedTypeContext a class with explicit getters/setters

This simplifies debugging because you can break when the possible types are set and you can also search for references to `setPossibleType` to figure out where the expected types are being set.
2022-02-16 20:28:13 +01:00
Rintaro Ishizaki
d9011e06b2 [CodeCompletion] Add a symbol kind for actors
rdar://79733313
2022-02-15 13:14:46 -08:00
Alex Hoppen
50eafca5bf [Code Completion] Extract CodeCompletionResultTypeRelation to a top-level type
Preliminary work to compute the type relation when constructing a contextual code completion result.
2022-02-08 15:04:38 +01:00
Alex Hoppen
fd72674a57 [Code Completion] Split code completion results into context free part that can be cached and contextual part displayed to the user
This allows makes the distinction between cachable and non-cachable properties cleaner and allows us to more easily compute contextual information (like type relations) for cached items later.
2022-01-27 10:40:47 +01:00
Alex Hoppen
bad96793f8 [Code Completion] Extract NotRecommendedReason and CodeCompletionResultKind to top-level types
Preliminary work to split `CodeCompletionResult` into a context-free and contextual part.
2022-01-20 16:26:30 +01:00
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