Commit Graph

107 Commits

Author SHA1 Message Date
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
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
51a035dce2 Use the BSP output file paths request to exclude units from the index that are no longer part of any targets 2025-03-05 09:58:37 -08:00
Alex Hoppen
c3ecb9adae Add BSP request to get the output file paths of a target 2025-03-05 09:58:34 -08:00
Alex Hoppen
2a05d940ff Merge pull request #2022 from ahoppen/structure-index-log
Add structure to the index logs
2025-03-05 09:56:47 -08:00
Alex Hoppen
655a93f05a Add structure to the index logs
When the client supports it, communicate the structure of tasks that were stared during background indexing or by the build server to the client. If there are multiple operations happening in parallel, this allows the client to display them in separate log tracks instead of interspersing them with the emoji prefixes like we do today.
2025-03-04 16:36:26 -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
fe750f6e09 Cache the set of buildable source files
This way we don’t need to rebuild the set every time we call `filesToIndex(toCover:)`.
2025-03-03 13:58:29 -08:00
Alex Hoppen
18b18c2b12 Debounce filesBuildSettingsChanged calls
This helps in the following situation: A build system takes 5s to return build settings for a file and we have 10 requests for those build settings coming in that time period. Once we get build settings, we get 10 calls to `resultReceivedAfterTimeout` in `buildSettings(for:in:language:fallbackAfterTimeout:)`, all for the same document.
But calling `fileBuildSettingsChanged` once is totally sufficient.
2025-02-27 21:54:04 -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
Alex Hoppen
6678fb0e40 Use an active compilation condition to build SourceKit-LSP without SwiftPM support
This is more explicit than using `#if canImport(PackageModel)`.
2025-02-05 17:56:20 -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
15b9670888 Split build systems for JSON compilation database and fixed compilation database
I feel like the implementations are actually simpler if we split them. This will also allow us to add more advanced logic to the JSON compilation database build system in the future, such as inferring the toolchain from the compile command.
2025-01-17 14:38:37 -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
5326852ea8 Support building SourceKit-LSP without a dependency on SwiftPM 2025-01-08 13:13:31 +01:00
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