Commit Graph

1154 Commits

Author SHA1 Message Date
Hamish Knight
e6df9e7483 Update for new ExpandEditorPlaceholdersToLiteralClosures API
This refactoring now takes a `Syntax` parameter. We don't actually
need to change anything else to handle placeholder expansion for
macro expansion completions since they get parsed as function calls.
2025-06-04 12:32:36 +01:00
Alex Hoppen
a9094391f0 Pass cancelOnSubsequentRequest: 0 to all requests that support it
Adopt the option introduced by https://github.com/swiftlang/swift/pull/81507. SourceKit-LSP uses explicit cancellation and perform any implicit cancellation inside sourcekitd.

Fixes #2021
rdar://145871554
2025-05-15 10:42:07 +02:00
Alex Hoppen
188e174cde Merge pull request #2094 from ahoppen/contextual-sourcekitd-request
Log contextual requests that affect sourcekitd’s global state
2025-05-14 19:12:58 +02:00
Alex Hoppen
3f1568c68d Merge pull request #2144 from ahoppen/refresh-semantic-tokens
Send `workspace/semanticTokens/refresh` to client when build settings have changed
2025-05-12 19:16:42 +02:00
Alex Hoppen
69ab356b36 Log contextual requests that affect sourcekitd’s global state
This way we can log them when a sourcekitd request crashes and we can thus replay these contextual requests when diagnosing the crash.
2025-05-12 15:39:52 +02:00
Alex Hoppen
863c0e2cdf Merge pull request #2137 from ahoppen/terminate-unresponsive-clangd-sourcekitd
If sourcekitd or clangd don’t respond to a request for 5 minutes, terminate them and use crash recovery to restore behavior
2025-05-12 15:13:30 +02:00
Alex Hoppen
1bc7d85dbd Send workspace/semanticTokens/refresh to client when build settings have changed
Similar to how we send a `workspace/diagnostic/refresh` request to the client when we get new build settings, we need to send a `workspace/semanticTokens/refresh` to the client to reload semantic tokens when builds settings change. This is particularly important so that we reload semantic tokens from real build setting after a SwiftPM package has finished loading (we previously used fallback settings).

Fixes #2141
rdar://150934682
2025-05-09 13:33:35 +02:00
Alex Hoppen
14cfd50582 If sourcekitd or clangd don’t respond to a request for 5 minutes, terminate them and use crash recovery to restore behavior
This should be a last stop-gap measure in case sourcekitd or clangd get stuck, don’t respond to any requests anymore and don’t honor cancellation either. In that case we can restore SourceKit-LSP behavior by killing them and using the crash recovery logic to restore functionality.

rdar://149492159
2025-05-07 13:43:28 +02:00
Alex Hoppen
f433f58448 Miscellaneous small cleanups 2025-04-23 18:54:45 +02:00
Alex Hoppen
82c5fa9789 Remove snapshotFromDisk
The function isn’t used anymore
2025-04-23 18:54:45 +02:00
Alex Hoppen
d8aeeaffe6 Only pass key and not value to LRUCache.removeAll(where:)
The value isn’t needed here and the calls become cleaner if only the key is passed.
2025-04-23 18:54:45 +02:00
Alex Hoppen
bc4d9c78e7 Remove public modifiers from MarkdownTitleFinder 2025-04-23 18:54:45 +02:00
Alex Hoppen
1355b203c0 Use on-disk contents of a source file to get the position of a symbol occurrence
The index refers to on-disk locations and since the cursor info below also operates on the on-disk contents, we should use the on-disk contents of the file to convert the symbol occurrence location to a `Position`.
2025-04-23 18:54:45 +02:00
Alex Hoppen
024efc2fa1 Remove dependency from SourceKitLSP on swift-docc-symbolkit
This way all dependencies on the `docc` libraries are wrapped inside the `DocCDocumentation` module.
2025-04-23 18:54:45 +02:00
Alex Hoppen
bbbc93ea01 Refactor cursorInfoFromDisk to share the underlying logic of invoking cursor info 2025-04-23 18:54:42 +02:00
Matthew Bastien
4fb5323bd4 add cursorInfoFromDisk() to SwiftLanguageService 2025-04-22 15:14:36 -04:00
Matthew Bastien
2ae2e709b3 add LRUCache struct to SKUtilities 2025-04-17 13:46:01 -04:00
Matthew Bastien
c24f92d73e add documentation for certain functions 2025-04-16 15:13:04 -04:00
Matthew Bastien
c37c596562 fix newline matching 2025-04-16 14:54:55 -04:00
Matthew Bastien
131c8113d5 add logging to SwiftLanguageService.doccDocumentation(_:) 2025-04-16 14:54:55 -04:00
Matthew Bastien
1c65bda727 remove some nesting levels in DocumentationLanguageService.doccDocumentation(_:) 2025-04-16 14:54:55 -04:00
Matthew Bastien
0ea0e00c55 use LinkCompletionTools to parse SwiftDocC symbol links 2025-04-16 14:44:13 -04:00
Matthew Bastien
4e06c36c70 organize imports 2025-04-16 14:44:13 -04:00
Matthew Bastien
8c15e27959 use a helper document in cursorInfo() 2025-04-16 14:44:12 -04:00
Matthew Bastien
1ca1441054 fix some review comments 2025-04-16 14:44:12 -04:00
Matthew Bastien
0adaf2581f more robust searching for DocC catalogs 2025-04-16 14:44:12 -04:00
Matthew Bastien
a8eae3c6d8 remove protocols from DocCDocumentation module 2025-04-16 14:44:12 -04:00
Matthew Bastien
c1a6e65efd add CMake build to DocCDocumentation module 2025-04-16 14:44:11 -04:00
Matthew Bastien
49b3f531eb move SwiftDocC related functionality into its own module 2025-04-16 14:44:11 -04:00
Matthew Bastien
24118ebc78 cleanup unused code 2025-04-16 14:44:11 -04:00
Matthew Bastien
39bf4852b0 handle Markdown and Tutorial files in textDocument/doccDocumentation 2025-04-16 14:44:11 -04:00
Alex Hoppen
254b42a406 Merge pull request #2098 from ahoppen/swift-format-crashing
Don’t crash SourceKit-LSP if swift-format crashes while we write the source file to stdin
2025-03-28 14:17:51 -07:00
Alex Hoppen
24f361cda2 Merge pull request #2093 from ahoppen/remove-dynamically-loaded-sourcekitd
Remove the split between `SourceKitD` and `DynamicallyLoadedSourceKitD`
2025-03-28 14:17:27 -07:00
Alex Hoppen
f3daf21802 Don’t crash SourceKit-LSP if swift-format crashes while we write the source file to stdin
When swift-format crashes before we send all data to its stdin, we get a SIGPIPE when trying to write more data to its studio on Linux. This, in turn, takes SourceKit-LSP down.

Do the same trick that we do when launching `JSONRPCConnection` of disabling SIGPIPE globally if we can’t disable it for individual pipes.

rdar://147665695
2025-03-27 21:47:33 -07:00
Alex Hoppen
374554bde7 Merge pull request #2092 from ahoppen/official-synchronization
Make `workspace/synchronize` a non-experimental request
2025-03-27 15:05:22 -07:00
Alex Hoppen
92aa94fa43 Remove the split between SourceKitD and DynamicallyLoadedSourceKitD
There is only one real class that implements the `SourceKitD` protocol, so there really isn’t any need for the protocol + class split at all. Unify them to make code simpler to reason about.
2025-03-27 11:05:24 -07:00
Alex Hoppen
e474354bca Merge pull request #2051 from ahoppen/build-graph-generation
Don't wait for build graph generation when file is changed
2025-03-26 14:40:06 -07:00
Alex Hoppen
73016af24e Make workspace/synchronize a non-experimental request
This request is generally useful, not only for tests within SourceKit-LSP but also:
- In editor tests that want to test the integration with SourceKit-LSP
- In code analysis tools that want to gather project information using SourceKit-LSP and need an up-to-date index for that.

Remove the experimental feature guard from `workspace/_synchronize`, consequently rename it to `workspace/synchronize` and only guard the `buildServerUpdates` option on the synchronize request by an experimental feature because its long-term usefulness is still not fully understood yet.
2025-03-26 10:08:20 -07:00
Alex Hoppen
3bb4690db4 Terminate pending background indexing and preparation tasks when shutting down SourceKit-LSP
When SourceKit-LSP is shut down, we should make sure that we don’t leave behind child processes, which will become orphans after SourceKit-LSP has terminated. What’s worse, when SourceKit-LSP has exited, these processes might not have any process to read their stdout/stderr, which can lead to them running indefinitely.

This change does not cover the termination of subprocess trees. For example, if we launch `swift build` and need to kill it because it doesn’t honor SIGINT, its child processes will still live on. Similarly, if we kill a BSP server, its child processes might live on. Fixing this is a drastically bigger endeavor, likely requiring changes to Foundation and/or TSC. I filed https://github.com/swiftlang/sourcekit-lsp/issues/2080 for it.
2025-03-25 14:10:38 -07:00
Alex Hoppen
e6ca874c1a Merge pull request #2086 from ahoppen/generated-interface-diags
Don’t return diagnostics for generated interfaces
2025-03-25 09:10:46 -07:00
Alex Hoppen
686c225520 Don’t return diagnostics for generated interfaces
Trying to get diagnostics for generated interfaces fails with: `'<…>' is not part of the input files`

rdar://146949806
2025-03-21 17:55:54 -07:00
Alex Hoppen
dd2d2aff49 Fix some more quadratic performance issues in AsyncQueue
We would hit quadratic behavior in `AsyncQueue` when the build system floods us with `build/logMessage` or `build/task(Start|Progress|Finish)` notifications because we record a dependency on all of the pending log message handling tasks.

We can extend the improvement made in https://github.com/swiftlang/sourcekit-lsp/pull/1840 to fix this quadratic problem: If the current task depends on a task with metadata that depends on itself (ie. all tasks of metadata that needs to be executed in-order), we only need to depend on the last task with that metadata.

This covers many message types and we can now only get into quadratic behavior if we get flooded with two different kinds of messages: One that does not have a self-dependency and one that depends on the message without a self-dependency. In terms of LSP messages, this could be a document read followed by a document update, but I think this is a lot more unlikely than getting spammed with one type of message.
2025-03-21 17:33:55 -07:00
Alex Hoppen
dcad3f4fd6 Don't wait for build graph generation when file is changed
Since we re-index source files if the build server sends us a `buildTarget/didChange` notification, we no longer need to wait for an up-to-date build graph when a file is modified. This resolves an issue that causes a `Scheduling tasks` progress to appear in the status bar whenever a file in the project is changed. Before https://github.com/swiftlang/sourcekit-lsp/pull/1973, this happened fairly frequently during the initial indexing when a header file was written into the build directory. After that PR the `Scheduling Indexing` status appears a lot more frequently, namely every time the index’s database is modified, which happens quite all the time during indexing...
2025-03-18 14:03:42 -07:00
Alex Hoppen
d10c868497 Support indexing a file in the context of multiple targets
If a source file is part of multiple targets, we should index it in the context of all of those targets because the different targets may produce different USRs since they might use different build settings to interpret the file.
2025-03-14 15:49:59 -07:00
Alex Hoppen
3cd38658cb Merge pull request #2065 from ahoppen/refresh-diags-sourcekitd-restored
Refresh diagnostics when sourcekitd has been restored
2025-03-14 15:11:30 -07:00
Alex Hoppen
1f1e440dd8 Merge pull request #2060 from ahoppen/synchronize-request
Generalize `PollIndexRequest` and `BarrierRequest` into a single `SynchronizeRequest`
2025-03-14 15:10:13 -07:00
Alex Hoppen
6c74631aca Refresh diagnostics when sourcekitd has been restored
After sourcekitd has been restored, we can provide diagnostics again, so tell the editor to reload them.
2025-03-13 21:17:48 -07:00
Alex Hoppen
9c867df103 Merge pull request #2057 from ahoppen/test-timeout
Add a few timeout checks to tests
2025-03-13 13:46:06 -07:00
Alex Hoppen
5fba1699bd Generalize PollIndexRequest and BarrierRequest into a single SynchronizeRequest
This new request also allows us to wait for build system updates without waiting for background indexing to finish.
2025-03-12 14:25:50 -07:00
Alex Hoppen
d645f44735 Merge pull request #2054 from ahoppen/file-change-freestanding
Handle file did change notifications as freestanding messages
2025-03-12 14:21:42 -07:00