Commit Graph

234 Commits

Author SHA1 Message Date
Josh Arnold
2e0735b72e Fix algorithmic bug causing exponential blowup in dependency analysis
(cherry picked from commit 18de71082c)
2025-07-24 11:33:23 -07:00
Ben Barham
f22e13db38 Merge pull request #2162 from bnbarham/20250519-manual-merge
Merge main into release/6.2
2025-05-21 17:00:27 -07:00
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
Ben Barham
fde7d70db1 Revert "Merge pull request #2137 from ahoppen/terminate-unresponsive-clangd-sourcekitd"
This change is too risky for 6.2 at this point.
2025-05-12 16:35:59 -07:00
Alex Hoppen
863c0e2cdf Merge pull request #2137 from ahoppen/terminate-unresponsive-clangd-sourcekitd
If sourcekitd or clangd don’t respond to a request for 5 minutes, terminate them and use crash recovery to restore behavior
2025-05-12 15:13:30 +02:00
Alex Hoppen
2c7ecffab4 Merge pull request #2143 from ahoppen/resolve-swiftly
Resolve swiftly when referenced in compile commands
2025-05-12 15:13:14 +02:00
Alex Hoppen
a26b0b7b3a Resolve swiftly when referenced in compile commands
When the compiler in `compile_commands.json` references a `swift` executable that’s a symlink to `swiftly`, SourceKit-LSP got confused because the `swift` executable doesn’t reside in a real toolchain, causing us to not provide any semantic functionality.

When we discover that the `swift` executable reference in compile commands references a `swiftly` executable, use `swiftly use -p` to resolve the binary in the real toolchain and continue operating based on that.

Fixes #2128
rdar://150301344
2025-05-09 09:12:21 +02:00
Doug Schaefer
3113bdbcc0 Add SwiftASN1 as an explicit dependency on BuildSystemIntegration
The SwiftPM smoke test still fails to build. I see the SwiftASN1
modules aren't getting added to the include path. Hopefully an
explicit dependency will fix that.
2025-05-08 15:08:38 -04:00
Alex Hoppen
14cfd50582 If sourcekitd or clangd don’t respond to a request for 5 minutes, terminate them and use crash recovery to restore behavior
This should be a last stop-gap measure in case sourcekitd or clangd get stuck, don’t respond to any requests anymore and don’t honor cancellation either. In that case we can restore SourceKit-LSP behavior by killing them and using the crash recovery logic to restore functionality.

rdar://149492159
2025-05-07 13:43:28 +02:00
Alex Hoppen
30ac972450 Remove FileBuildSettings.patching that takes a String
This overload is no longer needed.
2025-04-23 18:58:20 +02:00
Matthew Bastien
0e05bca76c remove isHeader from SourceKitSourceItemData 2025-04-16 14:44:13 -04:00
Matthew Bastien
8c15e27959 use a helper document in cursorInfo() 2025-04-16 14:44:12 -04:00
Matthew Bastien
0adaf2581f more robust searching for DocC catalogs 2025-04-16 14:44:12 -04:00
Alex Hoppen
161eea30f0 Merge pull request #2095 from bripeticca/swiftpmapi/fiximport
Update import on SwiftPM PackageModel for `SwiftPMBuildSystem.swift`
2025-04-08 12:03:04 -07: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
92aa94fa43 Remove the split between SourceKitD and DynamicallyLoadedSourceKitD
There is only one real class that implements the `SourceKitD` protocol, so there really isn’t any need for the protocol + class split at all. Unify them to make code simpler to reason about.
2025-03-27 11:05:24 -07:00
Alex Hoppen
3bb4690db4 Terminate pending background indexing and preparation tasks when shutting down SourceKit-LSP
When SourceKit-LSP is shut down, we should make sure that we don’t leave behind child processes, which will become orphans after SourceKit-LSP has terminated. What’s worse, when SourceKit-LSP has exited, these processes might not have any process to read their stdout/stderr, which can lead to them running indefinitely.

This change does not cover the termination of subprocess trees. For example, if we launch `swift build` and need to kill it because it doesn’t honor SIGINT, its child processes will still live on. Similarly, if we kill a BSP server, its child processes might live on. Fixing this is a drastically bigger endeavor, likely requiring changes to Foundation and/or TSC. I filed https://github.com/swiftlang/sourcekit-lsp/issues/2080 for it.
2025-03-25 14:10:38 -07:00
Alex Hoppen
dd2d2aff49 Fix some more quadratic performance issues in AsyncQueue
We would hit quadratic behavior in `AsyncQueue` when the build system floods us with `build/logMessage` or `build/task(Start|Progress|Finish)` notifications because we record a dependency on all of the pending log message handling tasks.

We can extend the improvement made in https://github.com/swiftlang/sourcekit-lsp/pull/1840 to fix this quadratic problem: If the current task depends on a task with metadata that depends on itself (ie. all tasks of metadata that needs to be executed in-order), we only need to depend on the last task with that metadata.

This covers many message types and we can now only get into quadratic behavior if we get flooded with two different kinds of messages: One that does not have a self-dependency and one that depends on the message without a self-dependency. In terms of LSP messages, this could be a document read followed by a document update, but I think this is a lot more unlikely than getting spammed with one type of message.
2025-03-21 17:33:55 -07:00
Alex Hoppen
71e74045f2 If the compiler arguments only contain -o, add the output path as -index-unit-output-path to the adjusted options
Otherwise, we would strip away the `-o`, leaving the command line without any output path option and thus not able to generate a unit file (which requires an output path).
2025-03-18 21:54:10 -07:00
Alex Hoppen
cef212f03b Merge pull request #2038 from ahoppen/multi-target-support
Support indexing a file in the context of multiple targets
2025-03-18 13:56:06 -07:00
Alex Hoppen
77b39200dc Fix typos 2025-03-17 17:10:00 -07:00
Alex Hoppen
20f0d3f3c4 Merge pull request #2063 from ahoppen/hover-compile-flags
Fix issue that caused code completion to fail using compile_flags.txt
2025-03-17 15:25:18 -07:00
Alex Hoppen
4991e1560c Re-index header files when they are modified 2025-03-14 15:50:11 -07:00
Alex Hoppen
d10c868497 Support indexing a file in the context of multiple targets
If a source file is part of multiple targets, we should index it in the context of all of those targets because the different targets may produce different USRs since they might use different build settings to interpret the file.
2025-03-14 15:49:59 -07: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
b49b40968b Fix issue that caused code completion to fail using compile_flags.txt
The compiler name shouldn’t be part of the build settings.
2025-03-13 20:19:26 -07:00
Alex Hoppen
e198b4b4d7 Do not apply file path normalization in mainFiles(containing:) to the file itself
Do not apply the standardized file normalization to the source file itself. Otherwise we would get the following behavior:
 - We have a build system that uses standardized file paths and index a file as /tmp/test.c
 - We are asking for the main files of /private/tmp/test.c
 - Since indexstore-db uses realpath for everything, we find the unit for /tmp/test.c as a unit containing /private/tmp/test.c, which has /private/tmp/test.c as the main file.
 - If we applied the path normalization, we would normalize /private/tmp/test.c to /tmp/test.c, thus reporting that /tmp/test.c is a main file containing /private/tmp/test.c,
But that doesn't make sense (it would, in fact cause us to treat /private/tmp/test.c as a header file that we should index using /tmp/test.c as a main file.
2025-03-12 18:06:17 -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
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
9f5f06bc57 Merge pull request #2032 from ahoppen/ahoppen/response-file-indexing
Use response files to index files if argument list exceeds maximum number of arguments
2025-03-05 23:50:33 -08:00
Alex Hoppen
5541060451 Use response files to index files if argument list exceeds maximum number of arguments 2025-03-05 13:33:40 -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
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