Commit Graph

50 Commits

Author SHA1 Message Date
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
acb5239440 Increase test timeout
In some CI environments, some tests exceed the 2 min timeout.
2024-02-19 08:20:58 -08:00
Alex Hoppen
378b62d8e1 Fix warnings when building sourcekit-lsp 2024-01-31 17:59:05 -08:00
Alex Hoppen
55f2df8317 Increase default timeout to 3 minutes
In some cases, when Xcode doesn’t have a module cache for SDK modules, building SwiftPM project in the tests can take longer than 1 minute. Increase the timeout to 2 minutes.
2024-01-22 15:49:50 -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
3e73f11de0 Migrate ToolchainRegistry to be an actor 2024-01-09 17:17:31 -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
3d17caded6 Implement request cancellation
When receiving a `CancellationNotification`, we cancel the task that handles the request with that ID.

This will cause `cancel_notification` to be sent to sourcekitd or a `CancellationNotification` to be sent to `clangd`, which ultimately cancels the request.

rdar://117492860
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
4086874cf3 Implement push diagnostics in terms of DocumentDiagnosticsRequest
Instead of listening for document updates sent from `sourcekitd` and sending a `PublishDiagnosticsNotification` based on the `sourcekitd` notification, wait for a little while and then execute an internal `DocumentDiagnosticsRequest` to load diagnostics and send them to the client.

This has two advantages:
- It unifies the two diagnostic implementations
- It removes the need to keep track of semantic diagnostics in `SwiftLanguageServer`
- It gets us one step closed to opening and editing documents in `syntactic_only` mode. The only thing that is left now are semantic tokens.
2023-10-18 13:48:23 -07:00
Alex Hoppen
6679652cde Remove awaitTask
It turns out that `XCTestCase.setUp` can indeed be `async` and we thus don’t actually need `awaitTask`
2023-10-12 08:30:07 -07:00
Alex Hoppen
0e85e544a2 Remove unused functions from TestClient 2023-10-12 08:28:06 -07:00
Alex Hoppen
efd55c2208 Simplify TestSourceKitServer
- Remove the JSONRPC connection kind between `TestSourceKitServer` and `SourceKitServer`
  - It wasn’t actually used and the connection abstraction just made things more complicated than they needed to be
- Send requests and notifications to `SourceKitServer` by directly calling into `SourceKitServer.handle` instead of going through a `Connection`. This makes the code a lot easier to understand statically
- Make `TestSourceKitServer` conform to `MessageHandler` instead of going through `TestClient`
  - IMO this centralizes all the handling and makes it a lot easier to follow. `TestClient` didn’t do a whole bunch anyway.
- Allow async awaiting of next notifications instead of having to register a `handleNextNotification` handler before expecting the notification to be emitted.
  - This allows us to remove quite a few `XCTExpectation`s in test cases
- Change `sendSync` function that sends a request and returns the result to be `async`
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
Alex Hoppen
8eed2e24dc Migrate SwiftPMWorkspace to be an actor 2023-10-02 09:47:25 -07:00
Alex Hoppen
b36352b892 Make sourcekit-lsp compatible with SDKs < macOS 13.3 2023-10-02 09:43:45 -07:00
Alex Hoppen
09dc0bc82f Make SourceKitServer an actor
Unfortuantely, we have a few potential out-of-order exeuction possibilities while we migrate everything else to also be asyncronous. But those should be low-probability issues that we can fix in follow-up commits, so I think it’s fine for now. All of these places are marked with `FIXME: (async)`
2023-10-02 09:43:42 -07:00
Alex Hoppen
b22af35eb1 Revert asyncificaiton changes
The asyncification changes caused some non-deterministic test failures. I believe that some of these are due to race conditions that are the result of the partial transition to actors.

Instead of merging the asyncification piece by piece, I will collect the changes asyncification changes in a branch and then qualify that branch througougly (running CI multiple times) before merging it into `main`.
2023-09-30 10:09:59 -07:00
Alex Hoppen
fccbc3973c Migrate SwiftPMWorkspace to be an actor 2023-09-29 16:55:51 -07:00
Alex Hoppen
4263313b20 Make sourcekit-lsp compatible with SDKs < macOS 13.3 2023-09-27 09:48:21 -07:00
Alex Hoppen
351eaa2393 Make SourceKitServer an actor
Unfortuantely, we have a few potential out-of-order exeuction possibilities while we migrate everything else to also be asyncronous. But those should be low-probability issues that we can fix in follow-up commits, so I think it’s fine for now. All of these places are marked with `FIXME: (async)`
2023-09-27 09:48:21 -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
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
Alex Hoppen
5af65fb184 Increase default timeout to 60 seconds
The reduced timeout of 15 seconds was causing issues in CI.
2022-07-21 20:20:37 +02: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
Alex Hoppen
2e76be7c96 Remove placeholders from code actions instead of replacinng them by snippets
#481 replaced SourceKit placeholders (like `<#code#>`) by LSP snippets for code actions, which are used to represent SourceKit refactoring and diagnostic Fix-Its. But LSP snippets are only supported for code completion, not for code actions. This results in LSP snippets like ${1:code} being inserted into the editor.

Instead of replacing SourceKit placeholders by LSP placeholders, we should just remove them altogether from the code action response.

rdar://92447079 [#488]
2022-04-28 10:59:33 +02:00
Kyle
6d1b09ad5b Remove available check below macOS 10.15.4
Since the Package.swift declare the minimal target for macOS is 10.15.4,
we can remove the uncessary available check code
2021-12-05 17:07:34 +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
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