Commit Graph

71 Commits

Author SHA1 Message Date
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
Alex Hoppen
5c839f8640 Add support for non-URL URIs
According to the LSP specification, arbitrary URIs can be used as
document identifiers. Instead of internally assuming that all URIs are
URLs, use a DocumentURI enum to represent URIs. These can either be file
URLs or other URIs whose value as treated as an opaque string.
2019-11-20 09:41:48 -08:00
Ben Langmuir
10ae122f17 Sink Int extension to JSONRPC
This is the only user of this code, and it's not particularly great.
Sink it to reduce dependency surface area.
2019-11-19 10:52:23 -08:00
Ben Langmuir
f83a9f4476 Sink Result to SKSupport
It's not being used for anything interesting in LSP layers, so sink it
to minimize dependencies.
2019-11-19 10:31:15 -08:00
Ben Langmuir
ec3fd7f940 Sink firstIndex to its only user in JSONRPC
This isn't a particularly good implementation and it only has one user.
Move it down to reduce dependency surface area.
2019-11-19 10:19:09 -08:00
Alex Hoppen
05ecd26d08 Reorganize the repository into a set of bare LSP modules and SourceKit modules
We will be able to split the LSP modules off later. These LSP modules
will provide the ability to write custom LSP servers and clients in
Swift. The sourcekit-lsp repository will build on top of this new
package to provide an LSP implementation that creates a language server
for Swift and C-based-languages.
2019-11-14 10:35:06 -08:00
Ben Langmuir
6e4060732d [tsan] Fix race in testMessageBuffer
We don't need to check the message buffer in the middle of the test; it
suffices that we got the expectation fulfilled at the right times. The
check at the end of the test can be done by synchronizing via close()
before reading.
2019-10-04 16:15:31 -07:00
Ben Langmuir
a964dad129 [tsan] Fix race in a few JSONRPCConnectionTests
These tests don't really need to check the message buffer anyway, it was
mostly a sanity check. There is still a race in testMessageBuffer, which
actually has a reason to look at the buffer and will need to be handled
separately.
2019-10-04 16:11:20 -07:00
Ben Langmuir
38dc0097cf Merge pull request #162 from rmaz/buildtargets
Add workspace/buildTargets request
2019-10-04 14:19:04 -07:00
Ben Langmuir
81e46c7c46 [test] Flip the default value of allowUnexpectedNotification
This is/was mostly useful for testing specific notification
interactions. Most new tests shouldn't need it, so remove the
boilerplate.
2019-10-01 22:30:58 -07:00