Commit Graph

1494 Commits

Author SHA1 Message Date
Alex Hoppen
4bc03f8392 [SourceKit] Add a request to get the semantic tokens of a file
We need this request for semantic highlighting in LSP. Previously, we were getting the semantic tokens using a 0,0 edit after a document update notification but that will no longer be possible if we open the documents in syntactic only mode.
2023-10-20 10:38:08 -07:00
Simon Barinka
23cde9b2e0 [SourceKit] Move the option to IndexToStore request 2023-10-20 12:55:41 +02:00
Simon Barinka
ae570850e0 [SourceKit] Fix formatting 2023-10-09 21:16:13 +02:00
Simon Barinka
b13a7f5829 [SourceKit] Add option to index local symbols to IndexSource request
Adds optional `key.should_index_locals` flag to the SourceKit `source.request.indexsource` request.
If true, the response includes symbol info for both locals and globals.
2023-10-09 20:59:43 +02:00
swift-ci
17a5d30d54 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-15 16:14:15 -07:00
Hamish Knight
746128c7aa Use StringMap in EditorDiagConsumer
As noted by the comment, storing a `StringRef` is
indeed brittle. Update to use a StringMap.

rdar://111589090
2023-09-15 18:27:49 +01:00
swift-ci
0407c3d3b2 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-06 13:34:53 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
swift-ci
fecdc7961c Merge remote-tracking branch 'origin/main' into rebranch 2023-08-28 10:37:07 -07:00
Artem Chikin
e0275f4f0e [Explicit Module Builds] Do not attempt to re-load module dependency from
interface for index.

An explicit module build compile is unable to do so because it does not have
access to the interfaces. Doing this in the first place is a workaround for a
known bug, which will require to be solved at the root cause instead (e.g.
Deserialization Safety feature).

Resolves rdar://113165898
2023-08-25 16:34:09 -07:00
Evan Wilde
11fcbbeea2 Cleaning up more deprecation warnings
Pointer `llvm/Support/Host.h` at `llvm/TargetParser/Host.h`.
Replacing deprecated API `startswith_insensitive` with replacement
`starts_with_insensitive`.
2023-08-10 16:19:24 -07:00
Alex Hoppen
bba2f476ab Merge pull request #67613 from barinsim/my-main
[SourceKit] Report cursor info information for literals
2023-08-08 20:54:00 -07:00
Simon Barinka
87878c5f35 [SourceKit] Address minor PR comments 2023-08-03 09:41:25 +02:00
Simon Barinka
76e01b8481 [SourceKit] Address minor PR comments 2023-08-03 09:36:29 +02:00
Simon Barinka
e5fa3f9d2d [SourceKit] Fix formatting issues 2023-08-03 00:53:46 +02:00
Simon Barinka
06af7494e9 [SourceKit] Report type decl info instead of hidden inits 2023-08-02 23:40:08 +02:00
Simon Barinka
d0cf2e4bf3 [SourceKit] Fix formatting issues 2023-08-01 13:26:14 +02:00
Simon Barinka
e32a20a55c [SourceKit] Report init info instead of the type decl info
Addresses PR review comments.
2023-08-01 12:51:39 +02:00
Simon Barinka
fcd084f9dd [SourceKit] Report cursor info information for literals
Adds literals support for the CursorInfo request.
Previously CursorInfo just returned error for literals.
Implements issue #57725
2023-07-30 14:22:08 +02:00
Ben Barham
6e93ac1627 Merge pull request #66958 from DavidGoldman/main
Add source.request.index_to_store to sourcekitd
2023-07-12 13:53:33 -07:00
David Goldman
af81adb63c sourcekitd source.request.index_to_store fixes - new test and minor changes 2023-06-30 15:55:43 -04:00
David Goldman
d618233166 Add source.request.index_to_store to sourcekitd
This requests performs an index store index of the given file using the
given index store path and index unit output path. All other options are
derived from the index store related compiler flags.

This will allow IDEs like Xcode to index the file directly inside of
sourcekitd and potentially reuse an already built AST.
2023-06-28 14:24:20 -04:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07: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
Ben Barham
93ec785d92 Merge pull request #66907 from bnbarham/fix-reuse-test
[CursorInfo] Pass primary path to allow comparing previous ASTs
2023-06-26 10:50:51 -07:00
Alex Hoppen
22d34d9b14 Merge pull request #58978 from ahoppen/pr/no-deadlock-cancellation-bigger-change
[SoruceKit] Audit SwiftASTManager to prevent deadlocks
2023-06-26 13:11:08 +02:00
Ben Barham
ab95dba720 [CursorInfo] Pass primary path to allow comparing previous ASTs
Update the cursor requests to also pass in their primary file. Snapshots
should be compared using this file, not the input buffer name. This
fixes AST re-use when the AST is usable with snapshots.

Resolves rdar://110344363.
2023-06-23 20:00:19 -07:00
Ben Barham
1d7c534228 Merge pull request #66839 from bnbarham/reuse-cursor-ast
[CursorInfo] Re-use already built ASTs ahead of currently building ones
2023-06-23 09:05:47 -07:00
Alex Hoppen
453f6cdeee [SoruceKit] Audit SwiftASTManager to prevent deadlocks
- Ensure that no callbacks are called when either of these mutexes are held:
  - `SwiftASTConsumer::CancellationRequestCallbackAndIsCancelledMtx`
  - `ASTBuildOperation::DependencyStampsMtx`
    - Exception: We allow calls to `getBuferStamp` because that doesn’t claim any locks)
    - No change was necessary here
  - `ASTBuildOperation::ConsumersAndResultMtx`
  - `ASTBuildOperation::CacheMtx`
    - No change was necessary here
  - `ASTBuildOperation::ScheduledConsumersMtx`
    - Make sure we always inform the consumers asynchronously, even if the operation was already cancelled when the consumer got enqueued by introducing `ConsumerNotificationQueue`
- Ensure that all callbacks to `SwiftASTConsumer` (i.e. `requestCancellation` and `handlePrimaryAST`, `failed`, `cancelled`) are performed asyncronously from a queue to avoid deadlocks

rdar://110357502
2023-06-23 16:55:49 +02:00
Ben Barham
037ddc92ee [CursorInfo] Re-use already built ASTs ahead of currently building ones
Resolves rdar://110344363.
2023-06-22 14:12:48 -07:00
Alex Hoppen
35661f2ab6 [SourceKit] Inform consumers about cancellation from a background queue
This fixes a deadlock that could occur when a cursor info request is cancelled while another one is inside the cancellation callback. The schematic deadlock backtrace is

```
sourcekitd::cancelRequest
SourceKit::RequestTracker::cancel -> holds RequestTracker.RequestsMtx
anonymous func in SourceKit::SwiftASTManager::processASTAsync
SourceKit::SwiftASTConsumer::requestCancellation
anonymous func in ASTBuildOperation::addConsumer -> tries to get ASTBuildOperation.ConsumersAndResultMtx

resolveCursor
SourceKit::SwiftASTManager::processASTAsync
SourceKit::SwiftASTConsumer::requestCancellation
anonymous func in ASTBuildOperation::addConsumer
[probably inlined] ASTBuildOperation::requestConsumerCancellation -> holds ASTBuildOperation.ConsumersAndResultMtx
resolveCursor::CursorInfoConsumer::cancelled
anonymous func in SourceKit::SwiftLangSupport::getCursorInfo
anonymous func in handleRequestCursorInfo
reportCursorInfo
anonymous func in sourcekitd::handleRequest -> tries to get RequestTracker.RequestsMtx
```

rdar://110357502
2023-06-22 21:31:42 +02:00
Alex Hoppen
b66dfadea5 [SourceKit] When AST-based cursor info is cancelled, don’t run solver-based cursor info
Running solver-based cursor info in the callback that is informed about cancellation extends the window for a deadlock.
2023-06-22 21:29:08 +02:00
Hamish Knight
a9f9bd1394 [SourceKit] Record module loading errors when generating interfaces
Record up to two errors emitted when we fail to
load a module for interface generation, and include
these errors in the message we pass back to the
editor. This should help us better pin down the
reason why interface generation failed.

rdar://109511099
2023-06-15 23:55:07 +01:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Rintaro Ishizaki
c3d1304345 [SourceKit] Add request to expand macros syntactically
Expand macros in the specified source file syntactically (without any
module imports, nor typechecking).

Request would look like:
```
{
  key.compilerargs: [...]
  key.sourcefile: <file name>
  key.sourcetext: <source text> (optional)
  key.expansions: [<expansion specifier>...]
}
```
`key.compilerargs` are used for getting plugins search paths. If
`key.sourcetext` is not specified, it's loaded from the file system.
Each `<expansion sepecifier>` is
```
{
  key.offset: <offset>
  key.modulename: <plugin module name>
  key.typename: <macro typename>
  key.macro_roles: [<macro role UID>...]
}
```
Clients have to provide the module and type names because that's
semantic.

Response is a `CategorizedEdits` just like (semantic) "ExpandMacro"
refactoring. But without `key.buffer_name`. Nested expnasions are not
supported at this point.
2023-06-07 14:26:40 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Hamish Knight
4ce49bd4d2 [Parse] Sink registerParseRequestFunctions call into ParserUnit 2023-05-22 14:55:18 +01:00
Ben Barham
01086bc8b5 Merge pull request #65688 from bnbarham/swap-cursor-info-order
[CursorInfo] Prefer AST based results over solver based
2023-05-05 16:54:25 -07:00
Ben Barham
5beeca7cf1 [CursorInfo] Prefer AST based results over solver based
Solver based results are fast within a function, where the `ASTContext`
can be re-used. But it is significantly slower than the AST based
results when outside of a function. Instead of using solver based as the
primary results, only use them as a fallback for when AST based fails.

Resolves rdar://108930110.
2023-05-04 20:53:38 -07:00
Hamish Knight
62b021030f [SourceKit] Include generated macro buffers in diagnostic responses
Introduce a new key `generated_buffers`, which
stores an array of generated buffers. These
include the buffer text, as well as its original
location and any parent buffers.

While here, also fix rdar://107281079 such that
only apply the filename fallback logic to the
pretty-printed Decl case. We ought to remove this
fallback once the editor can handle it though.

rdar://107281079
rdar://107952288
2023-05-02 16:21:44 +01:00
Hamish Knight
f0d5456b33 NFC: Move some code around 2023-05-02 16:21:44 +01:00
Ben Barham
3368e710a2 Merge pull request #65515 from bnbarham/add-attached-type-relation
[Completion] Add convertible type relation for attached macros
2023-05-01 09:52:04 -07:00
Ben Barham
f7d1cc8426 [Completion] Add convertible type relation for attached macros
Resolves rdar://108678938.
2023-04-28 16:15:51 -07:00
Hamish Knight
b8ae0666ad Rename getBriefComment -> getSemanticBriefComment
Make it clear that we will walk the comment providing
decls if needed.
2023-04-26 12:38:38 +01:00
Rintaro Ishizaki
a551c01d6a [Macros] Track plugin dependencies
* Factor out ASTContext plugin loading to newly introduced 'PluginLoader'
* Insert 'DependencyTracker' to 'PluginLoader'
* Add dependencies right before loading the plugins

rdar://104938481
2023-04-25 10:50:32 -07:00
Alex Hoppen
aef35b917e [SourceKit] Expand editor placeholder to trailing closures inside a TryExpr
rdar://108391690
2023-04-21 17:21:50 -07:00
Rintaro Ishizaki
3517db4c3b [SourceKit] Pass 'swiftc' path to Driver when creating frontend args
Driver uses its path to derive the plugin paths (i.e.
'lib/swift/host/plugins' et al.) Previously it was a constant string
'swiftc' that caused SourceKit failed to find dylib plugins in the
toolchain. Since 'SwiftLangSupport' knows the swift-frontend path,
use it, but replacing the filename with 'swiftc', to derive the plugin
paths.

rdar://107849796
2023-04-12 09:53:43 -07:00
Ben Barham
e5dbe300e4 Merge pull request #64986 from bnbarham/macro-completion
[Completion] Only provide macro completions when they are valid
2023-04-08 11:08:42 -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