Commit Graph

80 Commits

Author SHA1 Message Date
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
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
Ben Barham
96247c0472 Add sendable annotation to userInfo closure
swift-foundation recently landed a change (in
swiftlang/swift-foundation#764) which requires `any Sendable` values in
`JSONEncoder.userInfo`. This causes a build failure:
```
JSONRPCConnection.swift:370:50: error: type '(RequestID) -> Optional<any ResponseType.Type>' does not conform to the 'Sendable' protocol
368 |
369 |     // Setup callback for response type.
370 |     decoder.userInfo[.responseTypeCallbackKey] = { (id: RequestID) -> ResponseType.Type? in
    |                                                  |- error: type '(RequestID) -> Optional<any ResponseType.Type>' does not conform to the 'Sendable' protocol
    |                                                  `- note: a function type must be marked '@Sendable' to conform to 'Sendable'
371 |       guard let outstanding = self.outstandingRequests[id] else {
372 |         logger.error("Unknown request for \(id, privacy: .public)")
```

Make the closure sendable, which is safe as we're only reading from
`outstandingRequests` (where all our writes are guarded by the same
queue that the decoding is on).
2025-02-17 08:31:07 -08:00
Finagolfin
7016b12bd3 Import new Android overlay in more places 2024-11-05 00:27:08 +05:30
Alex Hoppen
099c8caced Use firstRange instead of implementing firstIndex
We have `firstRange` in the stdlib now, so we don’t need to implement `firstIndex` ourselves.
2024-08-08 09:19:29 -07:00
Alex Hoppen
50a28bb86a Change FIXME and TODO comments to always have an associated issue
Do one of the following for every `FIXME` or `TODO` comment
- Add an issue that tracks the task
- Remove the comment if we are not planning to address it
2024-08-07 10:00:04 -07:00
Alex Hoppen
970b44d255 Remove a few @preconcurrency imports
rdar://132378792 is fixed
2024-07-31 17:25:20 -07:00
Alex Hoppen
1ef71cf663 Merge LSPTestSupport and SKTestSupport 2024-07-25 09:11:13 -07:00
Alex Hoppen
87f8b94c26 Build SourceKit-LSP in the Swift 6 language mode
rdar://126553799
2024-07-24 06:12:56 -07:00
Alex Hoppen
33d803f1d1 Change methods that were only public for testing purposes to be @_spi(Testing)
Fixes #876
Fixes #877
rdar://116705648
rdar://116705669
2024-06-11 19:03:26 -07:00
Lokesh T R
1a45220bdd Fixed minor formatting issues 2024-05-29 18:00:36 +00:00
Lokesh.T.R
087ea64ed3 Rename note to notification throughout the codebase wherever necessary 2024-05-29 17:58:04 +00:00
Alex Hoppen
ee79512e0a Make LSPTestSupport build in Swift 6 mode 2024-05-14 15:00:43 -07:00
Alex Hoppen
267b1cd4bf Make LanguageServerProtocolJSONRPCTests build in Swift 6 mode 2024-05-14 15:00:43 -07:00
Alex Hoppen
be42621f4c Don’t crash sourcekit-lsp if a known message is missing a field
Previously, we `fatalError`ing when `JSONDecoder` failed to decode a message from the client. Instead of crashing, try recovering from such invalid messages as best as possible. If we know that the state might  have gotten out of sync with the client, show a notification message to the user, asking them to file an issue.

rdar://112991102
2024-04-02 07:50:03 +02:00
Alex Hoppen
d1b527e14c Make the LanguageServerProtocolJSONRPC module build with strict concurrency enabled 2024-03-20 08:37:39 +01:00
Alex Hoppen
259da4554e Improve queue handling in JSONRPCConnection
This started off by guarding `state` against concurrent access and then escalated slightly.

The main changes are:
- `state` must only be accessed on `queue` now, preventing race conditions of message handling while the connection is being closed.
- A few functions were renamed, merged, and documented to simplify the code
- A few dead members were removed
2024-03-20 08:30:16 +01:00
Alex Hoppen
3007d9f392 Naming improvements, added comments and typo fixes in connection related code
This should make the code easier to understand. No functionality change.
2024-03-20 08:30:16 +01:00
Alex Hoppen
7c46df3abe Remove clientID from request handling
The client ID was needed when a `MessageHandler` could handle messages from multiple connections. We don’t support this anymore (because it wasn’t needed) and so the client ID doesn’t need to get passed through as well.
2024-03-20 08:28:26 +01:00
Alex Hoppen
abd534b584 Fix a race condition in TestMessageHandler
Not entirely sure what introduced the race condition. Found by thread sanitizer. Probably wouldn’t have been an issue if we had migrated this code to strict concurrency checking.
2024-03-05 13:23:25 -08:00
Alex Hoppen
757a029664 Log messages from the build server and clangd
Log messages sent to clangd and the build server in a similar way that we log requests to sourcekitd.

Fixes #886
rdar://116705677
2023-12-12 14:05:25 -08:00
Alex Hoppen
9abcd2a3a3 Remove the Notification type
`Notification` is just a wrapper around `NotificationType` and there’s no reason for it to exist anymore.

Resolves #880
rdar://116705670
2023-10-26 18:28:10 -07:00
Alex Hoppen
0e85e544a2 Remove unused functions from TestClient 2023-10-12 08:28:06 -07:00
Alex Hoppen
d0fc00ce98 Format using swift-format
Add `.swift-format` to the repo and format the repo with `swift-format`.

This commit does not add any automation to enforce formatting of sourcekit-lsp in CI. The goal of this commit is to get the majority of source changes out of the way so that the diff of actually enforcing formatting will have fewer changes or conflicts.
2023-10-10 13:44:47 -07:00
Alex Hoppen
bdda582714 Reduce usgaes of try! in tests
The usage of `try!` was still a relict of when `XCTest` didn’t allow throwing test method.
2023-09-18 19:16:49 -07:00
JCWasmx86
e6ef3717ff Decode locale 2023-06-26 20:29:09 +02:00
JCWasmx86
e8c930df1d Decode clientInfo 2023-06-24 18:13:12 +02:00
Max Desiatov
f5a30d9351 Fix uses of deprecated non-throwing AbsolutePath.init (#709)
These warnings appeared after an update to TSC deprecated this initializer.
2023-02-09 14:04:57 +00:00
Alex Hoppen
ca45a7a62b Return a .serverCancelled error code if the server cancels a request
`.cancelled` should only be returned if the client requested cancellation.
2022-12-05 08:45:36 +01:00
Alex Hoppen
975286d353 Update capability definitions to LSP 3.17 2022-12-04 19:56:51 +01:00
Saleem Abdulrasool
ea6ad5f1ff LanguageServerProtocolJSONRPCTests: silence a warning
`Sleep` is a `void` returning function, which makes the blackhole
redundant.  Remove the unnecessary assignment which also silences
the warning associated with it.
2022-08-28 04:35:09 -07:00
Alex Hoppen
df594e332c Set a default timeout duration
Instead of having ad-hoc timeout durations in all the test cases, specify a default timeout duration that can be used by tests.

This allows us increase the timeout duration for all tests if we discover that e.g. sourcekitd is slower in CI setups.

rdar://91615376
2022-06-14 17:26:06 +02:00
Alex Hoppen
20f5387268 Fix a crash on Linux if a ShutdownRequest was sent without params
Workaround for SR-16097 to avoid hitting SR-16095: VSCode will send shutdown requests without a 'params' key. On macOS getting the superDecoder for a non-existent container returns an empty decoder, on Linux it throws `DecodingError.keyNotFound`, causing a crash.

Perform a targeted fix: If we don't have 'params' and the request is a ShutdownRequest, manually create a `ShutdownRequest` without any parameters.

rdar://91288093
2022-04-22 09:47:41 +02:00
Alex Hoppen
c445225721 Delete LinuxMain and XCTestManifests and automatically discover test on Linux
Automatic test discovery is enabled by default since Swift 5.4. I think we can start relying on it.
2022-01-18 12:52:36 +01:00
Ben Langmuir
7788bff20d Fix lifetime issues in tests
A number of tests were failing with the -Onone lifetime changes.
Regardless of what happens with that change, I'd like to keep our tests
passing with the stricter rules since we also test in release builds.
2021-04-05 15:54:29 -07:00
Ben Langmuir
cf69c3f76c [test] Stop matching error description text that is not from our code
The underlying JSON parsing error is from Foundation, so we don't want
to try to compare that in our tests. As a quick fix, just compare a
prefix of the string that we control.
2021-03-02 14:00:13 -08:00
Saleem Abdulrasool
cc702e2d16 LanguageServerProtocolJSONRPCTests: add Windows stubs
This set of changes is the last set of changes required to build the
entire test suite on Windows.  Although the tests do not yet fully pass,
this is a prerequisite for getting the test suite passing.
2020-11-16 09:07:30 -08:00
Ben Langmuir
bb9560f2e2 Merge pull request #341 from compnerd/handling
Fix the Pipe handling on Windows to be correct
2020-11-02 11:56:06 -08:00
Saleem Abdulrasool
6a275d134c Fix the Pipe handling on Windows to be correct
This actually addresses the real issue that was ignored earlier about
pipes on Windows.  The FileHandle cannot provide a non-owning file
descriptor (the returned file descriptor would need to be explicitly
`_close`'d by the receiver).  Foundation now vends a `_handle` accessor
to the OS primitive handle.  Use this to create the dispatch loop for
messaging.  We now create the JSONRPCConnection from handles on Windows
which actually should help enable running some of the tests on Windows
as well.
2020-11-02 09:55:58 -08:00
Joe Heck
c58d6939cc convert tests from #file to using #filePath 2020-10-31 18:29:08 -07:00
Sebastian Fichtner
7a36a51014 Synchronously send error response on message decoding failure (#334)
* Replaces two logs since those don't result in response messages anymore
* Adds a func for sending messages synchronously, to get the two messages out before fatalError
2020-10-16 16:29:46 -07:00
Ben Langmuir
5449a2acb7 [jsonrpc] Workaround file descriptor lifetime issue
We should solve this in the JSONRPCConnection itself, but in the
meantime workaround by keeping pipes alive until the connection has
closed.
2020-06-09 13:20:15 -07:00
David Goldman
8b57352f3b Send didSave notifications to clangd if it supports it (#280)
* Send `didSave` notifications to clangd if it supports it

- Minor update to the LSP protocol for `didSave` and `colorProvider` to be more in line with the spec
- Only send color requests over to clangd if it supports it

Rationale for this change: clangd recently implemented didSave support,
it is used to rebuild preambles when the user edits a header file
referenced by an open file.

Change-Id: Ie6e2198bdeccb9d1b4083806c254475baadc2d2b
2020-06-03 14:20:38 -07:00
Ben Langmuir
6445a69029 [test] Fix double close in testCloseRace
Close the fd via the FileHandle rather than directly on the file
descriptor so that it does not get closed again when the pipe is
released. Fixes running test in parallel on Linux.
2020-04-08 11:55:21 -07:00
Ben Langmuir
8b9f019d94 Fix a build warning in ConnectionTests.swift 2020-04-01 10:45:34 -07:00
Ben Langmuir
fae2fe85a7 [JSONRPC] Do not exit until outstanding I/O has finished
Specifically, we care that all outstanding **writes** are finished
before we call the close handler, because otherwise we may (a) send
corrupted output during shutdown, or (b) drop notifications and replies
sent during the shutdown process.  The former is a potential issue for
clients that are not robust about parse failures, and the latter is an
issue for reproducibility and robustness during testing/debugging - in
particular, we have some integration tests that send data without
waiting for individual replies and they need to finish outstanding
replies before exiting.

rdar://60159448
2020-03-10 11:16:34 -07:00
Alex Hoppen
e2d7eedef8 Unify the naming of request and notification types
Request types should always have the suffix Request and notifications
should end with Notification.

Also moved all request and notification types into separate folders to
reduce the number of files in the LanguageServerProtocol folder.
2019-12-13 13:56:10 -08:00
Alex Hoppen
c3e70b5933 Update ServerCapabilities to match version 3.14 of the LSP spec 2019-12-12 17:17:35 -08:00
Alex Hoppen
f167126c8d Fix typo: JSONRPCConnection should be spelled with two 'n' 2019-11-29 10:20:02 -08:00
Ben Langmuir
dfe2a6bc76 [jsonrpc] Move close handler to start
Since the connection and message handler have a reciprocal need to know
about each other, move the closeHandler so that it has the opportunity
to call a method on the message handler if desired.
2019-11-21 11:56:37 -08:00