Commit Graph

88 Commits

Author SHA1 Message Date
Alex Hoppen
559f23957e Improve performance of sourceFilesAndDirectories
`SourceFilesAndDirectoriesKey` contained all source files in the project and computing its hash value was pretty expensive. The key didn’t really provide any value here because the only way it changes is if the build targets change and if that’s the case, we already clear `cachedSourceFilesAndDirectories`, so we can just avoid the hash value computation.
2024-12-10 16:26:22 -08:00
Alex Hoppen
5eb460f148 Fix background indexing behavior if a source file is included in two targets via a symlink
Consider the following scenario: A project has target A containing A.swift an target B containing B.swift. B.swift is a symlink to A.swift. When A.swift is modified, both the dependencies of A and B need to be marked as having an out-of-date preparation status, not just A.
2024-12-09 15:06:39 -08:00
Alex Hoppen
fad3c10033 Merge pull request #1867 from ahoppen/cache-transformed
Cached transformed results in `Cache`
2024-12-06 17:15:12 -08:00
Alex Hoppen
1c1a1cf5f6 Cached transformed results in Cache
The transform to get the transformed result might be expensive, so we should cache its result.
2024-12-06 11:59:25 -08:00
Alex Hoppen
a61bbffdb4 Cache path components for directories returned from build system
We frequently compute if a file is descendent of the directory and `URL.pathComponents` is an expensive computation.
2024-12-06 11:55:00 -08:00
Matthew Bastien
8fd30908e7 handle *.md and *.tutorial files for Swift DocC 2024-12-05 11:18:49 -05: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
1f33ed484d Split SKUtilities from SKSupport 2024-11-13 16:53:54 -08:00
Alex Hoppen
47f3cd506b Split TSCExtensions into a separate module 2024-11-13 13:58:36 -08:00
Alex Hoppen
0fbb6466e7 Make BuildSystemKind a struct and rename to BuildSystemSpec 2024-11-13 10:23:43 -08:00
Alex Hoppen
c1e090ef33 Address minor review comments 2024-11-13 10:09:31 -08:00
Alex Hoppen
41a773f89a Merge pull request #1804 from ahoppen/remove-unnecessary-fault
Don’t log “Did not compute dependents for target”
2024-11-07 15:38:17 -08:00
Alex Hoppen
06f58db5c8 Use build/taskStart, build/taskProgress and build/taskFinish to communicate progress from a BSP server to the client
Instead of defining BSP extensions for `window/workDoneProgress/create` and `$/progress`, we should be able to use the standard `build/taskStart`, `build/taskProgress` and `build/taskFinish` messages to the same effect, as suggested by https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400/9.

Fixes #1783
rdar://138653131
2024-11-06 09:39:09 -08:00
Alex Hoppen
69e9a5cf54 Don’t log “Did not compute dependents for target”
Leaf targets don’t have dependents and that’s expected. We shouldn’t log a fault for them.
2024-11-04 15:58:57 -08:00
Alex Hoppen
5d47358236 Merge pull request #1762 from ahoppen/build-settings-timeout 2024-10-23 23:50:58 -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
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