Commit Graph

33 Commits

Author SHA1 Message Date
Alex Hoppen
4883ee7088 Merge pull request #2088 from ahoppen/cancellation-issue
Wait for request to be sent to sourcekitd before cancelling it in `SwiftSourceKitPluginTests.testCancellation`
2025-03-26 14:39:25 -07:00
Alex Hoppen
0f5727f4f0 Introduce assertContains to check that a sequence/string contains an element/substring
This also prints the sequence and expected element on failure, which is useful for debugging.
2025-03-25 19:12:51 -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
64147963d0 Support cancellation in CustomBuildServer
I developed this for a test case that didn’t end up being useful. But supporting request cancellation here might come in useful in the future.
2025-03-10 15:25:50 -07:00
Alex Hoppen
5c60d1d39c Add a new test project type that uses a custom build server
This allows us to more easily test behavior for build servers that have different behavior than SwiftPM and compile commands without having to implement the build server in Python.
2025-03-05 23:54:32 -08:00
Alex Hoppen
0a54c25785 Merge pull request #1999 from ahoppen/schedule-initial-syntactic-test-population
Do not block initialization of the build server when build server is unresponsive in returning the list of test files
2025-02-28 15:36:17 -08:00
Alex Hoppen
112252632d Make response of workspace/_sourceKitOptions request non-optional
The response was not specified as being optional and shouldn’t be.
2025-02-27 19:03:50 -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
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
8c2def8ef9 Rename SKSupport to LanguageServerProtocolExtensions 2024-11-13 16:53:58 -08:00
Alex Hoppen
64024f6cd7 Don’t rely on timers for BSP target / settings change tests
The timers were racy and on Windows we would get the updated build targets / build settings before we expect them. Change the tests to explicitly tell the build server when to change the targets / settings it reports by sending it a `workspace/didChangeWatchedFiles` notification.

This should also speed up the tests because we don’t have a 1s timer anymore.
2024-10-24 18:00:41 -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
ee1fc93b7c Remove dependency on ISDBTestSupport
We weren’t using it anymore anyway.
2024-10-17 11:09:39 -07:00
Rajveer
7b1f59e4a3 Update BSP connection build server config lookup path
Resolves #1695

Adopt `<workspace_root>/.bsp` search locations in addition to
`<workspace_root>/`.
2024-10-14 13:22:22 -07:00
Alex Hoppen
c16e33d281 Miscellaneous adjustments to make tests pass on Windows
This is mostly test infrastructure that needed adjusting.
2024-10-10 09:28:26 -07:00
Alex Hoppen
dff72f1807 In withTaskPriorityChangedHandler execute the task that watches for priority changes with high priority
I saw a nondeterministic test failure of `AsyncUtilsTests.testWithTimeoutEscalatesPriority` and I believe this was the cause.

Also refactor a few test helper functions on the way.
2024-10-04 09:57:52 -07:00
Alex Hoppen
f09f7e8714 Improve BuildServerBuildSystemTests.testCrashRecovery
The original idea behind this test was that only opening `Crash.swift` would retrieve build settings for `Crash.swift`. But that wasn’t actually true: Scanning for tests also retrieved build settings (to get the test’s module name). This caused test failures if we set `SOURCEKIT_LSP_TEST_TIMEOUT: 10`, like we do in `settings.json`.

Improve the test to actually check that the BSP server has crashed and increase timeout to be bigger than the 10s restart delay.
2024-09-27 10:58:50 -07:00
Alex Hoppen
2b3d733af6 Restart a BSP server after it has crashed
If a BSP server crashes, we should try to relaunch it. Use a similar relaunch logic as the one we use for `clangd`: Try restarting immediately unless the BSP server has crashed within the last 30 seconds, in which case we delay the restart by 10s.

rdar://136311009
Fixes #1686
2024-09-25 13:57:43 -07:00
Alex Hoppen
1fd700b810 Expose all BSP messages used by SourceKit-LSP to BSP servers
The interaction to an out-of-process BSP server still went through the `BuildServerBuildSystem`, which doesn’t forward all messages to the build system and uses the old push-based model for build settings.

If we discover that the BSP server supports the new pull-based build settings model, we now forward all methods to it directly, without going through `BuiltInBuildSystemAdapter`, which has been renamed to `LegacyBuildServerBuildSystem`.

rdar://136106323
rdar://127606323
rdar://126493405
Fixes #1226
Fixes #1173
2024-09-24 22:47:07 -07:00
Alex Hoppen
5202a8fc1c Add test cases that launch a SourceKitLSP server using a BSP server 2024-09-20 17:15:34 -07:00
Alex Hoppen
316790ff7a Review BuiltInBuildSystem 2024-09-16 10:12:34 -07:00
Alex Hoppen
85b2f1fd30 Review BuildServerProtocol module for consistency 2024-09-16 10:10:26 -07:00
Alex Hoppen
5870ad9eb4 Implement InverseSourcesRequest in BuildSystemManager
`buildTarget/inverseSources` is not required to be implemented by BSP servers and we have almost all information needed for it in `BuildSystemManager`.

This also makes sure that `buildTarget/sources` and `buildTarget/inverseSources` actually match each other. Before this change, we had source files like `Package.swift` for which we returned a target from `buildTarget/inverseSources` but that weren’t part of that target’s sources retrieved using `buildTarget/sources`.
2024-09-16 10:08:14 -07:00
Alex Hoppen
6cc2cc4e95 Implement reloadPackageStatusCallback using BSP messages 2024-09-15 16:28:12 -07:00
Alex Hoppen
022a6de6c3 Handle filesDependenciesUpdated in BuildSystemManager instead of the build system
The implementation of which file’s dependencies have been updated is common across all build systems and thus build systems shouldn’t need to implement this logic. This also allows us to remove `BuildSystemDelegate`.
2024-09-12 07:34:12 -07:00
Alex Hoppen
7e3f453a7c Remove registerForChangeNotifications
This was only really used for the legacy BSP integration, which we are phasing out in favor of the new `SourceKitOptions` request.
2024-09-11 08:40:12 -07:00
Alex Hoppen
236f566977 Instead of having FileHandlingCapability for a source file, check if it belongs to any targets 2024-09-11 08:27:12 -07:00
Alex Hoppen
f9e468ffba Use BSP requests to get build settings of a source file 2024-09-10 09:30:36 -07:00
Alex Hoppen
ea21175dd7 Create BuildSystem in BuiltInBuildSystemAdapter
This finalizes the move of `BuiltInBuildSystem` creation into `BuiltInBuildSystemAdapter` and means that we can set the message handler of the `BuiltInBuildSystem` during initialization instead of using a setter method.
2024-09-09 18:00:05 -07:00
Alex Hoppen
b490a6fef1 Use buildTarget/inverseSources from BSP to get targets of a source file 2024-09-09 16:31:30 -07:00
Alex Hoppen
50a28bb86a Change FIXME and TODO comments to always have an associated issue
Do one of the following for every `FIXME` or `TODO` comment
- Add an issue that tracks the task
- Remove the comment if we are not planning to address it
2024-08-07 10:00:04 -07:00
Alex Hoppen
970b44d255 Remove a few @preconcurrency imports
rdar://132378792 is fixed
2024-07-31 17:25:20 -07:00
Alex Hoppen
66f2d86775 Rename SKCore to BuildSystemIntegration 2024-07-25 09:11:13 -07:00