Commit Graph

111 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
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
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
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
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
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`
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
97a6e1c617 Handle notifications from sourcekitd on a serial queue 2023-10-06 10:49:03 -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
56713cb2ab Asyncify symbolInfo and definition 2023-10-05 13:31:49 -07:00
Alex Hoppen
599d47798a Asyncify declaration 2023-10-05 13:31:49 -07:00
Alex Hoppen
e3087b03fe Asyncify executeCommand 2023-10-05 13:31:49 -07:00
Alex Hoppen
411ded77a9 Asyncify documentDiagnostic 2023-10-05 13:31:49 -07:00
Alex Hoppen
9a05e5bc31 Asyncify inlayHints 2023-10-05 13:31:48 -07:00
Alex Hoppen
a2e2c563d9 Asyncify colorPresentation 2023-10-05 13:31:22 -07:00
Alex Hoppen
bfa8d321ed Asyncify documentSemanticTokens* 2023-10-05 13:31:22 -07:00
Alex Hoppen
84404215b6 Asyncify documentColor 2023-10-05 13:31:22 -07:00
Alex Hoppen
669b22f4df Asyncify documentSymbol 2023-10-05 13:31:22 -07:00
Alex Hoppen
377f7bafbd Asyncify documentSymbolHighlight 2023-10-05 13:31:22 -07:00
Alex Hoppen
19e22c57fa Asyncify codeCompletion 2023-10-05 13:30:41 -07:00
Alex Hoppen
479d54b89f Asyncify code actions 2023-10-03 08:09:00 -07:00
Alex Hoppen
6e7b5db9a2 Make hover return the request result as a return value 2023-10-03 08:09:00 -07:00
Alex Hoppen
1b6015f8aa Make the folding range request return the request result as an async return value 2023-10-03 07:56:49 -07:00
Alex Hoppen
dffcc939f7 Change the build system to only notify delegate about changed files, not about new build settings
This defines away an entire class of data races if delegate callbacks are delivered out-of-order. If we aren’t providing the new build settings in the delegate callback, then it doesn’t matter if two `fileBuildSettingsChanged` calls change order since they don’t carry any state.
2023-10-02 09:53:25 -07:00
Alex Hoppen
93dfc3dfbf Get the build settings of the main file for a given header in BuildSystemManager 2023-10-02 09:53:25 -07:00
Alex Hoppen
ebcdbb6839 Make SwiftLanguageServer and ClangLanguageServerShim call directly into SourceKitServer instead of through a LocalConnection
`LocalConnection` with its dynamic registration of a message handler made the overall design unnecessarily complicated. If we just call `SourceKitServer` from `ClangLanguageServerShim` and `SwiftLanguageServer` directly, it’s a lot more obvious, what’s going on, IMO.
2023-10-02 09:49:12 -07:00
Alex Hoppen
8eed2e24dc Migrate SwiftPMWorkspace to be an actor 2023-10-02 09:47:25 -07:00
Alex Hoppen
07eb45bb56 Wait for documents to be re-opened before setting the clangd status to be connected again 2023-10-02 09:44:14 -07:00
Alex Hoppen
f1548bd757 Call into the BuildSystemManager from SwiftLanguageServer to get build settings
Instead of storing build settings inside the language servers based on update notifications from the build system, always call into the `BuildSystemManager` to get the build settings.

Overall, I think this is a much clearer separation of concerns and will allow us to remove `SourceKitServer.documentToPendingQueue` in a follow-up commit as `SwiftLanguageServer` can always directly call into `BuildSystemManager` to get build settings and we don’t need to wait for the initial notification to receive the first build settings.

This requies `BuildServerBuildSystem` to keep track of the build settings it has received from the BSP server.

`ClangLanguageServer` still caches build settings locally. `ClangLanguageServer` will change to the same pull-based model in a follow-up commit.
2023-10-02 09:44:01 -07:00
Alex Hoppen
ded0cf0168 Migrate SwiftLanguageServer to an actor 2023-10-02 09:43:55 -07:00
Alex Hoppen
c4e50974d1 Make all the methods in ToolchainLanguageServer async
This is a preparation step for making `SwiftLanguageServer` and `ClangLanguageServerShim` actors.
2023-10-02 09:43:51 -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
cc5a83bc40 Wait for documents to be re-opened before setting the clangd status to be connected again 2023-09-28 22:37:57 -07:00
Alex Hoppen
23b2db0588 Call into the BuildSystemManager from SwiftLanguageServer to get build settings
Instead of storing build settings inside the language servers based on update notifications from the build system, always call into the `BuildSystemManager` to get the build settings.

Overall, I think this is a much clearer separation of concerns and will allow us to remove `SourceKitServer.documentToPendingQueue` in a follow-up commit as `SwiftLanguageServer` can always directly call into `BuildSystemManager` to get build settings and we don’t need to wait for the initial notification to receive the first build settings.

This requies `BuildServerBuildSystem` to keep track of the build settings it has received from the BSP server.

`ClangLanguageServer` still caches build settings locally. `ClangLanguageServer` will change to the same pull-based model in a follow-up commit.
2023-09-28 22:37:57 -07:00
Alex Hoppen
72e752fe78 Migrate SwiftLanguageServer to an actor 2023-09-28 22:37:45 -07:00
Alex Hoppen
0b345738a6 Make all the methods in ToolchainLanguageServer async
This is a preparation step for making `SwiftLanguageServer` and `ClangLanguageServerShim` actors.
2023-09-28 22:37:41 -07:00
Ben Barham
762532539e Revert "Make all the methods in ToolchainLanguageServer async"
This reverts commit a8b84256b3.
2023-09-28 15:51:21 -07:00
Ben Barham
7bc3f1710e Revert "Migrate SwiftLanguageServer to an actor"
This reverts commit 42ec5bba74.
2023-09-28 15:51:17 -07:00
Ben Barham
15bdcc42e1 Revert "Call into the BuildSystemManager from SwiftLanguageServer to get build settings"
This reverts commit 9dd38798bb.
2023-09-28 15:51:07 -07:00
Ben Barham
cd4e733de2 Revert "Wait for documents to be re-opened before setting the clangd status to be connected again"
This reverts commit b9fa20303d.
2023-09-28 15:50:45 -07:00
Alex Hoppen
b9fa20303d Wait for documents to be re-opened before setting the clangd status to be connected again 2023-09-27 16:51:54 -07:00
Alex Hoppen
9dd38798bb Call into the BuildSystemManager from SwiftLanguageServer to get build settings
Instead of storing build settings inside the language servers based on update notifications from the build system, always call into the `BuildSystemManager` to get the build settings.

Overall, I think this is a much clearer separation of concerns and will allow us to remove `SourceKitServer.documentToPendingQueue` in a follow-up commit as `SwiftLanguageServer` can always directly call into `BuildSystemManager` to get build settings and we don’t need to wait for the initial notification to receive the first build settings.

This requies `BuildServerBuildSystem` to keep track of the build settings it has received from the BSP server.

`ClangLanguageServer` still caches build settings locally. `ClangLanguageServer` will change to the same pull-based model in a follow-up commit.
2023-09-27 16:20:53 -07:00
Alex Hoppen
42ec5bba74 Migrate SwiftLanguageServer to an actor 2023-09-27 16:20:53 -07:00
Alex Hoppen
a8b84256b3 Make all the methods in ToolchainLanguageServer async
This is a preparation step for making `SwiftLanguageServer` and `ClangLanguageServerShim` actors.
2023-09-27 16:20:52 -07:00