Commit Graph

315 Commits

Author SHA1 Message Date
Alex Hoppen
6d2709d46f Remove the fallback value from SourceKitServer.handleRequest
It’s not entire clear why we have a fallback value if no document service can serve a request and I checked that VS Code behaves if we return empty results for jump to definition or if we return an error. To simplify the codebase, we should just throw an error here and remove the `fallback` parameter from `handleRequest`.

Resolves #862
rdar://116703662
2023-10-26 21:42:53 -07:00
Alex Hoppen
d043dc068d Merge pull request #860 from ahoppen/ahoppen/cancellation
Implement request cancellation
2023-10-26 15:34:38 -07:00
Alex Hoppen
9ebee17ea8 Merge pull request #926 from ahoppen/ahoppen/document-symbols-syntax
Implement DocumentSymbolsRequest using SwiftSyntax
2023-10-26 11:59:17 -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
973c382d9c Implement DocumentSymbolsRequest using SwiftSyntax 2023-10-26 09:42:08 -07:00
Alex Hoppen
87dd95e779 Merge pull request #927 from ahoppen/ahoppen/mini-improvements
Minor improvements to SwiftLanguageServer.swift
2023-10-26 09:37:46 -07:00
Alex Hoppen
69d22daed1 Format SwiftLanguageServer.swift 2023-10-25 21:23:09 -07:00
Alex Hoppen
59cc291668 Don’t log a fault if the publish diagnostics notification is cancelled
Cancelling the publish diagnostics notificaiton because there was an edit is totally normal and nothing to be logged at the `fault` level.
2023-10-25 21:23:09 -07:00
Alex Hoppen
a1f909ae2e Introduce a new sub-logging scope for the implicitly triggered publish diagnostics notification
Just makes it clearer why some logs are being triggered if you know that it’s for the publish diagnostics notification.
2023-10-25 21:23:09 -07:00
Alex Hoppen
1b3fd5f1ab Implement the document color request using the SwiftSyntax tree 2023-10-25 14:17:02 -07:00
Alex Hoppen
c5c605d81d Merge pull request #912 from ahoppen/ahoppen/semantic-tokens-request
Load semantic tokens from a document using a sourcekitd request instead of the 0,0 edit
2023-10-24 17:51:46 -07:00
Alex Hoppen
1d10f82d80 Make SyntaxHighlightingTokenParser.parseTokens that take an inout parameter private
This simlifies the callers of `SyntaxHighlightingTokenParser`.
2023-10-24 08:13:20 -07:00
Alex Hoppen
645b5110e9 Merge pull request #915 from GeorgeLyon/dev/george/compilation-db-search-paths 2023-10-23 21:03:59 -07:00
George
170b44bb05 Add support for compile databases not at the root of the workspace 2023-10-21 05:17:01 +00:00
Alex Hoppen
ffbf025896 Open and edit documents in syntactic-only mode in sourcekitd
With this change, opening and editing a document no longer causes a non-cancellable AST build. Instead, all semantic information is retrieved via requests that can be cancelled (after we implement cancellation).
2023-10-20 09:38:35 -07:00
joehsieh
98ba3ee7d8 Remove isFallback from func buildSettings for FallbackBuildSystem 2023-10-20 10:04:18 +09:00
Alex Hoppen
080e664363 Load semantic tokens from a document using a sourcekitd request instead of the 0,0 edit
This allows us to cancel the semantic tokens request. It is also the last step to allow us to open and edit documents in syntactic-only mode.

It also means that we no longer need to send a `WorkspaceSemanticTokensRefreshRequest` to the client after sourcekitd has updated its semantic tokens since with the new design the `DocumentSemanticTokensRangeRequest` will simply return the results once it has the updated semantic token.
2023-10-19 17:46:58 -07:00
Alex Hoppen
5c2218902c Merge pull request #895 from divalue/swift-syntax-api-incompatible-changes
Fix swift-syntax API incompatible changes
2023-10-19 17:07:34 -07:00
Alex Hoppen
d231263257 Remove underscored _log* functions from SourceKitServer
Makes the logs more readable and unifies the logging of the request duration time and its result.
2023-10-18 21:55:22 -07:00
Alex Hoppen
35779ece2e Remove [weak self] dance in ClangLanguageServerShim.shutdown
This is not needed and was actually incorrect because the continuation was never resumed if `self` was `nil`.
2023-10-18 21:46:55 -07:00
Alex Hoppen
f7735bd276 Log the request handling duration 2023-10-18 21:46:55 -07:00
Alex Hoppen
85dc39ce1d Set a request/notification ID as the logging scope
This will use a unique identifier for the `category` of the logger, so that we can corrolate log messages to the request that caused them.
2023-10-18 21:46:55 -07:00
Alex Hoppen
86437c0c4c Introduce handleImpl for request and notification handling
This reduces the nesting level by 1 and makes it easier to add more logging in the future.
2023-10-18 21:46:55 -07:00
Alex Hoppen
8331b9bf96 Merge pull request #902 from ahoppen/ahoppen/unify-diagnostics 2023-10-18 20:49:49 -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
1458d06937 Add more fine grained dependency tracking to AsyncQueue
Instead of just having barriers and non-barriers, this allows `AsyncQueue` to track dependencies between tasks at a more fine-grained level.

For example, we can now specify that requests that affect one document only depend on edits to that same document and are not blocked by edits to any other document. As a consequence, a busy `sourcekitd` will not block requests from `clangd` to be executed and vice versa.

Resolves #875
rdar://116705652
2023-10-16 17:36:53 -07:00
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
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
c4ff9d0592 Fix race conditions in code completion 2023-10-12 08:28:06 -07:00
Dmitrii Valuev
eae3d0ae0e Fix parseIncrementally API incompatible changes 2023-10-12 17:18:26 +03:00
fwcd
f0ee6b138b Merge pull request #891 from fwcd/fix-typo
Fix typo in `SemanticRefactoringError` doc comment
2023-10-11 22:09:06 +01: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
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
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
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`
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
7ab3b048be Introduce an ID for DocumentSnapshot 2023-10-06 07:28:53 -07:00