Commit Graph

53 Commits

Author SHA1 Message Date
Ahmed Mahmoud
ec1b146581 [IDE] Move CodeCompletionString building into CodeCompletionStringBuilder
[IDE] Move primitive completion function label into CodeCompletionStringBuilder

[IDE] NFC: Remove unneeded string builder methods on CodeCompletionResultBuilder

[IDE] Move addValueBaseName into CodeCompletionStringBuilder

[IDE] Make CodeCompletionResultBuilder a CodeCompletionStringBuilder

[IDE] Explicitly pass DeclContext in CodeCompletionStringBuilder

[IDE] Reduce includes in CodeCompletionStringBuilder.h
2025-08-27 00:40:20 +03:00
Pavel Yaskevich
816ea9fda6 [CodeCompletion] Implement completions in using declaration's specifier position 2025-05-30 00:39:06 -07:00
Hamish Knight
52d8b36af4 [Completion] Suggest trivial trailing closures for macros
Follow the same logic as function decl completion and suggest a
trailing closure for trivial cases.

rdar://150550747
2025-05-22 11:16:10 +01:00
Hamish Knight
352caa4ddc [Completion] NFC: Factor out addMacroCallArguments 2025-05-21 18:06:54 +01:00
Hamish Knight
f0c38616d0 [Completion] Handle unbound generics in typealiases
The underlying type for a typealias can be an unbound generic type,
replace these with the bound generic equivalent. This avoids crashing
when attempting to compute the type relation (in the future we'll
want to open these type parameters for the comparison).

rdar://147789214
2025-04-01 20:11:48 +01:00
Ahmed Mahmoud
673d6a1d9f [IDE] Rename CustomSyntaxAttributeKind to ParameterizedDeclAttributeKind 2025-03-13 02:19:17 +02:00
Tony Allevato
d94bd80c62 Add support for raw identifiers.
Raw identifiers are backtick-delimited identifiers that can contain any
non-identifier character other than the backtick itself, CR, LF, or other
non-printable ASCII code units, and which are also not composed entirely
of operator characters.
2025-03-11 17:18:43 -04:00
Hamish Knight
be0f6f9491 [Completion] NFC: Factor out getMemberBaseType() 2025-02-25 14:49:12 +00:00
Becca Royal-Gordon
01b8bbea89 Tie attributes to language features
The new `DECL_ATTR_FEATURE_REQUIREMENT` macro in DeclAttr.def can be used to declare that an attribute should only be available when a related language feature is enabled.

Effects:

• `#if hasAttribute(someAttr)` will return `false` unless the required feature is enabled.
• Code completion will not include the attribute unless the required feature is enabled.
• `TypeChecker::checkDeclAttributes()` diagnoses non-implicit uses of the attribute.

Add this mechanism and use it to tie @abi to the ABIAttribute feature. Also design tests for it.
2024-12-19 15:49:34 -08:00
Hamish Knight
c19d049493 [Completion] Fix invertible type completion
The previous logic for this was unused, replace
it with new logic that consults
InvertibleProtocols.def for the list of protocols
to suggest.

rdar://139212286
2024-11-19 12:12:21 +00:00
Hamish Knight
ec597c82fa [Completion] Only complete @unchecked et al in inheritance clauses
Add a case for completing type attributes in
inheritance clause position, and limit the
completion of `@unchecked`, `@preconcurrency`, and
`@retroactive` to that case.
2024-07-03 11:41:58 +01:00
Hamish Knight
94ed2418f4 [Completion] Complete .isolation for @isolated(any) functions
This was added in SE-0431.

rdar://124615036
2024-07-01 12:49:52 +01:00
Hamish Knight
1f83e66a3e [Completion] NFC: Factor out addBuiltinMemberRef 2024-07-01 12:49:52 +01:00
James Brown
2c281208de 56350 - Give Identifier a hasUnderscoredNaming() helper and in the places currently using str().startsWith, change it to use the new helper. 2024-03-04 19:34:11 -05:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Hamish Knight
d7fc22aaca [IDE] Simplify isImplicitSingleExpressionReturn
Use the generalized implied result logic, and
rename to `isImpliedResult` since that's really
what we're querying here, and it needs to handle
implicit-last-exprs if enabled.
2024-02-07 18:14:23 +00:00
Alex Hoppen
7087da9913 [CodeComplete] Emit Copyable declaration instead of keyword
Now that there is an actual declaration for `Copyable` we should be emitting that as a code completion result instead of a keyword, like we currently do.

rdar://109107817
2024-01-22 12:34:38 -08:00
Alex Hoppen
ee85314e6f [CodeCompletion] Add completion for @storageRestrictions 2023-09-27 09:33:38 -07:00
Holly Borla
97f1e617fd [Concurrency] Replace ClosureActorIsolation with ActorIsolation throughout
the isolation query APIs.
2023-09-16 12:21:36 -07:00
Alex Hoppen
5aa725d5cc [CodeCompletion] Delete dead code 2023-09-06 13:13:01 -07:00
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Alex Hoppen
e8a32e45be Merge pull request #65805 from ahoppen/ahoppen/complete-constraint-type
[CodeComplete] Offer completions after `~` in an inheritance clause
2023-05-12 13:32:40 -07:00
Alex Hoppen
2abae1019f [CodeComplete] Offer completions after ~ in an inheritance clause
We should only be suggesting `Copyable` after `~` in an inheritance clause, in accordance with [SE-0390](https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md)

rdar://109063223
2023-05-09 20:21:30 -07:00
Alex Hoppen
c140fe480c [CodeCompletion] Only show type annotations for macros that return non-void
Showing the type annotation only makes sense if they are not `Void`. That’s consistent with functions where we also don’t show a `Void` return type. Most importantly, we shouldn’t be showing a `Void` type annotation for attached macros.

rdar://108870970
2023-05-04 18:02:26 -07:00
Alex Hoppen
1e505791e4 [CodeComplete] Offer completions for the names: argument of a macro declaration
When completing after `names:`, completion should offer the different ways you can specify the names, i.e. `arbitrary`, `named`, etc.

```
@freestanding(declaration, names: #^COMPLETE^#)
```

rdar://108535077
2023-04-28 17:20:45 -07:00
Alex Hoppen
053d215d55 Merge pull request #65427 from ahoppen/ahoppen/macro-attribute-completions
[CodeCompletion] Support completion for macro roles and the 'names:' argument label
2023-04-28 17:20:24 -07:00
Alex Hoppen
6098a3ca2b [CodeCompletion] Support completion for macro roles and the 'names:' argument label
rdar://108163121
2023-04-27 21:48:06 -07:00
Alex Hoppen
d5e97501fa [CodeCompletion] Suggest freestanding after @
rdar://108163121
2023-04-25 18:06:47 -07:00
Rintaro Ishizaki
20a8441724 [CodeCompletion] Don't take opaque types subst map into account
for checking duplicated results from multiple type checker solutions.
e.g.

  protocol Proto {}
  struct Generic<T> {
    func retProto() -> some Proto
  }
  func foo() -> Generic<T1>
  func foo() -> Generic<T2>

  foo().<COMPLETION>

The return type of `Geric<T1>.retProto()` and `Geric<T2>.retProto()` is
different, but they both spelled 'some Proto'. So IDE consumers don't
care the difference.

rdar://107669173
2023-04-13 16:38:10 -07:00
Ben Barham
31dee1ce1c [Completion] Only provide macro completions when they are valid
Only return macros that are valid in their current position, ie. an
attached macro is not valid on a nominal.

Also return freestanding expression macros in code block item position
and handle the new freestanding code item macros.

Resolves rdar://105563583.
2023-04-07 18:43:06 -07:00
Alex Hoppen
8a2cd86deb Split IDEInspectionCallbacks into CodeCompletionCallbacks and DoneParsingCallback
Cursor info only cares about the `doneParsing` callback and not about all the `complete` functions that are now defined in `CodeCompletionCallbacks`. To make the design clearer, split `IDEInspectionCallbacks`.

rdar://105120332
2023-03-17 10:31:13 -07:00
Doug Gregor
7fc7040aad [Macros] Drop special code completions for built-in macros.
We don't need special completion logic for things like `#file` and
`#line` now that they are declared in the standard library. Drop it
and update tests.
2023-03-02 20:34:58 -08: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
Doug Gregor
af6b30a195 [Code completion] Add code completion support for macro expansions. 2022-11-28 18:33:10 -08: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
Rintaro Ishizaki
0e2e315633 Remember nominal type decls for member lookup
`lookupVisibleMemberDecls` visits nominal type decls to find visible
members of the type. Remembering what decls are visited can be useful
information for the clients.

* Add a 'VisibleDeclConsumer' callback function that is called when
  'lookupVisibleDecls' visits each nominal type decls
* Remember the decl names in 'CodeCompletionContext' for future use
2022-10-21 16:46:06 -07:00
Alex Hoppen
442cf9bd4e [Sema] Add custom functions to ActorIsolationChecker to determine expr type and closure actor isolation
When we get rid of `LeaveClosureBodiesUnchecked` we no longer save closure types to the AST and thus also don’t save their actor isolation to the AST. Hence, we need to extract types and actor isolations of parent closures from the constraint system solution instead of the AST. This prepares `ActorIsolationChecker` to take custom functions to determine the type of an expression or the actor isolation of a closure.
2022-09-07 11:12:23 +02: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
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
Alex Hoppen
310ec6eb8d [CodeCompletion] Only include results from other modules once
In case of ambigous expression/global completions, we call `getValueCompletionsInDeclContext` multiple times for the amigous solutions to the constraint system. This can cause modules to be included multiple times in `RequestedCachedResults` and thus global results from these modules are reported multiple times. Make `RequestedCachedResults` a set so we don’t get duplicate results.

rdar://92048610
2022-04-21 10:48:40 +02:00
Rintaro Ishizaki
0dad5ff24e [NFC][CodeCompletion] Prepend 'should' to 'addItemWithoutDefaultArgs'
Rename 'addItemWithoutDefaultArgs' to 'shouldAddItemWithoutDefaultArg'
because this function only returns bool indicating "should or not".
2022-04-05 16:53:37 -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
03d819f442 [CodeCompletion] Check whether surrounding context supports async in all solver-based completion kinds 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
Konrad `ktoso` Malawski
13cc8b3157 [Distributed] Enable no-longer-experimental distributed by default 2022-03-11 22:14:49 +09: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