Commit Graph

436 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
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
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
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
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
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
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
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
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
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
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
ca960bc9c2 Introduce a MultiEntrySemaphore for testing
Compare to the `while !AtomicBool.value { sleep }` pattern, this eventually times out, avoiding a timeout of the entire `swift test` invocation.
2025-03-11 09:20:44 -07:00
Alex Hoppen
572660ae26 Add timeouts to most subprocess calls in tests
Just a speculative fix to avoid timeouts during the `swift test` invocation
2025-03-11 09:20:44 -07:00
Alex Hoppen
1cd1102d89 Introduce defaultTimeoutDuration to get the default timeout as a Duration 2025-03-11 09:20:44 -07:00
Alex Hoppen
956742d34f Merge pull request #2049 from ahoppen/cancellation-custom-build-server
Support cancellation in `CustomBuildServer`
2025-03-11 08:22:43 -07:00
Alex Hoppen
ce75053555 Handle file did change notifications as freestanding messages
Technically, the watched files notification can change the response of any other request (eg. because a target needs to be re-prepared). But treating it as a `globalConfiguration` inserts a lot of barriers in request  handling and significantly prevents parallelism. Since many editors batch file change notifications already, they might have delayed the file change notification even more, which is equivalent to handling the  notification a little later inside SourceKit-LSP. Thus, treating it as `freestanding` should be acceptable.

Also, simplify the logic needed in tests to write modified files to disk because we now need to run a barrier request in tests to ensure that the watched file notification has been handled.
2025-03-10 21:44:35 -07:00
Alex Hoppen
64147963d0 Support cancellation in CustomBuildServer
I developed this for a test case that didn’t end up being useful. But supporting request cancellation here might come in useful in the future.
2025-03-10 15:25:50 -07:00
Alex Hoppen
776d019ec9 Do not send DiagnosticsRefreshRequest to the client if it doesn't support it
Check if the client's capabilities to see if it supports `workspace/diagnostic/refresh`.
2025-03-10 14:11:23 -07:00
Alex Hoppen
34f977219b Merge pull request #2041 from ahoppen/license-headers
Consistently add license headers to all files
2025-03-07 13:26:18 -08: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
cf828a8135 Consistently add license headers to all files
To prepare for the GitHub Action license header check.
2025-03-06 22:01:00 -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
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
2ee9dff5e5 Merge pull request #2023 from ahoppen/dont-escape-slashes
Don't escape slashes in various `JSONEncoder`s
2025-03-03 12:51:47 -08:00
Alex Hoppen
2305dfab7a Don't escape slashes in various JSONEncoders
This makes the JSON easier to work with, especially for paths.
2025-03-03 07:55:09 -08:00
Alex Hoppen
bd6fb5d04c Do not block initialization of the build server when build server is unresponsive in returning the list of test files
We were blocking the initialization response on `self.buildSystemManager.testFiles`, which requires the list of test files to be determined. Make that operation asynchronous so that a slow build server can’t take down all of SourceKit-LSP.
2025-02-26 16:31:29 -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
dae74db63c Merge pull request #2011 from ahoppen/client-specified-id
Add a `send` method to `InProcessSourceKitLSPClient` and `LocalConnection` in which the client specifies the request ID
2025-02-26 16:06:05 -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
db792c536f Add a send method to InProcessSourceKitLSPClient and Connection in which the client specifies the request ID 2025-02-26 08:41:30 -08:00