Commit Graph

555 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
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
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
0ea0e00c55 use LinkCompletionTools to parse SwiftDocC symbol links 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
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
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
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
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
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
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
572660ae26 Add timeouts to most subprocess calls in tests
Just a speculative fix to avoid timeouts during the `swift test` invocation
2025-03-11 09:20:44 -07:00
Alex Hoppen
bdd6ab1ecc Merge pull request #2048 from ahoppen/diag-refresh-capability
Do not send `DiagnosticsRefreshRequest` to the client if it doesn't support it
2025-03-11 02:42:38 -07:00
Alex Hoppen
776d019ec9 Do not send DiagnosticsRefreshRequest to the client if it doesn't support it
Check if the client's capabilities to see if it supports `workspace/diagnostic/refresh`.
2025-03-10 14:11:23 -07:00
Alex Hoppen
8aa8fa0ff8 Remove offensive terms from the codebase 2025-03-07 13:58:02 -08:00
Alex Hoppen
1cfa8db1d8 Require Swift 6 to build SourceKit-LSP
This significantly cleans up our `import` statements
2025-03-07 08:05:49 -08:00
Alex Hoppen
698b384a8b Add - to swift-format invocation to indicate that file contents should be read from stdin
To match https://github.com/swiftlang/swift-format/pull/914
2025-03-06 22:53:26 -08:00
Alex Hoppen
5541060451 Use response files to index files if argument list exceeds maximum number of arguments 2025-03-05 13:33:40 -08:00
Alex Hoppen
bd6fb5d04c Do not block initialization of the build server when build server is unresponsive in returning the list of test files
We were blocking the initialization response on `self.buildSystemManager.testFiles`, which requires the list of test files to be determined. Make that operation asynchronous so that a slow build server can’t take down all of SourceKit-LSP.
2025-02-26 16:31:29 -08:00
Alex Hoppen
0258d1dd63 Merge pull request #2007 from ahoppen/dont-cache-failed-diag-reports
Do not cache diagnostic reports for sourcekitd requests that have failed
2025-02-26 16:05:42 -08:00
Alex Hoppen
abea29c9fa Do not cache diagnostic reports for sourcekitd requests that have failed
Otherwise, we return the failed diagnostic report even after sourcekitd has been restored.

Also, make sure that we don't show the `semantic editor is disabled` error to users.
2025-02-25 20:29:21 -08:00
Alex Hoppen
1209747496 Merge pull request #2001 from ahoppen/add-call-with-no-defaulted-arguments
Add calls with no defaulted arguments to code completion results
2025-02-25 19:53:08 -08:00
Alex Hoppen
bcdf91cf5e Add calls with no defaulted arguments to code completion results
The completion items that don’t have any of the defaulted arguments disappeared when we switched to the SourceKit plugin.
2025-02-25 14:59:17 -08:00
Alex Hoppen
9339791e83 Set useNewAPI when closing a code completion session
Otherwise, the close does not get handled by the SourceKit plugin. In practice, it doesn’t matter too much because the SourceKit plugin will implicitly close the last completion session when a new one is opened but we should fix this.
2025-02-25 08:04:58 -08:00
Alex Hoppen
1d1f1fb3dc Merge pull request #1989 from ahoppen/didchangactivedocument
Add notification to inform SourceKit-LSP about the currently active document
2025-02-23 21:27:23 -08:00
Alex Hoppen
4d00c9089b Add notification to inform SourceKit-LSP about the currently active document
SourceKit-LSP prepares the currently active file for editor functionality and currently infers the currently active document from whichever received the last `TextDocumentRequest`.

If an editor is capable of doing so, it should be able to report the document that the user currently has focused so that SourceKit-LSP does not have to infer this information from other requests.

Also clean up some handling code for experimental capabilities.
2025-02-20 12:29:30 -08:00
Matthew Bastien
151ac12463 add target name to command arguments 2025-02-20 11:20:05 -05:00
Matthew Bastien
96d8dd09b6 add target display name to run and debug code lenses 2025-02-20 11:20:05 -05:00