Commit Graph

92 Commits

Author SHA1 Message Date
Alex Hoppen
ea1f1879d2 Merge pull request #2082 from ahoppen/cancel
Send CancelRequestNotification if we time out a request in `TestSourceKitLSPClient`
2025-03-24 13:27:58 -07:00
Alex Hoppen
37b8b06732 Send CancelRequestNotification if we time out a request in TestSourceKitLSPClient 2025-03-21 15:22:38 -07:00
Alex Hoppen
6feab14ee2 Add a timeout to the semaphore we use for shutting down SourceKit-LSP 2025-03-20 10:30:34 -07:00
Alex Hoppen
b757fb9806 Merge pull request #2069 from ahoppen/test-request-timeout
Add a timeout for requests sent from `TestSourceKitLSPClient`
2025-03-17 17:07:32 -07:00
Alex Hoppen
1f5cb45b32 Add a timeout for requests sent from TestSourceKitLSPClient
Otherwise, if a SourceKit-LSP request hangs, we would hang the test execution.
2025-03-17 11:16:24 -07:00
Alex Hoppen
6a3afeaaa0 Remove trailing comma
This restores the ability to build SourceKit-LSP using a Swift 6.0 compiler
2025-03-14 15:52:12 -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
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
1cd1102d89 Introduce defaultTimeoutDuration to get the default timeout as a Duration 2025-03-11 09:20:44 -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
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
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
b33a42f0ab When using SOURCEKIT_LSP_TEST_PLUGIN_PATHS=RELATIVE_TO_SOURCEKITD infer plugin paths from default testing toolchain
Otherwise, we infer the SourceKit plugin paths from the toolchain when creating a `SourceKitLSPServer` during testing because we don’t override the plugin paths in the SourceKitLSPOptions. But when running `SourceKitDTests`, we pass `pluginPaths: nil`, which would not load any plugins. If both of the tests run in the same process, this causes a fault to get logged because sourcekitd can only loaded once per process and we can’t modify which plugins are loaded after the fact.
2025-02-05 08:23:04 -08:00
Alex Hoppen
8787787e4f Allow loading the SourceKit plugin from the toolchain during testing 2025-01-27 09:18:45 -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
aee36fdf6c Remove SkipUnless checks that always evaluate to true
We don’t support testing SourceKit-LSP using toolchains that don’t contain these features anymore.
2025-01-23 21:11:08 -08:00
Matthew Bastien
6675d275fe address review comments 2025-01-17 11:11:56 -05:00
Matthew Bastien
5c3136694f use built-in LSP ResponseError with code RequestFailed for errors 2025-01-17 11:11:55 -05:00
Matthew Bastien
af02df9af7 revert changes to TestSourceKitLSPClient 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
e5f1bbfc03 Set plugin paths in all tests
Otherwise, we were trying to load sourcekitd without the plugins for the normal SourceKIt-LSP tests and with the plugins for the plugin tests.
2025-01-09 14:09:01 +01:00
Alex Hoppen
5709e1a864 Add a SourceKit plugin to handle code completion requests
This adds a sourcekitd plugin that drives the code completion requests. It also includes a `CompletionScoring` module that’s used to rank code completion results based on their contextual match, allowing us to show more relevant code completion results at the top.
2025-01-03 14:21:54 +01:00
Alex Hoppen
c0c0f1f0a6 Skip tests that use background indexing when running tests with a Swift 5.10 toolchain
https://github.com/swiftlang/sourcekit-lsp/pull/1714 changed the background preparation mode to `enabled` but a Swift 5.10 toolchain does not support `--experimental-prepare-for-indexing`. Thus, these tests fail. Skip tests that rely on background indexing when testing SourceKit-LSP with a Swift 5.10 host toolchain.
2024-11-18 15:28:34 -08:00
Alex Hoppen
78f9968eec Merge pull request #1819 from ahoppen/notification-wait 2024-11-14 08:09:33 -08:00
Alex Hoppen
8c2def8ef9 Rename SKSupport to LanguageServerProtocolExtensions 2024-11-13 16:53:58 -08:00
Alex Hoppen
1f33ed484d Split SKUtilities from SKSupport 2024-11-13 16:53:54 -08:00
Alex Hoppen
bb6f4b4a47 Allow waiting for the next notification from SourceKit-LSP when the previous wait timed out
When `TestSourceKitLSPClient.nextNotification` timed out, it would cancel `AsyncSequence.Iterator.next()` and thus also cancel the underlying `AsyncStream` (which I only now found out). This means that calling `nextNotification` again would never return any notification. Hence, if we didn’t receive a `PublishDiagnosticsNotification` within the first timeout, we would never get one.
2024-11-13 16:53:08 -08:00
Alex Hoppen
2270ab9a6d Fix race condition that caused testMainFileChangesIfIncludeIsAdded to fail
In some situations, we could return the timeout error from the timeout task, but receive a notification from the `self.notifications` `AsyncStream`. That notification would then be dropped and never get delivered to the test case, which can cause test cases to fail.
2024-10-29 13:04:09 -07:00
Alex Hoppen
951e923245 Use withUnsafeFileSystemRepresentation to get the path of a URL on disk
`URL.path` returns forward slashes in the path on Windows (https://github.com/swiftlang/swift-foundation/issues/973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
2024-10-21 11:12:30 -07:00
Alex Hoppen
0c37cb3e34 Support workspace/diagnostic/refresh request from TestSourceKitLSPClient
Currently, we return a `methodNotFound` error when we get a diagnostic refresh request from SourceKit-LSP. This doesn’t do any harm but draws the attention when reading test logs, despite being the expected result. Clean up that output by returning a proper response.
2024-10-15 18:33:05 -07:00
Alex Hoppen
2623b4949d Use the test’s default timeout duration for sourcekitd timeouts
Otherwise, we are stuck with the timeout default of 120s and the test runner can’t increase it.
2024-10-09 13:55:18 -07:00
Alex Hoppen
947e5269c4 Reduce the number of public imports 2024-09-30 07:50:12 -07:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
23c37ed47a Add method to extract DocumentPositions and text without markers from marked text 2024-09-17 11:48:38 -07:00
Alex Hoppen
3d95375043 Use a LocalConnection to communicate between BuildSystemManager and BuildSystem 2024-09-15 16:28:12 -07:00
Alex Hoppen
b4d04ce983 Introduce a BuiltInBuildSystemAdapter that can be used to transition BuildSystem to a type that implements BSP 2024-09-09 16:31:00 -07:00
Alex Hoppen
d86a32bc19 Remove custom decoding function from SourceKitLSPOptions
We forgot to decode the following keys in the custom decode function, which meant that you couldn’t set them using SourceKit-LSP’s `config.json` file.
- `backgroundPreparationMode`
- `sourcekitdRequestTimeout`
- `cancelTextDocumentRequestsOnEditAndClose`

We had the custom decoder function so that the keys weren’t required in the JSON but we could access eg. `SwiftPMOptions` without needing to deal with optionals in the codebase.

Make the accesses to these nested options structs a little more verbose but eliminate the source of the above bug, which seems like a good tradeoff.
2024-09-06 13:45:24 -07:00
Alex Hoppen
6d34d70883 Split SourceKitLSPOptions out of SKCore
This only leaves build system functionality in SKCore, which allows us to rename SKCore.
2024-07-25 09:11:13 -07:00
Alex Hoppen
cfe18f1256 Split toolchain-related functionality out of SKCore 2024-07-25 09:11:13 -07:00
Alex Hoppen
1ef71cf663 Merge LSPTestSupport and SKTestSupport 2024-07-25 09:11:13 -07:00
Alex Hoppen
2877675bd5 Adopt package access level
Change a l public declarations to the `package` access level, accept for:
- The `LanguageServerProtocol` module
- The `BuildServerProtocol` module
- `InProcessClient.InProcessSourceKitLSPClient`
- `LanguageServerProtocolJSONRPC` (I would like to create a more ergonomic API for this like `InProcessSourceKitLSPClient` in the future, but for now, we’ll leave it public)

Unfortunately, our pattern of marking functions as `@_spi(Testing) public` no longer works with the `package` access level because declarations at the `package` access level cannot be marked as SPI. I have decided to just mark these functions as `package`. Alternatives would be:
- Add an underscore to these functions, like we did for functions exposed for testing before the introduction of `SPI`
- Use `@testable` import in the test targets and mark the methods as `internal`

Resolves #1315
rdar://128295618
2024-07-19 09:54:30 -07:00
Alex Hoppen
c6b82a7556 Fix a compilation issue caused by #1533 and #1524 racing 2024-06-28 22:54:52 +02:00
Alex Hoppen
d8e0fff6da Make background indexing a proper option in SourceKitLSPOptions
This allows us to flip the default in the future more easily. It also allows users to disable background indexing when it’s enabled by default.

rdar://130280855
2024-06-28 10:23:29 +02:00
Alex Hoppen
d1cddb8c41 Allow configuring of SourceKit-LSP’s options using .sourcekit-lsp configuration files
The idea here is to unify the different ways in which we can currently set options on SourceKit-LSP in a scalable way: Environment variables, command line arguments to `sourcekit-lsp` and initialization options.

The idea is that a user can define a `~/.sourcekit-lsp/.sourcekit-lsp` file (we store logs in `~/.sourcekit-lsp/logs` on non-Darwin platforms), which will be used as the default configuration for all SourceKit-LSP instances. They can also place a `.sourcekit-lsp` file in the root of a workspace to configure SourceKit-LSP for that project specifically, eg. setting arguments that need to be passed to `swift build` for that project and which thus also need to be set on SourceKit-LSP.

For compatibility reasons, I’m mapping the existing command line options into the new options structure for now. I hope to delete the command line arguments in the future and solely rely on `.sourcekit-lsp` configuration files.

Environment variable will be migrated to `.sourcekit-lsp` in a follow-up commit.
2024-06-27 17:36:16 +02:00
Alex Hoppen
5d42fcde17 Add a variant of send to TestSourceKitLSPClient that allows implicit discarding of VoidResponse
Cleans up tests slightly.
2024-06-25 03:41:07 -07:00
Alex Hoppen
8642768902 Fix a few Swift concurrency warnings 2024-06-18 18:07:22 -07:00
Alex Hoppen
c43cffd044 Change all variables that are Atomic* types to not be nonisolated(unsafe)
Since the `Atomic*` types can not be marked as `Sendable` (because they aren’t C structs), we can change the variables to constants and can remove `nonisolated(unsafe)`.
2024-06-07 08:49:10 -07:00