Commit Graph

46 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
d5e254137c Make fulfillmentOfOrThrow take a variadic list of expectations
In almost all cases, we pass a single expectation and that looks a lot nicer with a variadic parameter.
2025-03-25 09:16:17 -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
28e3f99319 Allow a build system to use standardized paths while indexstore-db return realpaths
On Darwin platforms, this fixes the following problem: indexstore-db by itself returns realpaths but the build system might be using standardized Darwin paths (eg. realpath is `/private/tmp` but the standardized path is `/tmp`). Because of this, when inferring the main file for a file, we might get a URI that the build system doesn’t know about. To fix this, if the realpath that indexstore-db returns could not be found in the build system's source files but the standardized path is part of the source files, use the standardized path instead.
2025-03-03 21:16:14 -08:00
Alex Hoppen
f4e015b3c0 Merge pull request #1988 from ahoppen/sourcekitoptions
Add an experimental request to return the build settings that SourceKit-LSP uses to process a file
2025-02-26 16:06:20 -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
af62cbcfd3 Change the build server injection logic to inject a Connection instead of BuiltInBuildSystem
This gives the injected build system more flexibility by being able to respond to all BSP messages instead of only those methods defined in `BuiltInBuildSystem`.
2025-02-25 17:46:37 -08:00
Ben Barham
ab12429651 Update the compiler arguments used for background AST builds
This fixes two issues:
1. The SwiftPM build system was setup without passing through whether it
   should prepare or not. This meant that we lost eg. the argument to
   allow compiler errors when building the AST (even though it was set
   when building the modules)
2. The compiler argument adjustment to remove harmful and unnecessary
   flags only applied to indexing arguments, not those passed to the AST
   builds

Resolves rdar://141508656.
2025-02-07 11:57:30 -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
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
be546308ca Use URL in many cases where we used AbsolutePath
We made quite a few fixes recently to make sure that path handling works correctly using `URL` on Windows. Use `URL` in most places to have a single type that represents file paths instead of sometimes using `AbsolutePath`.

While doing so, also remove usages of `TSCBasic.FileSystem` an `InMemoryFileSystem`. The pattern of using `InMemoryFileSystem` for tests was never consistently used and it was a little confusing that some types took a `FileSystem` parameter while other always assumed to work on the local file system.
2024-11-18 18:19:48 -08:00
Alex Hoppen
9c84a344c8 Merge pull request #1817 from ahoppen/bsp-review 2024-11-14 08:10:02 -08:00
Alex Hoppen
8c2def8ef9 Rename SKSupport to LanguageServerProtocolExtensions 2024-11-13 16:53:58 -08:00
Alex Hoppen
0fbb6466e7 Make BuildSystemKind a struct and rename to BuildSystemSpec 2024-11-13 10:23:43 -08:00
Alex Hoppen
5bae73fca8 Use fallback build settings if build system doesn’t provide build settings within a timeout
When we receive build settings after hitting the timeout, we call `fileBuildSettingsChanged` on the delegate, which should cause the document to get re-opened in sourcekitd and diagnostics to get refreshed.

rdar://136332685
Fixes #1693
2024-10-16 10:55:29 -07:00
Alex Hoppen
36478d87ed Allow build systems to specify the files to watch for changes
rdar://136014553
Resolves #1671
2024-09-30 10:33:32 -07:00
Alex Hoppen
0f56e5f32e Simplify FallbackBuildSystem to a free function returning fallback arguments 2024-09-16 10:12:09 -07:00
Alex Hoppen
85b2f1fd30 Review BuildServerProtocol module for consistency 2024-09-16 10:10:26 -07:00
Alex Hoppen
765ea4878c Remove testSettingsChangedAfterUnregister 2024-09-16 10:10:26 -07:00
Alex Hoppen
cb2924a5fb Remove sourceFilesDidChange
This was equivalent to `buildTargetsDidChange`
2024-09-16 10:08:14 -07:00
Alex Hoppen
d00722e33f Use BSP to log messages from preparation in the build system 2024-09-16 10:06:35 -07:00
Alex Hoppen
8ac405cb19 Make BuildSystemManager.buildSystem and BuiltInBuildSystemAdapter.underlyingBuildSystem private 2024-09-16 10:06:35 -07:00
Alex Hoppen
6cc2cc4e95 Implement reloadPackageStatusCallback using BSP messages 2024-09-15 16:28:12 -07:00
Alex Hoppen
66f24e3554 Introduce buildSystemTestHooks 2024-09-15 16:28:12 -07:00
Alex Hoppen
3d95375043 Use a LocalConnection to communicate between BuildSystemManager and BuildSystem 2024-09-15 16:28:12 -07:00
Alex Hoppen
a96c0913ad Implement addSourceFilesDidChangeCallback in BuildSystemManager 2024-09-13 11:12:40 -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
3a118980b4 Migrate BuildSystem.prepare to a BSP request 2024-09-11 09:48:50 -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
9f4088038c Create BuiltInBuildSystem in BuildSystemManager
This moves the creation another step closer to creating the `BuiltInBuildSystem` inside `BuiltInBuildSystemAdapter`.
2024-09-09 18:00:05 -07:00
Alex Hoppen
6a9dcd2349 Split determining which build system to use for a workspace and the workspace creation
This allows us to create the build system from a `BuiltInBuildSystemAdapter` when it receives an `InitializeRequest`, which will be done in a follow-up commit.
2024-09-09 17:42:15 -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
63c5ca4a2c Use BuildTargetIdentifier from BSP instead of ConfiguredTarget 2024-09-09 16:31:00 -07:00
Alex Hoppen
e38d37e01c Use workspace/didChangeWatchedFiles from BSP to communicate file changes to the build system 2024-09-09 16:31:00 -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
fd0573e4b8 Rename BuildSystem to BuiltInBuildSystem 2024-09-09 16:30:13 -07:00
Alex Hoppen
4d1fa7a7ee Fix a race condition that could cause the build graph to not be generated when doing initial background indexing
We were making the initial `generateBuildGraph` call in `SourceKitLSPServer` from a `Task`. This means that `generateBuildGraph` could be executed after `waitForUpToDateBuildGraph` was called by `SemanticIndexManager`. Thus `waitForUpToDateBuildGraph` returned immediately and no files were background indexed.

Make `generateBuildGraph` immediately schedule a package reload for SwiftPM build systems instead of doing the hop through a `Task`, fixing the race condition.

rdar://135551812
2024-09-09 11:50:18 -07:00
Alex Hoppen
6e0281f79a Don’t block the generation of a build system by build graph generation
We currently load the entire package before generating a `SwiftPMBuildSystem`. That means that the initialize request to SourceKit-LSP is blocked until the package has been loaded, preventing us from offering any sort of functionality, including syntactic functionality like formatting.

Decouple build system creation and build graph generation (aka. package loading for SwiftPM). We can operate with fallback build settings until the build graph has been loaded and reopen the document once the proper build settings are available.

rdar://126644596
2024-09-06 22:51:53 -07:00
Alex Hoppen
189f32ae04 Remove workarounds that are no longer needed 2024-08-17 07:52:55 -07:00
Alex Hoppen
0249741aba Remove indexPrefixMappings from BuildSystem
They weren’t used.
2024-08-01 10:11:48 -07:00
Alex Hoppen
66f2d86775 Rename SKCore to BuildSystemIntegration 2024-07-25 09:11:13 -07:00