Commit Graph

1285 Commits

Author SHA1 Message Date
Doug Gregor
af6b30a195 [Code completion] Add code completion support for macro expansions. 2022-11-28 18:33:10 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Robert Widmann
9ff5d88847 Remove SourceKit Support for the libSyntax Tree 2022-11-16 14:52:28 -08:00
Robert Widmann
4c162b2aeb Delete libSyntax 2022-11-16 14:52:28 -08:00
Alex Hoppen
bd2771e756 [CodeComplete] Show global completions from modules that are imported as @_spi
If a module is imported as `@_spi`, we didn’t receive any global completions from it.

rdar://99027179
2022-08-24 23:52:21 +02:00
Slava Pestov
172bcdca8b Sema: Type resolution only needs a GenericSignature and not a GenericEnvironment 2022-08-08 01:20:04 -04:00
Alex Hoppen
2304bb9882 Merge pull request #59837 from ahoppen/pr/rename-dotexprcompletion-postfixcompletion
[CodeCompletion] Rename DotExprCompletion -> PostfixCompletion
2022-08-02 11:46:41 +02:00
Alex Hoppen
c5c34464de Merge pull request #58999 from ahoppen/pr/cache-function-asyncness
[CodeCompletion] Cache 'async'-ness of free functions
2022-08-01 10:15:23 +02:00
Sima Nerush
5e28b06baf Add in keyword completion and a test 2022-07-24 15:10:01 -06:00
Alex Hoppen
dec32674ef [CodeCompletion] Compute InvalidAsyncContext warning when making a completion result contextual
Store whether a result is async in the `ContextFreeCodeCompletionResult` and determine whether an async method is used in a sync context when promoting the context free result to a contextual result.

rdar://78317170
2022-07-21 14:27:19 +02:00
Alex Hoppen
803e667024 [CodeCompletion] Rename DotExprCompletion -> PostfixCompletion 2022-07-01 15:57:54 +02:00
Alex Hoppen
795be6c2bb Merge pull request #58734 from ahoppen/pr/fix-completion-in-property-attribute
[CodeCompletion] Support type checking attributes even if they are not part of the AST
2022-05-13 09:39:00 +02:00
Rintaro Ishizaki
1e018989c8 [CodeCompletion] Suggest 'in' after expression in closure
func test(value: [Int]) {
    value.map { value <HERE> }
  }

In this case 'value' in the closure is ambiguous between an expression
referring the outer function parameter, or a parameter declaration in
the closure. Previously, code completion only considered the former and
suggest the members of '[Int]', but not 'in' keyword. As a result, when
the user actually want to type 'in' here, they needed to hit 'esc' to
cancel the code completion.

In this change, suggest 'in' keyword even without a newline, as long as
the current decl context is a closure and it doesn't have 'in' in it.

Also previously 'in' was suggested even outside the closure and even it
already had the explict 'in'. This PR limit suggesting 'in' inside
closures without explicit 'in'.

rdar://80489548
2022-05-10 11:49:12 -07:00
Alex Hoppen
00423540f7 Merge pull request #58690 from ahoppen/pr/attribute-type-relation
[CodeCompletion] Mark types that can’t be used as attributes as having an invalid type relation when used after '@'
2022-05-09 22:00:52 +02:00
Alex Hoppen
9dbd5829de [CodeCompletion] Support type checking attributes even if they are not part of the AST
The code completion might occur inside an attriubte that isn’t part of the AST because it’s missing a `VarDecl` that it could be attached to. In these cases, record the `CustomAttr` and type check it standalone, pretending it was part of a `DeclContext`.

This also fixes a few issues where code completion previously wouldn’t find the attribute constructor call and thus wasn’t providing code completion inside the property wrapper.

rdar://92842803
2022-05-07 08:58:52 +02:00
Alex Hoppen
df605d479d [CodeCompletion] Mark types that can’t be used as attributes as having an invalid type relation when used after '@'
When completing after `@`, record what kind of attributes are applicable here (property wrapper, result builder, global actor), mark types that are marked as property wrapper etc. as having a 'Convertible' type relation and mark all other types as having an invalid type relation.

rdar://78239501
2022-05-06 20:09:12 +02:00
Rintaro Ishizaki
2805864bb5 [CodeCompletion] Suggest 'actor' decl introducer keyword
Previously 'actor' keyword was suggested as (deprecated) 'actor' decl
modifier, and it was gated by '-enable-experimental-concurrency'
compiler argument.
Add 'actor' as a type decl introducer. This causes duplicated 'actor' in
code completion if '-enable-experimental-concurrency', but that option
is basically useless at this point, so I assume not many people is using
it. Also 'actor' as a modifier will be removed soon.

[#58520] rdar://92511769
2022-05-05 14:37:44 -07:00
Alex Hoppen
c21a75def4 [CodeCompletion] Migrate CaseStmtBeginning to solver-based 2022-04-06 09:59:33 +02:00
Rintaro Ishizaki
cd4bc88443 Merge pull request #42145 from rintaro/ide-completion-rdar90399603
[CodeCompletion] Update for SE-0345 shorthand optional binding
2022-04-05 16:30:29 -07:00
Rintaro Ishizaki
bcc003bd2d [CodeCompletion] Update for SE-0345 shorthand optional binding
Suggest visible optional values after 'if let'.

rdar://90399603
2022-04-05 09:56:14 -07:00
Alex Hoppen
8cd5bbd5e6 [CodeCompletion] Migrate AccessorBeginning to solver-based 2022-04-03 16:46:23 +02:00
Alex Hoppen
2a96221d44 [CodeCompletion] Migrate AfterPoundExprCompletion to solver-based 2022-03-24 18:10:28 +01:00
Alex Hoppen
56ea3341f5 [CodeCompletion] Migrate ForEachSequence and PostfixExprBeginning to solver-based 2022-03-23 13:03:56 +01:00
Alex Hoppen
03d819f442 [CodeCompletion] Check whether surrounding context supports async in all solver-based completion kinds 2022-03-21 20:04:32 +01:00
Alex Hoppen
51777d5ff7 [CodeCompletion] Move TypeCheckCompletionCallbacks to IDE 2022-03-21 20:04:32 +01:00
Alex Hoppen
e2a62f1a60 [CodeCompletion] Migrate expression completions to solver-based 2022-03-21 13:00:33 +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
e40fc772c1 Merge pull request #41667 from ahoppen/pr/complete-expr-after-if
[CodeCompletion] Complete code completion tokens after if-statement as top-level
2022-03-16 15:07:27 +01:00
Alex Hoppen
82cb46c8b0 [CodeCompletion] Complete code completion tokens after if-statement as top-level
Instead of setting the code completion position when parsing the if-statement, which doesn’t create a `CodeCompletionExpr`, parse it as a new top-level expression.

As far as test-cases are concerned, this removes the “RareKeyword” flair from top-level completions in the modified test case. This makes sense IMO.
2022-03-14 14:40:11 +01:00
Konrad `ktoso` Malawski
13cc8b3157 [Distributed] Enable no-longer-experimental distributed by default 2022-03-11 22:14:49 +09:00
Rintaro Ishizaki
92b9df0725 [CodeCompletion] Remove 'declTypeContext' field from the result builder
This field is not used anymore
2022-03-03 11:47:33 -08:00
Alex Hoppen
a02c7e7346 Merge pull request #41601 from ahoppen/pr/prepare-for-solver-based-arg-completion
[CodeCompletion] Some more code cleanup
2022-03-03 09:43:41 +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
d9f3324aff [CodeCompletion] Make CodeCompletionCallbacksImpl::addSuperKeywords a static method
This matches the other add*Keywords methods.
2022-03-01 09:36:57 +01:00
Alex Hoppen
1baa1f4d9c [CodeCompletion] Extract common implementation of sawSolution and fallbackTypeCheck to TypeCheckCompletionCallback 2022-03-01 09:36:57 +01: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
5bfa9ca026 [CodeCompletion] Make deliver*Result functions members on their TypeCheckCompletionCallback 2022-02-28 11:55:25 +01:00
Alex Hoppen
36c0bcc305 [CodeCompletion] Rename postProcessResults to postProcessCompletionResults 2022-02-28 11:45:51 +01:00
Alex Hoppen
8340abd8b1 [CodeCompletion] Move solver-based key path completion to its own file 2022-02-23 17:08:27 +01:00
Alex Hoppen
c8aba81978 [CodeCompletion] Move solver-based unresolved member completion to its own file 2022-02-23 17:08:27 +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
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
e37796dc88 [CodeCompletion] Move CompletionOverrideLookup to its own file 2022-02-23 17:05:52 +01:00
Alex Hoppen
67815f14f5 [CodeCompletion] Move implementation of CodeCompletionResultBuilder into 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
Alex Hoppen
b8be2794a3 [CodeCompletion] Move CompletionLookup to its own file 2022-02-23 17:05:52 +01:00