Commit Graph

230 Commits

Author SHA1 Message Date
Alex Hoppen
bbbc93ea01 Refactor cursorInfoFromDisk to share the underlying logic of invoking cursor info 2025-04-23 18:54:42 +02: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
39bf4852b0 handle Markdown and Tutorial files in textDocument/doccDocumentation 2025-04-16 14:44:11 -04: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
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
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
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
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
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
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
Alex Hoppen
655a93f05a Add structure to the index logs
When the client supports it, communicate the structure of tasks that were stared during background indexing or by the build server to the client. If there are multiple operations happening in parallel, this allows the client to display them in separate log tracks instead of interspersing them with the emoji prefixes like we do today.
2025-03-04 16:36:26 -08:00
Alex Hoppen
6818cbe45a Log a few strings publicly
Just something I noticed while reading logs
2025-03-03 13:29:29 -08:00
Alex Hoppen
6a1d923f5b Add a request to check if SourceKit-LSP is currently performing any indexing 2025-02-27 12:52:28 -08:00
Alex Hoppen
9496b49c72 Add an experimental request to return the build settings that SourceKit-LSP uses to process a file
This can be useful to IDEs that want to perform some additional semantic processing of source files, which requires knowledge of a file’s build settings.
2025-02-26 09:12:47 -08:00
Alex Hoppen
baa3b70f7c A couple refinements to the window/didChangeActiveDocument notification
- Clarify that this must only be called with documents that are open in SourceKit-LSP and add a check for that.
- Allow sending `null` to indicate that no SourceKit-LSP document is currently active.
- Cancel preparation tasks for other workspaces that don’t contain the currently active document.
2025-02-24 13:58:19 -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
f1aeb6c196 Add an experimental request to pause background indexing
This request allows IDEs to disable SourceKit-LSP’s background indexing functionality when it requires all compute resources for other, more interactive, tasks.
2025-02-21 08:09:34 -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
Alex Hoppen
f6b83dbb1e Support completionItem/resolve to compute documentation of code completion item
Fixes #1935
2025-02-05 10:26:44 -08:00
Alex Hoppen
fc100d24bf Cache the mapping from compiler to toolchain
While at it, also make `Toolchain.path` non-optional and clean up `ToolchainRegistry.init` slightly.
2025-01-25 21:32:44 -08:00
Alex Hoppen
ed098f58cb Merge pull request #1934 from ahoppen/multi-toolchain-support
Support opening documents within the same workspace with sourcekitd/clangd from different toolchains
2025-01-25 08:52:52 -08:00
Alex Hoppen
98b1294ad9 Support opening documents within the same workspace with sourcekitd/clangd from different toolchains
rdar://142909783
2025-01-24 22:32:05 -08:00
Alex Hoppen
12c225c00b Merge pull request #1936 from ahoppen/flush-nondarwin-logger-shutdown
Flush the `NonDarwinLogger` before shutting down `SourceKitLSPServer`
2025-01-21 15:23:00 -08:00
Alex Hoppen
f7ab6c5e71 Flush the NonDarwinLogger before shutting down SourceKitLSPServer
This ensures that we don't drop any log messages when stopping the LSP server, in particular while running tests.
2025-01-20 19:56:25 -08:00
Alex Hoppen
aeb6c14659 Merge pull request #1851 from matthewbastien/convert-documentation
Add `textDocument/doccDocumentation` request
2025-01-20 08:31:59 -08:00
Ben Barham
0c896696c9 Allow workspace options to affect build system search
There were a few places that options only took place *after* determining
a build system, even though we have multiple that impact the search (eg.
`defaultBuildSystem` and `searchPaths`).

Additionally track project root and configuration paths separately, so
that when searching for implicit workspaces we can make sure to skip
creating duplicates.
2025-01-17 08:36:36 -08:00
Matthew Bastien
f6bec67672 add canImport check around SourceKitLSPServer.doccDocumentation(_:) 2025-01-17 11:11:56 -05:00
Matthew Bastien
4b9288a97a clean up request forwarding 2025-01-17 11:11:55 -05:00
Matthew Bastien
f03ae0bb88 rename request to textDocument/doccDocumentation 2025-01-17 11:11:55 -05:00
Matthew Bastien
6ed5cbef14 minor code quality improvements 2025-01-17 11:11:54 -05:00
Matthew Bastien
d4b63a2af5 add textDocument/convertDocumentation request to SourceKit-LSP 2025-01-17 11:11:54 -05:00
Alex Hoppen
31b1909ce1 Allow injection of build systems into SourceKitLSP
This allows us to clean up the creation of `TestBuildSystem` a little bit because the tests can create `TestBuildSystem` instead of retrieving it from the `BuildSystemManager`.

rdar://142906050
2025-01-15 15:57:21 -08:00
Alex Hoppen
760be317bc Avoid logging options for a workspace twice
We are already logging the options below.
2025-01-15 09:55:48 -08:00
Alex Hoppen
48389c75a2 Merge pull request #1912 from ahoppen/reduce-swiftpm-dependency
Support building SourceKit-LSP without a dependency on SwiftPM
2025-01-09 13:10:44 +01:00
Alex Hoppen
718c0ee809 Remove imports of SwiftPM modules that are not strictly necessary 2025-01-08 12:43:43 +01:00
Alex Hoppen
17e2db073c Merge pull request #1909 from ahoppen/cache-container-names
Cache container names in `CheckedIndex`
2025-01-08 09:37:30 +01:00
Alex Hoppen
2a0902bb20 Cache container names in CheckedIndex
It is important that we cache this because we might find a lot of symbols in the same container for eg. workspace symbols (eg. consider many symbols in the same C++ namespace). If we didn't cache this value, then we would need to perform a `primaryDefinitionOrDeclarationOccurrence` lookup for all of these containers, which is expensive.

For example, searching for `only` in SourceKit-LSP’s codebase used to not return results in more than 20s (after which I gave up) and now returns >8000 results in <2s.

rdar://141412138
2025-01-03 16:00:22 +01:00
Alex Hoppen
2f53e7cf16 Remove SourceKitLSPServer.openGeneratedInterface
The method was never called.
2025-01-03 15:09:40 +01:00
Alex Hoppen
f653ef3255 Merge pull request #1887 from ahoppen/generated-interface-reference-document
Support semantic functionality in generated interfaces if the client supports `getReferenceDocument`
2025-01-03 14:35:01 +01:00
Alex Hoppen
8d73731bcb Support semantic functionality in generated interfaces if the client supports getReferenceDocument
This allows us to provide semantic functionality inside the generated interfaces, such as hover or jump-to-definition.

rdar://125663597
2025-01-02 20:29:36 +01:00
Alex Hoppen
e59df13bb0 Clear inProgressTextDocumentRequests on textDocumentTrackingQueue
`inProgressTextDocumentRequests` is supposed to only be accessed on `textDocumentTrackingQueue` but we were accessing it outside of that queue. Because of this, we might try to remove requests from `inProgressTextDocumentRequests` before adding them, which would cause them to stay in the list indefinitely.
2025-01-02 13:23:18 +01:00
Alex Hoppen
87af5b06f1 Merge pull request #1857 from ahoppen/no-implicit-completion-cancellation 2024-12-07 08:56:38 -08:00
Alex Hoppen
5183889e7e Merge pull request #1872 from ahoppen/no-background-indexing-warning
Don’t show warning message when opening projects that don't support background indexing
2024-12-06 18:16:23 -08:00
Alex Hoppen
cbd897de03 Don’t show warning message when opening projects that don't support background indexing
Since we enabled background indexing by default, the user is no longer explicitly opting into it. A user might be exclusively working with compilation database projects or BSP server without background indexing support and thus not care that we switched the background indexing default. We shouldn’t bother them with a warning message every time they launch sourcekit-lsp.
2024-12-06 12:12:26 -08:00
Alex Hoppen
751291e14f Only show call-like occurrences in call hierarchy.
`extension MyTask: AnyTask {}` includes an occurrence of `MyTask.cancel` to mark it as an override of `AnyTask.cancel` but we shouldn't show the extension in the call hierarchy.
2024-12-06 08:05:50 -08:00
Alex Hoppen
990ec7fc2a Don’t implicitly cancel code completion requests on document edits
As the user types, we filter the code completion results. Cancelling the completion request on every keystroke means that we will never build the initial list of completion results for this code completion session if building that list takes longer than the user's typing cadence (eg. for global completions) and we will thus not show any completions.
2024-12-05 14:43:56 -08:00