Commit Graph

109 Commits

Author SHA1 Message Date
Max Desiatov
8a908f21b6 Pass hostToolchainBinDir to SwiftSDKBundleStore (#2157)
This became a required parameter in
https://github.com/swiftlang/swift-package-manager/pull/8668, which can
be easily computed, since the host toolchain in practice is always available when `SwiftSDKBundleStore` is initialized.
2025-05-15 11:25:23 +01:00
Ben Barham
385f8ae79f Resolve paths passed in the SwiftPM configuration to the project root
Resolves #2148.
2025-05-12 18:16:57 -07:00
Matthew Bastien
0adaf2581f more robust searching for DocC catalogs 2025-04-16 14:44:12 -04:00
Bri Peticca
41fe2a52b3 Update import for PackageModel
With upcoming changes to SwiftPM's TraitConfiguration
(see #8370), PackageModel needs to be imported using
`@preconcurrency`.
2025-03-27 14:42:58 -04:00
Alex Hoppen
c9a1a08255 Make output paths part of the buildTarget/sources request instead of a separate request
We need a mapping from source file to its output path in order to support source files that are part of multiple targets (because we need the output path to check if we have an up-to-date unit for a file in a given target). To achieve this mapping, it’s easier to tag the output path for each source file onto the `buildTarget/sources` request.
2025-03-14 15:12:38 -07:00
Alex Hoppen
cb17643752 Make a couple parameters in the BuildTarget initializer defaulted 2025-03-14 15:12:38 -07:00
Alex Hoppen
cde206c017 Allow specifying toolsets for SwiftPM projects
Equivalent to SwiftPM’s `--toolset` option, implemented in https://github.com/swiftlang/swift-package-manager/pull/8051.

Fixes #2047
rdar://146557424
2025-03-11 13:21:54 -07:00
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
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
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
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
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
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
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
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
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
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
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
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
ddbd6543c4 Allow dependency updates in the index-build folder
When we have background indexing enabled, SourceKit-LSP manages the dependencies. We should thus allow it to update them, eg. after `Package.resolved` was updated.
2024-12-06 11:30:02 -08:00
Alex Hoppen
388789472c Create child scopes for SwiftPM operations
Some SwiftPM functions check whether their observability scope has errors. If we use the same observability scope for all SwiftPM operations during SourceKit-LSP’s lifetime, a single SwiftPM error will set the `hasError` bit in that observability scope for the entirety of SourceKit-LSP’s lifetime, impacting all upcoming SwiftPM operations.

Creating a separate child scope for every operation fixes
2024-12-06 11:26:13 -08:00
Alex Hoppen
b42e62f42d Merge pull request #1862 from ahoppen/log-package-reload-trigger
Log which file caused the package to be reloaded
2024-12-06 09:02:36 -08:00
Alex Hoppen
1c9a15eeb0 Log which file caused the package to be reloaded 2024-12-05 20:27:32 -08:00
Alex Hoppen
5914efd9b4 Log package loading messages to the index log 2024-12-05 20:26:50 -08:00
Matthew Bastien
f900b4ef2c Merge pull request #1853 from matthewbastien/include-all-build-target-resources
Include all resources in a build target's sources list
2024-12-05 16:49:06 -05:00
Matthew Bastien
f2fed7afa5 reduce code duplication
Co-authored-by: Alex Hoppen <alex@alexhoppen.de>
2024-12-05 10:48:56 -05:00
Matthew Bastien
3ea9a65d77 include all resources in a build target's sources list 2024-12-05 09:53:42 -05:00
Alex Hoppen
cddd810455 Provide build settings for version-specific package manifests
Fixes #1670
rdar://136014520
2024-11-22 22:04:20 +01:00
Alex Hoppen
76304db5e2 Fix merge conflict
https://github.com/swiftlang/sourcekit-lsp/pull/1824 and https://github.com/swiftlang/sourcekit-lsp/pull/1832 raced.
2024-11-19 15:47:52 -08:00
Alex Hoppen
8d13afa73d Merge pull request #1824 from kateinoigakukun/katei/interpret-relative-scratch-dir
Allow `scratchPath` to be a relative path
2024-11-19 11:14:40 -08:00
Yuta Saito
184fa12389 Allow scratchPath to be relative paths
Interpret it as relative to the project root directory if it's a
relative path.
2024-11-19 11:19:54 +09: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
c23b4ff776 Merge pull request #1803 from ahoppen/indexbuild-subfolder
Make `.index-build` a subdirectory of `.build`
2024-11-14 12:54:20 -08:00