Commit Graph

1141 Commits

Author SHA1 Message Date
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
Alex Hoppen
209fb1b602 Merge pull request #2053 from ahoppen/index-progress
Don't increment in-progress task counter for files that cannot be indexed
2025-03-12 14:21:34 -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
55b514f6a4 Log the source files that are marked in-progress when updating the index status
If we have a bug in index status tracking, this helps figure out which files are considered to be currently indexed.
2025-03-11 08:31:21 -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
ce75053555 Handle file did change notifications as freestanding messages
Technically, the watched files notification can change the response of any other request (eg. because a target needs to be re-prepared). But treating it as a `globalConfiguration` inserts a lot of barriers in request  handling and significantly prevents parallelism. Since many editors batch file change notifications already, they might have delayed the file change notification even more, which is equivalent to handling the  notification a little later inside SourceKit-LSP. Thus, treating it as `freestanding` should be acceptable.

Also, simplify the logic needed in tests to write modified files to disk because we now need to run a barrier request in tests to ensure that the watched file notification has been handled.
2025-03-10 21:44:35 -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
2a1fd10295 Add an experimental LSP request to return the output paths for all files in a target 2025-03-06 08:30:47 -08:00
Alex Hoppen
2a12d21378 Merge pull request #2036 from ahoppen/log-invalid-language
Add log message if we can’t infer the language server type for a document that was opened
2025-03-05 23:50:46 -08:00
Alex Hoppen
9f5f06bc57 Merge pull request #2032 from ahoppen/ahoppen/response-file-indexing
Use response files to index files if argument list exceeds maximum number of arguments
2025-03-05 23:50:33 -08:00
Alex Hoppen
2bb79e3888 Add log message if we can’t infer the language server type for a document that was opened
Motivated by https://github.com/swiftlang/sourcekit-lsp/issues/2028#issuecomment-2702162160.
2025-03-05 13:53:28 -08:00