Commit Graph

70 Commits

Author SHA1 Message Date
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
aa0aa927ca Stop using TSCBasic.resolveSymlinks and URL.resolvingSymlinksInPath 2024-10-09 13:16:57 -07:00
Alex Hoppen
ee29e31fb4 Merge pull request #1719 from ahoppen/explicit-bsp-shutdown
Explicitly shut down the build server when SourceKit-LSP is shut down
2024-10-02 10:27:15 -07:00
Alex Hoppen
3c7aa6f438 Merge pull request #1715 from ahoppen/bsp-cancellation
Share implementation of message handling on an `AsyncQueue` between `BuildSystemIntegration` and `SourceKitLSPServer`
2024-09-30 15:31:54 -07:00
Alex Hoppen
d25b65c307 Explicitly shut down the build server when SourceKit-LSP is shut down
The build server is automatically shut down using a background task when `BuildSystemManager` is deallocated.

This, however, leads to possible race conditions where the shutdown task might not finish before the test is done, which could result in the connection being reported as a leak. To avoid this problem, we want to explicitly shut, down the build server when the `SourceKitLSPServer` gets shut down.
2024-09-30 11:57:39 -07:00
Alex Hoppen
7befd0c648 Share implementation of message handling on an AsyncQueue between BuildSystemIntegration and SourceKitLSPServer
This gives us cancellation support for `BuiltInBuildSystemAdapter`.
2024-09-30 10:42:46 -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
d842579402 Merge pull request #1712 from ahoppen/build-system-logging-improvements
Improve logging surrounding build systems
2024-09-30 08:11:40 -07:00
Alex Hoppen
bd422cf5d7 Improve logging surrounding build systems 2024-09-27 11:07:39 -07:00
Alex Hoppen
b91f72f1d4 Merge pull request #1700 from ahoppen/build-settings-timeout
Use fallback build settings if build system doesn’t provide build settings within a timeout
2024-09-27 10:28:50 -07:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
fb5ee8e9c7 Miscellaneous adjustments to allow SourceKit-LSP to build using Swift 5.10 2024-09-26 18:23:59 -07:00
Alex Hoppen
78217ec6a6 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
2024-09-26 17:50:58 -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
d8b41d4eff Merge pull request #1685 from ahoppen/only-scan-test-targets
Only scan test targets for tests
2024-09-19 20:41:40 -07:00
Alex Hoppen
120bd8688b Only scan test targets for tests
Don’t run the syntactic test scanner on files that we know are only part of non-test targets.

rdar://126493903
2024-09-19 13:42:40 -07:00
Alex Hoppen
82e0036b96 Don’t send messages to the BSP server before the build/initialize request returns
We currently allow sending requests to the BSP server before `build/initialize` returns. This is not valid in general and we should wait for the initialize result before sending any other messages.

rdar://136111469
2024-09-19 13:41:45 -07:00
Alex Hoppen
478227308b Merge pull request #1682 from ahoppen/swiftpm-symlink
Fix an issue that caused us to not get compiler arguments when opening a SwiftPM package at a symlink
2024-09-19 13:38:11 -07:00
Alex Hoppen
14765bbca8 Fix an issue that caused us to not get compiler arguments when opening a SwiftPM package at a symlink
When you had a package at `/pkg_real` and a symlink `/pkg` pointing to `/pkg_real`, then opened a workspace at `/pkg`, we wouldn’t get any build settings for any of the files. This was masked in tests because they still called `SwiftPMBuildSystem.targets(for:)`, which handled symlink resolution but wasn’t called in production.

Handle symlink resolution `BuildSystemManager`, remove `SwiftPMBuildSystem.targets(for:)` and its related members/methods, and migrate the tests to go through `BuildSystemManager`, which is what production code does. A nice side effect of this is that the tests will log the requests sent to the build system.
2024-09-18 17:41:36 -07:00
Alex Hoppen
2446a32604 Fix a memory leak
We had a retain cycle from `BuildSystemManager` to `LocalConnection`. Fix it by making `LocalConnection` have a weak reference to `BuildSystemManager`.
2024-09-18 07:55:15 -07:00
Alex Hoppen
d8b2cb2a82 Mark all transitive dependents of a modified target as being unprepared
We weren’t considering transitive dependencies in `BuildSystemManager.targets(dependingOn:)` before.

rdar://136039234
2024-09-17 14:37:24 -07:00
Alex Hoppen
316790ff7a Review BuiltInBuildSystem 2024-09-16 10:12:34 -07:00
Alex Hoppen
d155665b73 Review BuildSystemManager 2024-09-16 10:12:18 -07:00
Alex Hoppen
0f56e5f32e Simplify FallbackBuildSystem to a free function returning fallback arguments 2024-09-16 10:12:09 -07:00
Alex Hoppen
9ee7c59c7d Minor cleanups 2024-09-16 10:10:26 -07:00
Alex Hoppen
3a78b650c1 Share logic to infer language from file extension between BuildSystemManager and FileBuildSettings.patching 2024-09-16 10:10:26 -07:00
Alex Hoppen
2f388b988a Send shutdown request to build system from BuildSystemManager 2024-09-16 10:10:26 -07:00
Alex Hoppen
85b2f1fd30 Review BuildServerProtocol module for consistency 2024-09-16 10:10:26 -07:00
Alex Hoppen
80afa152fb Replace FIXME with TODO 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
79e1d2abad If we have a cached request for a superset of the targets, serve the result from that 2024-09-16 10:08:14 -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
29cfda032c Refactor sourceFiles to return a dictionary from DocumentURI to SourceFileInfo instead of a SourceFileInfo array 2024-09-16 10:08:13 -07:00
Alex Hoppen
f741b0dd41 Use more fine-grained dependency tracking to allow BSP requests to be handled concurrently 2024-09-16 10:06:35 -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
c93f193d21 Share message handling logic between BuiltInBuildSystemAdapter and BuildSystemManager 2024-09-15 16:28:12 -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
fac21f5976 Implement waitForUpToDateBuildGraph using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
12923b6d73 Implement toolchain(for:) using BSP 2024-09-13 11:12:40 -07:00
Alex Hoppen
d8161b371f Cache build targets by ID and associated depths
We often need targets by ID, so cache it at that level and also simplify the cache of the target depths by computing it when getting build targets.
2024-09-13 11:12:40 -07:00
Alex Hoppen
cc11fe1b02 Implement topologicalSort inside BuildSystemManager using dependency information 2024-09-12 17:26:41 -07:00
Alex Hoppen
bb96ff4c68 Migrate targets(dependingOn:) to BSP 2024-09-12 16:59:03 -07:00
Alex Hoppen
897cd5e775 Implicitly trigger build graph generation when creating a SwiftPMBuildSystem 2024-09-12 16:24:48 -07:00
Alex Hoppen
9006ab6fc8 Use the InitializeRequest from BSP to communicate some static options between the build system and BuildSystemManager 2024-09-12 07:34: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