Commit Graph

196 Commits

Author SHA1 Message Date
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
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
1c968226f1 When the build system sends an update for build targets, update the index for the files in those targets
For each file in the changed targets, we still check whether it has an up-to-date unit based on timestamps. The important thing for this change is that we start indexing files for which we only receive build settings after an update from the build server.
2025-03-01 09:25:45 -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
66793ffbb2 Merge pull request #2000 from ahoppen/index-store-path-option
If a build server doesn’t specify `-index-store-path` in the SourceKit options, add it during background indexing
2025-02-26 12:30:07 -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
628ce3cc63 If a build server doesn’t specify -index-store-path in the SourceKit options, add it during background indexing 2025-02-25 22:46:32 -08:00
Alex Hoppen
328d46d01c Merge pull request #1996 from ahoppen/inject-build-server-message-handler
Change the build server injection logic to inject a `Connection` instead of `BuiltInBuildSystem`
2025-02-25 22:34:50 -08:00
Alex Hoppen
086f4796eb Merge pull request #2002 from ahoppen/remove-semicolons
Remove superfluous semicolons
2025-02-25 20:24:49 -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
Alex Hoppen
5efdd19a3b Remove superfluous semicolons 2025-02-25 15:01:29 -08:00
Alex Hoppen
e50772bf08 Retry loading the build description if it fails to write output-file-map.json on Windows
Loading the build description sometimes fails non-deterministically on Windows because it's unable to write `output-file-map.json`, probably due to https://github.com/swiftlang/swift-package-manager/issues/8038.

If this happens, retry loading the build description up to 5 times.
2025-02-25 08:59:24 -08:00
Ben Barham
a5343852c6 Add option to skip building and running plugins
This *shouldn't* be needed, but allows running plugins to be skipped if
there's any unexpected interactions with background indexing.
2025-02-17 19:14:34 -08:00
Ben Barham
cea30e54b0 Add a couple missing SwiftPM options 2025-02-17 19:11:30 -08:00
Ben Barham
3f189ee82c Use the new SwiftPM API to load the build plan
We previously skipped building/running tool plugins here, which meant
that the compiler arguments for a target also missed any generated
sources. Use the new `BuildDescription.load` API from SwiftPM to address
this.

Resolves rdar://102242345.
2025-02-17 19:11:30 -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
6746f30ba3 Allow non-file URLs when injecting a build system
There is no reason why we should only support file URLs here.
2025-01-28 10:42:53 -08:00
Alex Hoppen
fc100d24bf Cache the mapping from compiler to toolchain
While at it, also make `Toolchain.path` non-optional and clean up `ToolchainRegistry.init` slightly.
2025-01-25 21:32:44 -08:00
Alex Hoppen
ed098f58cb Merge pull request #1934 from ahoppen/multi-toolchain-support
Support opening documents within the same workspace with sourcekitd/clangd from different toolchains
2025-01-25 08:52:52 -08:00
Alex Hoppen
c67c06e7b1 Merge pull request #1950 from ahoppen/gardening
Gardening
2025-01-24 22:33:51 -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
e9ea204ac2 Merge pull request #1930 from ahoppen/inject-indexstoredb
Add a hook to inject an `IndexStoreDB` instance into `SourceKitLSPServer`
2025-01-24 13:16:19 -08:00
Alex Hoppen
a1716e29ea Merge pull request #1940 from ahoppen/log-module-graph-loading-finish
Add a signposter for SwiftPM package loading
2025-01-24 12:54:09 -08:00
Alex Hoppen
73bf53a953 Merge pull request #1933 from ahoppen/split-compile-commands-build-systems
Split build systems for JSON compilation database and fixed compilation database
2025-01-23 21:25:12 -08:00
Alex Hoppen
64f2aef446 Fix build warnings
Quite a few of these were reminders to clean things up once we no longer need to support testing using compilers and sourcekitd from older toolchains.
2025-01-23 21:11:08 -08:00
Alex Hoppen
6620faed02 Add a signposter for SwiftPM package loading
I saw `testBackgroundIndexingHappensWithLowPriority` hang once. This should help us determine where we are hanging if we see the hang again.

rdar://143303256
2025-01-21 11:48:31 -08:00
Alex Hoppen
e39321fc27 Merge pull request #1923 from kabiroberai/kabir/cross-index
Support background indexing when cross-compiling
2025-01-21 02:23:31 -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
Alex Hoppen
44bd97babe Fix Windows test failures 2025-01-17 09:49:52 -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
8cfc4b67f4 Add a hook to inject an IndexStoreDB instance into SourceKitLSPServer
rdar://142907558
2025-01-16 16:34:47 -08:00
Alex Hoppen
b7907b4c5a Merge pull request #1922 from ahoppen/inject-build-system
Allow injection of build systems into `SourceKitLSP`
2025-01-16 14:01:19 -08:00
Alex Hoppen
8d28ed1373 Merge pull request #1919 from ahoppen/output-redirection-sendable
Mark all closures in the `.stream` outputRedirection of TSC as `@Sendable`
2025-01-16 13:35:48 -08:00
Kabir Oberai
b5a97695b6 Forward cross-compilation args when indexing 2025-01-15 21:40:26 -05: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
8617b8bbcc Do not realpath the project root of a SwiftPMBuildSystem
If you have a package located at `/pkg` and a symlink at `/symlink` and you open `/symlink` as a workspace, the SwiftPMBuildSystem’s project root would be `/pkg`. This would mean that it also only knew about build settings for files in `/pkg`, not in `/symlink`. Thus, whenever we were opening a file in `/symlink` we would create an implicit workspace to handle it (but which ended up having a project root at `/symlink` again) – or something close to this.

We shouldn’t need to realpath here. If you open `/symlink`, we should view `/symlink` as the project root of your workspace.
2025-01-15 09:54:20 -08:00
Alex Hoppen
7fffc04e50 Mark all closures in the .stream outputRedirection of TSC as @Sendable
The closures aren’t guaranteed to be called on the same thread as the process was launched, which can cause assertion failure by the concurrency runtime.

rdar://142813605
2025-01-15 08:25:25 -08:00
Alex Hoppen
5326852ea8 Support building SourceKit-LSP without a dependency on SwiftPM 2025-01-08 13:13:31 +01:00
Alex Hoppen
718c0ee809 Remove imports of SwiftPM modules that are not strictly necessary 2025-01-08 12:43:43 +01:00
Alex Hoppen
b07044d25d Interpret the -index-store-path relative to the command’s directory
Fixes #1856
rdar://141004197
2024-12-13 18:35:13 +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
7a06eb0ddf Merge pull request #1858 from ahoppen/symlink-target
Fix background indexing behavior if a source file is included in two targets via a symlink
2024-12-10 15:00:46 -08:00
Alex Hoppen
a087692725 Return compiler arguments for invalid package manifests
Currently, when there‘s a syntax error in a package manifest, we don’t get any build settings from it in SourceKit-LSP and thus loose almost all semantic functionality. If we can’t parse the package manifest, fall back to providing build settings by assuming it has the current Swift tools version.

Currently, when there‘s a syntax error in a package manifest, we don’t get any build settings from it in SourceKit-LSP and thus loose almost all semantic functionality. If we can’t parse the package manifest, fall back to providing build settings by assuming it has the current Swift tools version.

Fixes #1704
rdar://136423767
2024-12-09 15:25:38 -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
247acf6ae7 Merge pull request #1874 from ahoppen/allow-dependency-updates
Allow dependency updates in the `index-build` folder
2024-12-09 14:31:38 -08:00
Alex Hoppen
881f0f55fa Merge pull request #1873 from ahoppen/swiftpm-child-scopes
Create child scopes for SwiftPM operations
2024-12-09 12:17:02 -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