Commit Graph

2515 Commits

Author SHA1 Message Date
Alex Hoppen
3528e52bcb Add delay before writing file to disk in tests
Depending on the system, mtime resolution might not be perfectly accurate. Particularly containers appear to have imprecise mtimes.
Wait a short time period before writing the new file to avoid situations like the following:
 - We index a source file and the unit receives a time stamp and wait for indexing to finish
 - We modify the source file but so quickly after the unit has been modified that the updated source file
   receives the same mtime as the unit file
 - We now assume that the we have an up-to-date index for this source file even though we do not.

Waiting 10ms appears to be enough to avoid this situation on the systems we care about.

rdar://147811044
2025-03-25 18:59:01 -07:00
Alex Hoppen
d5e254137c Make fulfillmentOfOrThrow take a variadic list of expectations
In almost all cases, we pass a single expectation and that looks a lot nicer with a variadic parameter.
2025-03-25 09:16:17 -07:00
Alex Hoppen
e6ca874c1a Merge pull request #2086 from ahoppen/generated-interface-diags
Don’t return diagnostics for generated interfaces
2025-03-25 09:10:46 -07:00
Alex Hoppen
5575e90431 Merge pull request #2085 from ahoppen/quadratic-queue
Fix some more quadratic performance issues in `AsyncQueue`
2025-03-24 13:28:23 -07:00
Alex Hoppen
e5735196dc Merge pull request #2083 from ahoppen/localconnection-request-duration
Log request durations from `LocalConnection`
2025-03-24 13:28:09 -07:00
Alex Hoppen
ea1f1879d2 Merge pull request #2082 from ahoppen/cancel
Send CancelRequestNotification if we time out a request in `TestSourceKitLSPClient`
2025-03-24 13:27:58 -07:00
Alex Hoppen
e28c460f6d Merge pull request #2079 from ahoppen/dependent-targets
Move `targets(dependingOn:)` call out of the changed files loop
2025-03-24 13:27:41 -07:00
Alex Hoppen
54ac721f7e Merge pull request #2072 from ahoppen/update-index-store-db-during-indexing
Ensure that unit file generated by background indexing are immediately loaded into indextore-db
2025-03-24 13:27:23 -07:00
Alex Hoppen
686c225520 Don’t return diagnostics for generated interfaces
Trying to get diagnostics for generated interfaces fails with: `'<…>' is not part of the input files`

rdar://146949806
2025-03-21 17:55:54 -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
c6e1e9286a Log request durations from LocalConnection 2025-03-21 16:50:35 -07:00
Alex Hoppen
2ddacb1c9f Move targets(dependingOn:) call out of the changed files loop
We can call this function once we have gathered all changed targets instead of once for each changed file, which should be slightly more performant.
2025-03-21 16:33:47 -07:00
Alex Hoppen
4220b7fe39 Merge pull request #2078 from ahoppen/no-reindex-deleted-files
Do not re-index deleted files
2025-03-21 16:26:18 -07:00
Alex Hoppen
37b8b06732 Send CancelRequestNotification if we time out a request in TestSourceKitLSPClient 2025-03-21 15:22:38 -07:00
Alex Hoppen
87dd406af8 Merge pull request #2077 from ahoppen/shutdown-semaphore
Add a timeout to the semaphore we use for shutting down SourceKit-LSP
2025-03-21 14:30:30 -07:00
Alex Hoppen
fa32cbc8b0 Do not re-index deleted files
This wasn’t an issue when we were always waiting for an up-to-date build graph before indexing files but now we could still have an old build graph that contains the deleted files and thus start an indexing process for a file that doesn’t exist anymore on disk. And it’s cleaner anyway.
2025-03-20 10:32:52 -07:00
Alex Hoppen
6feab14ee2 Add a timeout to the semaphore we use for shutting down SourceKit-LSP 2025-03-20 10:30:34 -07:00
Saleem Abdulrasool
684bfe419a SKTestSupport: remove hardcoded version for XCTest
The XCTest and Testing version information is encoded into the
`PlatformInfo.plist` that is at the root of the platform. Use this to
determine the path for XCTest. This allows us to migrate the XCTest
location into an appropriate versioned directory.
2025-03-19 20:24:52 -07:00
Alex Hoppen
8b2727f9f9 Ensure that unit file generated by background indexing are immediately loaded into indextore-db
Otherwise, we can end up in a situation where we declare indexing as done but haven’t loaded the new units into indexstore-db yet.
2025-03-19 07:24:16 -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
a76f57202e Don’t enter an infinite loop when a circular symlink is added to a project 2025-03-18 14:18:25 -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
b757fb9806 Merge pull request #2069 from ahoppen/test-request-timeout
Add a timeout for requests sent from `TestSourceKitLSPClient`
2025-03-17 17:07:32 -07:00
Alex Hoppen
7734c3d16e Merge pull request #2067 from ahoppen/trailing-comma
Remove trailing comma
2025-03-17 15:27:46 -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
1f5cb45b32 Add a timeout for requests sent from TestSourceKitLSPClient
Otherwise, if a SourceKit-LSP request hangs, we would hang the test execution.
2025-03-17 11:16:24 -07:00
Alex Hoppen
3cc39df8a6 Merge pull request #2066 from ahoppen/expected-formatting
Fix expected output in swift-format `SkipUnless` check
2025-03-14 19:42:19 -07:00
Alex Hoppen
6a3afeaaa0 Remove trailing comma
This restores the ability to build SourceKit-LSP using a Swift 6.0 compiler
2025-03-14 15:52:12 -07:00
Alex Hoppen
88b40f3077 Use Windows file paths for fake output paths 2025-03-14 15:50:12 -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
c771daee1e Add standard initialization response for custom build server that supports background indexing 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
3cd38658cb Merge pull request #2065 from ahoppen/refresh-diags-sourcekitd-restored
Refresh diagnostics when sourcekitd has been restored
2025-03-14 15:11:30 -07:00
Alex Hoppen
23780ca7f1 Merge pull request #2061 from ahoppen/normalized-path
Do not apply file path normalization in `mainFiles(containing:)` to the file itself
2025-03-14 15:10:23 -07:00
Alex Hoppen
1f1e440dd8 Merge pull request #2060 from ahoppen/synchronize-request
Generalize `PollIndexRequest` and `BarrierRequest` into a single `SynchronizeRequest`
2025-03-14 15:10:13 -07:00
Alex Hoppen
35b6c1236c Fix expected output in swift-format SkipUnless check
We weren’t hitting this in Swift CI because we only test against Swift 6.2 toolchains, which take an earlier exit based on the Swift version.
2025-03-14 14:43:29 -07:00
Alex Hoppen
6c74631aca Refresh diagnostics when sourcekitd has been restored
After sourcekitd has been restored, we can provide diagnostics again, so tell the editor to reload them.
2025-03-13 21:17:48 -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
6eb800625a Merge pull request #2062 from ahoppen/skip-format-tests
Skip formatting tests if the `swift-format` executable in the host toolchain doesn’t support `-` to indicate that it’s reading the source file from stdin
2025-03-13 20:17:00 -07:00
Alex Hoppen
7f1e90f194 Skip formatting tests if the swift-format executable in the host toolchain doesn’t support - to indicate that it’s reading the source file from stdin 2025-03-13 14:12:03 -07:00
Alex Hoppen
9c867df103 Merge pull request #2057 from ahoppen/test-timeout
Add a few timeout checks to tests
2025-03-13 13:46:06 -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
5fba1699bd Generalize PollIndexRequest and BarrierRequest into a single SynchronizeRequest
This new request also allows us to wait for build system updates without waiting for background indexing to finish.
2025-03-12 14:25:50 -07:00
Alex Hoppen
f9fc58da6d Merge pull request #2058 from ahoppen/toolsets
Allow specifying toolsets for SwiftPM projects
2025-03-12 14:22:23 -07:00
Alex Hoppen
d645f44735 Merge pull request #2054 from ahoppen/file-change-freestanding
Handle file did change notifications as freestanding messages
2025-03-12 14:21:42 -07:00
Alex Hoppen
209fb1b602 Merge pull request #2053 from ahoppen/index-progress
Don't increment in-progress task counter for files that cannot be indexed
2025-03-12 14:21:34 -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