Commit Graph

1658 Commits

Author SHA1 Message Date
Alex Hoppen
16aa082afe Fix a race condition in code completion
Each `sourcekitd` uses a single, global code completion session but we were managing code completion sessions on the `SwiftLanguageServer` level. This had two issues:
- Code completion is considered non-blocking on `SourceKitServer` and thus we could execute two concurrent code completion requests, which would conflict with each other.
- You could have multiple `SwiftLanguageServer`s that each have a connection to `sourcekitd` but share the same `sourcekitd` state. This shouldn't happen in the real world but does happen if we create multiple `SourceKitServer` instances in tests.
2023-10-16 09:59:27 -07:00
Alex Hoppen
68a90aac8b Change CodeCompletionSession to not have a circular reference to SourceKitServer
This just clean up the layering slightly.
2023-10-16 09:57:19 -07:00
Alex Hoppen
d9055b798d Remove client-side filtering for code completion
`SKCompletionOptions.serverSideFiltering` is `true` by default and I know of no editor that disables it. Delete it.

Fixes #863
rdar://116703670
2023-10-16 09:55:22 -07:00
Alex Hoppen
4bc4a22df9 Merge pull request #859 from ahoppen/ahoppen/migrate-to-oslog swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a swift-DEVELOPMENT-SNAPSHOT-2023-10-14-a 2023-10-14 07:16:24 -07:00
Alex Hoppen
f960d7ed9b Change logging to use OSLog
OSLog is the suggesting logging solution on Apple platforms and we should be using it there, taking advantage of the different log levels and privacy masking.

Switch sourcekit-lsp to use OSLog on Apple platforms and implement a logger that is API-compatible with OSLog for all uses in sourcekit-lsp and which can be used on non-Darwin platforms.

The goal of this commit is to introduce the new logging API. There are still improvements about what we log and we can display more privacy-insensitive information after masking. Those changes will be in follow-up commits.
2023-10-13 13:46:32 -07:00
Alex Hoppen
78a4fab40e Merge pull request #896 from ahoppen/ahoppen/simplify-tests
Simplify tests
swift-DEVELOPMENT-SNAPSHOT-2023-10-13-a
2023-10-13 13:43:20 -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
64ba40e5cc Make TestSourceKitLSPClient.serverOptions a static member on SourceKitServer.Options
Really, these options had nothing to do with `TestSourceKitLSPClient`, they are just the defaults that are used for all the tests.
2023-10-12 08:28:06 -07:00
Alex Hoppen
2120d124f7 Rename TestSourceKitServer to TestSourceKitClient
Really, what the class was mocking is a SourceKit-LSP client.
2023-10-12 08:28:06 -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
c4ff9d0592 Fix race conditions in code completion 2023-10-12 08:28:06 -07:00
fwcd
f0ee6b138b Merge pull request #891 from fwcd/fix-typo
Fix typo in `SemanticRefactoringError` doc comment
swift-DEVELOPMENT-SNAPSHOT-2023-10-12-a
2023-10-11 22:09:06 +01:00
Alex Hoppen
31152de26a Merge pull request #888 from ahoppen/ahoppen/older-toolchains
Make `PullDiagnosticsTests.testCodeActions` pass with older toolchains
swift-DEVELOPMENT-SNAPSHOT-2023-10-11-a
2023-10-11 08:04:02 -07:00
Alex Hoppen
779a3c3daf Merge pull request #890 from ahoppen/ahoppen/format
Format using swift-format
2023-10-11 08:00:03 -07:00
fwcd
2f01143c5e Fix typo in SemanticRefactoringError doc comment 2023-10-11 01:59:06 +01: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
eb47ba615e Make PullDiagnosticsTests.testCodeActions pass with older toolchains
The Fix-It message that we are testing here has changed in https://github.com/apple/swift/pull/67909. Accept both the old and the new message to make sure SourceKit-LSP tests also pass with older toolchains (e.g. if are using Xcode 15.0, which doesn’t contain the change yet).

rdar://116706363
2023-10-10 09:34:21 -07:00
Alex Hoppen
2fb2e3a917 Merge pull request #864 from ahoppen/ahoppen/setup-expectation
Wait for asynchronous setup in `BuildSystemTests` using an expectation instead of a semaphore
swift-DEVELOPMENT-SNAPSHOT-2023-10-10-a
2023-10-10 08:28:40 -07:00
Alex Hoppen
4fba0fdbbf Merge pull request #871 from ahoppen/ahoppen/no-queue-hopping
Don't hop on background queue to run `onExit`
2023-10-10 08:28:29 -07:00
Alex Hoppen
0b8611b156 Don't hop on background queue to run onExit
Since we use Swift Concurrency now, we no longer need to be worried about queues blocking each other, so the queue hopping is no longer necessary.
2023-10-09 15:41:13 -07:00
Alex Hoppen
d2834f33b8 Wait for asynchronous setup in BuildSystemTests using an expectation instead of a semaphore
Just cleaner because it will also fail if it times out.
2023-10-09 15:26:10 -07:00
Alex Hoppen
fbd0cd11c7 Merge pull request #856 from ahoppen/ahoppen/remove-dead-code swift-DEVELOPMENT-SNAPSHOT-2023-10-09-a swift-DEVELOPMENT-SNAPSHOT-2023-10-08-a 2023-10-07 18:18:11 -07:00
Alex Hoppen
32acbf52fd Remove FileBuildSettingsChange
This type wasn’t used anymore.
2023-10-06 18:07:20 -07:00
Alex Hoppen
16c3ae17c2 Remove functions that were never called 2023-10-06 18:07:20 -07:00
Alex Hoppen
d9da113ca7 Remove BuildServerBuildSystem.requestQueue
The queue isn’t used anymore.
2023-10-06 18:07:20 -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
203d585b77 Remove some dead completion handler code 2023-10-06 18:07:20 -07:00
Alex Hoppen
9e07784fb8 Remove the version of SourceKitD.send that took a completion handler 2023-10-06 18:07:19 -07:00
Alex Hoppen
db1c48b419 Remove withLanguageServiceAndWorkspace
This function was never called
2023-10-06 18:06:55 -07:00
Alex Hoppen
c98c16ef71 Merge pull request #857 from ahoppen/ahoppen/syntax-tree-manager
Store syntax trees in semantic token in syntax tree/semantic token managers instead of in the `Document`
swift-DEVELOPMENT-SNAPSHOT-2023-10-07-a
2023-10-06 18:05:53 -07:00
Alex Hoppen
c1771de104 Translate an if into a guard 2023-10-06 14:26:42 -07:00
Alex Hoppen
2d44263165 Keep track of semantic tokens in a SemanticTokensManager
Storing the semantic tokens inside `Document` was an anti-pattern because the semantic tokens only applied to Swift and were also being updated while the document contents themselves stayed constant.

Instead, we should store the semantic tokens in a separate `SemanticTokensManager` that only exists in the `SwiftLanguageServer` and has the sole responsibility of tracking semantic tokens.
2023-10-06 14:25:29 -07:00
Alex Hoppen
8837399c79 Move semantic highlighting into its own file
No code changes, just moving code around because `mergedAndSortedTokens` no longer belonged in DocumentTokens.swift
2023-10-06 14:25:07 -07:00
Alex Hoppen
88cd743b79 Introduce SyntaxTreeManager that keeps track of the SwiftSyntax trees for documents
This allows us to use Swift concurrency to await the computation of the SwiftSyntax tree for a given document instead of having to poll for its creation.
2023-10-06 14:25:06 -07:00
Alex Hoppen
1a7939304b Merge pull request #858 from ahoppen/ahoppen/serial-sourcekitd-notification-queue
Handle notifications from `sourcekitd` on a serial queue
swift-DEVELOPMENT-SNAPSHOT-2023-10-06-a
2023-10-06 14:00:24 -07:00
Alex Hoppen
97a6e1c617 Handle notifications from sourcekitd on a serial queue 2023-10-06 10:49:03 -07:00
Alex Hoppen
9a120c8140 Merge pull request #855 from AndreyKlebanov/fix-closed-handler
Don't call closeHandler if it is nil
2023-10-06 08:38:05 -07:00
Alex Hoppen
7ab3b048be Introduce an ID for DocumentSnapshot 2023-10-06 07:28:53 -07:00
Alex Hoppen
556a58a05e Make DocumentSnapshot not have a reference to its originating Document
The reference just isn’t needed and this makes everything clearer.
2023-10-06 07:26:27 -07:00
Alex Hoppen
818be5eb86 Make members of DocumentSnapshot immutable 2023-10-06 07:17:26 -07:00
Alex Hoppen
0ea522b4ad Merge pull request #853 from ahoppen/ahoppen/more-async-requests
Asyncify the handling of more requests
2023-10-06 06:54:57 -07:00
Alex Hoppen
da8f46b05d Asyncify handling of TypeHierarchySubtypesRequest 2023-10-05 13:31:49 -07:00
Alex Hoppen
d6f4ccd1b2 Asyncify handling of TypeHierarchySupertypesRequest 2023-10-05 13:31:49 -07:00
Alex Hoppen
cc91ecdb42 Asyncify handling of CallHierarchyOutgoingCallsRequest 2023-10-05 13:31:49 -07:00
Alex Hoppen
fa6e9f867b Asyncify handling of CallHierarchyIncomingCallsRequest 2023-10-05 13:31:49 -07:00
Alex Hoppen
58db28d22b Asyncify handling of PollIndexRequest 2023-10-05 13:31:49 -07:00
Alex Hoppen
d2de1a2ad7 Asyncify handling of WorkspaceSymbolsRequest 2023-10-05 13:31:49 -07:00
Alex Hoppen
c4155bc893 Asyncify handling of ShutdownRequest 2023-10-05 13:31:49 -07:00
Alex Hoppen
8a2215d37b Asyncify handling of InitializeRequest 2023-10-05 13:31:49 -07:00