Commit Graph

874 Commits

Author SHA1 Message Date
Hamish Knight
be0f6f9491 [Completion] NFC: Factor out getMemberBaseType() 2025-02-25 14:49:12 +00:00
Xi Ge
87877bd95f ABI checker: avoid diagnosing missing availability info for decls that are only explicitly available on visionOS
Resolves: rdar://145061506
2025-02-18 09:56:42 -08: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
9ca1157a07 Add cache for USRBasedTypeContext::typeRelation
This brings the time taken for the cached completion:

```
import SwiftUI

Table(#^CC^#
```

down from ~400ms to ~190ms.
2024-10-31 15:42:30 +00:00
Hamish Knight
1a62f36a3a Eliminate recursion from USRBasedType::typeRelation
Use a worklist instead, and bump the size of the
inline set storage. This shaves ~30ms off the
time it takes to do this cached completion:

```
import SwiftUI

Table(#^CC^#
```
2024-10-31 15:42:30 +00:00
Hamish Knight
b840730958 [IDE] Pass LangOptions to ide::isSourceInputComplete
Ensure we account for things like the enablement
of bare slash regex literals.
2024-10-17 14:04:34 +01:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Doug Gregor
4c4a70f042 Remove unused shouldWalkInactiveConfigRegion 2024-09-16 16:30:57 -07: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
0f30a1ab35 [Completion] Handle body macro attribute completion
Add support for function-attached macros, and
complete body and preamble macros in those
positions.

rdar://130740590
2024-07-02 09:44:32 +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
Hamish Knight
b8b6395635 Merge pull request #74331 from hamishknight/keyword-completion
[Completion] Completions for `inout`, `borrowing`, `consuming`, `isolated`, `consume`, and `copy`
2024-06-18 21:00:54 +01:00
Alex Hoppen
f5d15f4f60 Merge pull request #74241 from ahoppen/enum-case-rename
Fix renaming enum case parameters with unnamed associated arguments
2024-06-12 14:46:46 -07:00
Hamish Knight
af0062725e [Completion] Complete ownership specifiers in parameters
Complete ownership specifiers such as `consuming`,
`borrowing`, and `inout` in parameter type
position. While here, also complete `isolated`.

rdar://127261573
2024-06-12 13:36:07 +01:00
Alex Hoppen
155773c38e Fix renaming enum case parameters with unnamed associated arguments
We treated enum case parameters the same way as function parameters and weren’t considering that they can be unlabeled. That caused us to insert eg. `_ ` in front of the case’s type, producing `case myCase(_ String)`, which is invalid. When we are inside an enum case parameter and the parameter label is empty, treat it the same as a function call, which will leave the label untouched if it isn’t modified and insert a label including a colon if a new label is introduced.

https://github.com/apple/sourcekit-lsp/issues/1228
2024-06-11 19:18:59 -07:00
Hamish Knight
30af99e47e [Completion] Better handle merging of lookup base types
For unresolved member completion, we were preferring
the more general type, when we ought to be preferring
the more specific type. Additionally, for both
unresolved member and postfix completion we were
opening archetypes, which doesn't work as expected
since we don't compare requirements. Factor out
the logic that deals with merging base types for
lookup, and have it prefer either the subtype, or
the optional type in the case of optional promotion.

rdar://126168123
2024-06-07 10:04:31 +01:00
Rintaro Ishizaki
79a7410206 [CodeCompletion] Remove CrossActorReference diagnostics too
Same for 'async in non-concurrency' context
2024-05-15 15:10:03 -07:00
Rintaro Ishizaki
39d633f5a8 [CodeCompletion] Remove unused 'isAsync' flag from CodeCompletionResult 2024-05-15 13:43:19 -07:00
Rintaro Ishizaki
9a6770e770 [CodeCompletion] Remove warning for 'async in non-concurrency context'
This warnings don't give much benefits for developers. Code completion
UI tends to show them unusable. But usually, developers can modify the
context to accept async calls, e.g. by wrapping it with `Task { }`

rdar://126737530
2024-05-15 12:55:05 -07:00
Alex Hoppen
ef3e1c1d4f [SourceKit] Allow generation of cursor info for declarations from solutions that haven’t aren’t applied to the AST ye
This has two benefits:
1. We can now report ambiguous variable types
2. We are more robust in the generation of results for declarations inside closures. If the closure has an error, we won’t apply the solution to the AST and thus any cursor info that tried to get types out of the AST would fail.

rdar://123845208
2024-03-20 14:52:39 +01:00
Alex Hoppen
aa955655ab Merge pull request #72048 from Jamezzzb/#56350
#56350 - Give Identifier a hasUnderscoredNaming() helper
2024-03-04 20:13:01 -08: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
Alex Hoppen
63aeedecbd [SourceKit] Only report textual results inside comments and strings from syntactic rename ranges 2024-02-29 15:37:29 -08:00
Ben Barham
1306f2b32a Merge pull request #71863 from bnbarham/remove-makearrayref
Use the new template deduction guides rather than `makeArrayRef`
2024-02-25 21:06:51 -08:00
Alex Hoppen
873ed19786 [SourceKit] Add the raw doc comment to the cursor info response
SourceKit-LSP currently parses the XML comment to generate Markdown again but round-tripping a (probably markdown) doc comment to XML to Markdown is lossy in many cases and unnecessary work. Include the comment as it is spelled in source in the cursor info response so that sourcekit-lsp can display it.

Part of rdar://120685874
2024-02-24 08:41:08 -08:00
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
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
c8424c1b7a [CodeComplete] Remove code for call pattern heuristics
These options weren’t used anymore, so we can remove them.
2024-01-22 19:57:12 -08:00
Alex Hoppen
ece521c12b Merge pull request #71046 from ahoppen/ahoppen/copyable-completion
[CodeComplete] Emit `Copyable` declaration instead of keyword
2024-01-22 17:22:51 -08: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
695e69e09e [CodeComplete] Suggest single argument labels if code completion is invoked at start of function call with exiting parameters
This removes the distinction between argument completions and postfix expr paren completions, which was meaningless since solver-based completion.

It then determines whether to suggest the entire function call pattern (with all argument labels) or only a single argument based on whether there are any existing arguments in the call.

For this to work properly, we need to improve parser recovery a little bit so that it parsers arguments after the code completion token properly.

This should make call pattern heuristics obsolete.

rdar://84809503
2024-01-22 12:21:04 -08:00
Alex Hoppen
72d38e94e2 [IDE] Move definition of low-level runNameMatcher entry point to .cpp file 2023-12-12 12:58:15 -08:00
Alex Hoppen
7d84f08d95 [SourceKit] Delete C++ NameMatcher
The C++ `NameMatcher` has bee completely replaced by the swift-syntax `NameMatcher` now.
2023-12-12 12:58:15 -08:00
Alex Hoppen
a5530ce9b6 [SourceKit] Factor out some more bridging code to run the NameMatcher from swift-syntax 2023-12-12 12:58:15 -08:00
Alex Hoppen
9219b0cd71 [SourceKit] Address FIXMEs for the NameMatcher
rdar://118996561
2023-12-11 16:56:01 -08:00
Alex Hoppen
5cae50a1a6 [SourceKit] Refactor addSyntacticRenameRanges
Refactor `addSyntacticRenameRanges`, adding comments to make it easier to follow and remove its dependency on the `IsFunctionLike` parameter in `RenameLoc`.
2023-12-06 14:31:47 -08:00
Alex Hoppen
db8ca19a24 Merge pull request #70014 from ahoppen/ahoppen/some-any-completion
[CodeCompletion] Add keyword completion for 'some', 'any', 'repeat', and 'each'
2023-12-05 16:24:05 -08:00
Alex Hoppen
9cb2a248c6 [CodeCompletion] Add keyword completion for 'some', 'any', 'repeat', and 'each'
The implementation is not 100% perfect but I don’t think it’s worth putting too much effort into it passing more information down in the parser if 'repeat' and 'each' are valid if we are going to remove the current parser anyway.

rdar://95725895
2023-12-04 15:20:05 -08:00
Alex Hoppen
bc5cc43a06 Don’t include <vector> in IDEBridging.h 2023-11-28 14:04:37 -08:00
Alex Hoppen
b31398215d Don’t include SourceLoc.h when USED_IN_CPP_SOURCE is not set 2023-11-27 19:34:27 -08:00
Alex Hoppen
f408619ddc Address Hamish’s review comments 2023-11-27 14:17:04 -08:00
Alex Hoppen
330ed60401 [SourceKit] Don't use C++ interop to append elements to a ResolvedLocVector
This was causing build issues on Linux with Swift 5.8. Instead, wrap the `std::vector` in a `BridgedResolvedLocVector` that has a pointer to a heap-allocated `std::vector`
2023-11-22 16:41:07 -08:00
Alex Hoppen
d224549030 [SourceKit] Don’t use C++ to Swift interop to run NameMatcher 2023-11-20 11:30:18 -08:00
Alex Hoppen
8fd025625b [SourceKit] Use NameMatcher that is rewritten in Swift for syntactic rename 2023-11-17 09:30:04 -08:00
Alex Hoppen
1047328b63 [SourceKit] Lowercase members of ResolvedLoc
This type will get exposed to Swift and the members should be lowercase so that they read nicely in Swift.
2023-11-16 16:05:08 -08:00
Alex Hoppen
33e9c30ede [SourceKit] Unify boolean values in ResolvedLoc into a ResolvedLocContext 2023-11-16 16:05:08 -08:00
Alex Hoppen
8208c23850 [SourceKit] Remove ResolvedLoc.Node
We can’t represent the parent node when rewriting `NameMatcher` using swift-syntax. Replace it by two boolean fields `IsComment` and `IsInStringLiteral` that can be bridged.
2023-11-16 16:05:08 -08:00