Commit Graph

153 Commits

Author SHA1 Message Date
Alex Hoppen
3e432c495a Merge pull request #965 from joehsieh/cache-diagnostics 2024-01-11 23:41:21 -08:00
Alex Hoppen
1e72500f1a Merge pull request #1017 from ahoppen/ahoppen/secondary-cursor-info-results
Report secondary cursor info results
2024-01-11 09:30:10 -08:00
Alex Hoppen
7572fb96ee Report secondary cursor info results
rdar://119163908
2024-01-10 21:05:31 -08:00
joehsieh
8dcfb30cdb Add cache to avoid requesting diagnostics from sourcekitd frequently
Move the responsibility of sending requests to get diagnostics from SwiftLanguageServer to DiagnosticReportManager

Make buildSettings as part of the key to the cache

Add ReportTask and refine the code

Reset cache for reportTasks if needed

Finetune the wordings and logics

Solve conflicts

Only remove necessary items from cache

Refine the code
2024-01-11 10:36:37 +09:00
Alex Hoppen
d55e2a2b88 Merge pull request #1007 from ahoppen/ahoppen/concurrent-map
Add a `concurrentMap` function to `Collection`
2024-01-10 15:52:39 -08:00
Alex Hoppen
ca470335e6 Merge pull request #1008 from ahoppen/ahoppen/skd-array-dictionary-from-literal
Support creation of SKDRequest(Dictionary|Array) from literals
2024-01-09 13:26:00 -08:00
Alex Hoppen
a73d0df77b Add a concurrentMap function to Collection
I find this a lot more intuitive to use than `TaskGroup`.
2024-01-08 18:34:24 -08:00
Alex Hoppen
3991fae867 Define methods on SourceKitD to create arrays and dictionaries instead of using skd postfix syntax 2024-01-08 18:06:31 -08:00
Marcin Krzyzanowski
79ca4c0ac6 Remove redundant typealias 2024-01-08 23:51:09 +01:00
Marcin Krzyzanowski
2c616f7838 Refactor SemanticTokenTypes, SemanticTokenModifiers 2023-12-26 22:55:12 +01:00
Alex Hoppen
f901cc9250 Support creation of SKDRequest(Dictionary|Array) from literals
IMO this makes it a lot clearer which keys are present in the request dictionaries because we are no longer mutating them on the fly.
2023-12-22 22:29:11 -08:00
Alex Hoppen
f32e7dd51c Merge pull request #999 from ahoppen/ahoppen/folding-range-improvements
Improve code folding
2023-12-15 07:43:49 -08:00
Alex Hoppen
c8b2f76adc Move FoldingRange to its own file
No code change here.
2023-12-13 16:00:35 -08:00
Alex Hoppen
997ef38916 Support rename across Swift files
rdar://118995700
2023-12-12 17:34:34 -08:00
Alex Hoppen
8acc5bd999 Factor related identifiers request into a separate file
This allows use to re-use related identifiers when implementing rename
2023-12-09 08:34:40 -08:00
Alex Hoppen
f293741dca Merge pull request #981 from ahoppen/ahoppen/never-error-for-diagnostics-request
Never return error for diagnostics request
2023-12-05 10:03:45 -08:00
Alex Hoppen
4c8aea29c3 Never return error for diagnostics request
VS Code does not request diagnostics again for a document if the diagnostics request failed. Since sourcekit-lsp usually recovers from failures (e.g. after sourcekitd crashes), this is undesirable. Instead of returning an error, return empty results.
2023-11-27 19:39:22 -08:00
Alex Hoppen
e6cf72317d Merge pull request #975 from ahoppen/ahoppen/normalize-identifier-start
Support cursor info-based requests when cursor is placed at the end of an identifier
2023-11-27 15:36:19 -08:00
Alex Hoppen
f5e26e4b95 Support cursor info-based requests when cursor is placed at the end of an identifier
VS Code considers the position after an identifier as part of an identifier. Ie. if you have `let foo| = 1`, then it considers the cursor to be positioned at the identifier. This scenario is hit, when selecting an identifier by double-clicking it and then eg. performing jump-to-definition. In that case VS Code will send the position after the identifier.
`sourcekitd`, on the other hand, does not consider the position after the identifier as part of the identifier.
To bridge the gap here, normalize any positions inside, or directly after, an identifier to the identifier's start.

Fixes #820
rdar://115557453
2023-11-23 20:22:05 -08:00
Alex Hoppen
2aedb85a1f Don't cancel cursor info and related identifiers requests on subsequent requests
SourceKit-LSP supports explicit cancellation and thus we don’t need to do the implicit cancellation of cursor info and related identifiers on subsequent requests.
2023-11-21 17:45:10 -08:00
Alex Hoppen
1a23153fd5 When sourcekitd crashes, log the file contents with which it crashed and the request
This should make it a lot easier to reproduce sourcekitd crashes.
2023-10-31 08:30:54 -07:00
Alex Hoppen
c37b4b8a8c Always require a prefix for orLog calls
Otherwise it’s very easy to end up with log messages like `requestCancelled` for which it’s not clear where they are coming from.
2023-10-30 16:55:50 -07:00
Alex Hoppen
f4a07df3c5 Merge pull request #943 from ahoppen/ahoppen/latest-snapshot-throw
Make `DocumentManager.latestSnapshot` throw if no snapshot exists for the URI
2023-10-30 13:56:01 -07:00
Alex Hoppen
8d71b317a4 Merge pull request #946 from ahoppen/ahoppen/remove-connection-sendsync
Remove `Connection.sendSync`
2023-10-27 14:04:00 -07:00
Alex Hoppen
96e0e48b0d Make DocumentManager.latestSnapshot throw if no snapshot exists for the URI
This simplifies most calls that would log an error + return an empty response if no document was found.
2023-10-27 12:59:44 -07:00
Alex Hoppen
baa450a602 Remove Connection.sendSync
All callers should call the async version `Connection.send`.
2023-10-27 10:42:00 -07:00
Alex Hoppen
5bdd6f253b Refactor SwiftLanguageServer to be able to call the async version of SourceKitD.send
Resolves #869
rdar://116703689
2023-10-26 21:38:25 -07:00
Alex Hoppen
c667741b7e Change most SourceKitD.sendSync calls to call the async alternative 2023-10-26 21:38:25 -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
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
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
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
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