Commit Graph

31 Commits

Author SHA1 Message Date
Alex Hoppen
b479b2e874 Create a SwiftExtensions module
This allows us to share common Swift utility functions between SourceKit-LSP and LSPLogging.
2024-06-04 07:06:44 -07:00
Lokesh.T.R
087ea64ed3 Rename note to notification throughout the codebase wherever necessary 2024-05-29 17:58:04 +00:00
Alex Hoppen
da96d45443 Add a development subcommand to index a project
This allows us to run `sourcekit-lsp index --project /path/to/project` to index a project. Intended to debugging purposes, eg.
- Profile the time it takes to index a project
- See if the project can be indexed successfully
- Look at signposts generated during indexing in Instruments to see whether indexing or preparation is the bottleneck and how well we can parallelize tasks.
2024-05-21 22:29:52 -07:00
Alex Hoppen
195d3af74e Move LocalConnection to LSPTestSupport
We weren’t logging requests sent to a `TestSourceKitLSPClient` because we were assuming that `JSONRPCConnection` logs those requests in `SourceKitLSPServer`. But no logging happens in `LocalConnection`, which `TestSourceKitLSPClient` uses.

Since `LangaugeServerProtcol` can’t depend on `LSPLogging`, move the type to `LSPTestsSupport`.
2024-05-17 11:59:40 -07:00
Alex Hoppen
ee79512e0a Make LSPTestSupport 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
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
6a0a944563 Change #if swift(<5.11) to #if compiler(<5.11)
We want to check the compiler version, not the effective language version (which is 5.10 for a Swift 6 compiler).
2024-03-12 14:48:18 -07:00
Alex Hoppen
a6fdd1d0d8 Merge pull request #1117 from ahoppen/ahoppen/sendability
Add Sendable annotations to LanguageServerProtocol, LSPLogging and SKSupport
2024-03-07 18:27:26 -08: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
fa54ef1748 Add Sendable annotations to LanguageServerProtocol 2024-03-03 21:50:38 -08:00
Alex Hoppen
4b32dfe121 Guard usages of @retroactive by Swift 5.11, not 5.10
I incorrectly thought that `@retroactive` gets introduced by Swift 5.10 but it’s only available in Swift 5.11.
2024-01-11 09:41:18 -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
d2e79c8128 Add @retroactive annotations 2023-11-21 17:40:17 -08:00
Alex Hoppen
324a7daddd Change the Request type to be a fileprivate RequestAndReply in SourceKitServer
Since asyncifying all the request handling, `Request` only had a few lingering uses. Remove most of them and shrink it down to a type that only contains the request’s parameters and the reply block of the corresponding type.

And while we’re doing this, also move `NotificationType.forLogging` out of the `LanguageServerProtocol` module to remove the dependency from `LanguageServerProtocol` on `LSPLogging`.

Resolves #881
Resolves #936
rdar://116705662
rdar://117562587
2023-10-30 13:45:16 -07:00
Alex Hoppen
204236792e Merge pull request #931 from ahoppen/ahoppen/remove-notification-type
Remove the `Notification` type
2023-10-27 06:01:43 -07: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
71dfd489ae Remove CancellationToken
This is no longer needed because we handle cancellation on the `Task` level.
2023-10-26 11:03:15 -07:00
Alex Hoppen
9ba3de57b4 Rename TestClient to TestMessageHandler
`TestClient` was confusing because we have a bunch of variables `testClient: TestSourceKitLSPClient`. `TestMessageHandler` should describe the type’s job a lot better.

There’s probably room for more cleanup in the entire JSONRPC connection testing area but I’m not touching that for now.
2023-10-24 18:27:33 -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
4495256b35 Remove the queue parameter from Connection.send
We don’t actually care about the queue that we receive the reply on anymore since we migrated everything™ to actors/async/await.
2023-10-06 18:07:20 -07:00
Ben Barham
e540e169bc Revert "Show a progress indicator in the editor if SourceKit-LSP is reloading packages" 2023-07-17 21:56:35 -07:00
Alex Hoppen
24317f1e97 Show a progress indicator in the editor if SourceKit-LSP is reloading packages
I noticed that the initial package loading can take ~5s. It’s good behavior to inform the client that sourcekit-lsp is busy reloading the package, showing the user that semantic functionality might not be ready yet.

https://github.com/apple/sourcekit-lsp/issues/620
rdar://111917300
2023-07-17 11:08:20 -07:00
Saleem Abdulrasool
d1b1b48908 SourceKitLSPTests: replace some fatalError with XCTFail
This replaces many instances of `fatalError` with `XCTFail`.  Although
these code paths should not come to pass, there are currently failures
in the test suite on Windows where these trigger.  By using `XCTFail`
instead, we allow the tests to continue execution which is helpful for
investigating the current state and make progress towards fixing the
issues.
2022-07-17 17:30:18 -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
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
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
Alex Hoppen
f167126c8d Fix typo: JSONRPCConnection should be spelled with two 'n' 2019-11-29 10:20:02 -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