Commit Graph

205 Commits

Author SHA1 Message Date
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
Alex Hoppen
6f342e2b82 Remove static shared toolchain registry
Global state is never a good thing and we needed to modify it in tests. The design becomes a lot cleaner if we explicitly pass the toolchain registry around.
2024-01-09 17:17:31 -08:00
Alex Hoppen
3e73f11de0 Migrate ToolchainRegistry to be an actor 2024-01-09 17:17:31 -08:00
Alex Hoppen
527600e977 Support the prepare rename request
This allows us to return the current compound decl name when renaming a function, which will get populated as the default value for the text field in which the user enters the new symbol name.

rdar://118995649
2023-12-20 09:43:26 -08:00
Alex Hoppen
b381811710 Merge pull request #1000 from ahoppen/ahoppen/wrap-logging-category 2023-12-18 18:04:12 -08:00
Alex Hoppen
c36a854e7a Wrap request and notification ID for the purpose of logging scopes
OSLog only allows the creation of 4000 logger objects, which means that logging will crash on the 4000th request to sourcekit-lsp (which would create the 4000th os_log object because it is the 4000th distinct category in which we are logging).

To circumvent this problem, only use the last two digits of the request and notification ID for the logging scope and wrap around afterwards. This should still allow us to tell apart log messages from concurrently handled requests/notifications while only using 200 os_log objects, which means we stay well clear of the 4000 limit.

rdar://119221355
2023-12-14 08:22:36 -08:00
Alex Hoppen
e08f0a906a Set the renameProvider capability 2023-12-13 14:37:35 -08:00
Alex Hoppen
997ef38916 Support rename across Swift files
rdar://118995700
2023-12-12 17:34:34 -08:00
Alex Hoppen
d931806c69 Merge pull request #988 from z2oh/configure-workspace-type
Allow configuring workspace type via flag
2023-12-12 10:50:52 -08:00
Alex Hoppen
ce9fdf9258 Merge pull request #990 from ahoppen/ahoppen/rename
Implement local rename within the current file
2023-12-11 19:39:35 -08:00
Alex Hoppen
777f1dc463 Add support for rename within the current file
rdar://117822427
2023-12-09 08:35:13 -08:00
Jeremy Day
c006421667 Switch to more descriptive case names 2023-12-08 15:23:03 -08:00
Jeremy Day
3278ff0612 Enable per-workspace configuration of default workspace type 2023-12-08 11:06:11 -08:00
Alex Hoppen
96905aaf16 Add a request to get all tests within a file 2023-12-06 17:40:21 -08:00
Alex Hoppen
446f9280da Add a request to list all the tests within the current workspace
Fixes #611
rdar://98710526
2023-12-06 17:40:21 -08:00
Alex Hoppen
4077ce360d Don’t use the best local declaration when jumping to definition of a C function
For non-Swift symbols, we need to perform an index lookup because the best local declaration will point to a header file but jump-to-definition should prefer the implementation (there's the declaration request to jump to the function's declaration).

rdar://119243893
2023-12-06 11:08:44 -08:00
Jeremy Day
cafc63ea98 Add --workspace-type flag 2023-12-06 10:29:19 -08:00
Alex Hoppen
ed410e6503 Merge pull request #977 from ahoppen/ahoppen/jump-to-override
Show overriden functions when performing jump-to-definition on a dynamic call
2023-12-05 16:18:46 -08:00
Alex Hoppen
c7bd8c9e8f Consider all symbol replies from clangd dynamic 2023-12-04 18:49:36 -08:00
Alex Hoppen
84fdea9e05 Filter overrides in DefinitionRequest by receiver types 2023-11-29 09:03:36 -08:00
Alex Hoppen
1ffa825b3f Remove extractIndexedOccurences
`extractIndexedOccurences` mostly dealt with how to create a fallback value and we didn’t support fallback values in 3/4 cases. Remove it, simplifying the callers of `extractIndexedOccurances` along the way.
2023-11-29 09:02:19 -08:00
Alex Hoppen
4052465905 Show overriden functions when performing jump-to-definition on a dynamic call
Fixes #809
rdar://114864256
2023-11-29 09:02:02 -08:00
Alex Hoppen
33f4612243 Add support for different arguments per workspace
Fixes #663
rdar://101815704
2023-11-28 11:19:09 -08:00
Alex Hoppen
ac3eb32e65 Format sources with swift-format 2023-10-31 19:30:31 -07:00
Alex Hoppen
e0173c8740 Merge pull request #956 from ahoppen/ahoppen/dont-log-error-for-unknown-notifications
Reduce logging level for unknown notifications or requests
2023-10-31 17:05:43 -07:00
Alex Hoppen
35c52c7590 Allow creation of TaskMetadata for all known notification and request types
Previously, we would sometimes log errors for example for the `setTrace` notification sent by VS Code. To avoid those logs, add cases for all known requests and notifications to the `TaskMetadata` initializers.
2023-10-31 09:12:24 -07: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
33fa4c5487 Merge pull request #951 from ahoppen/ahoppen/signpost
Emit signposts for request handling
2023-10-31 08:27:24 -07:00
Alex Hoppen
cc40dfb1d8 Merge pull request #937 from ahoppen/ahoppen/remove-request-type
Change the `Request` type to be a fileprivate `RequestAndReply` in `SourceKitServer`
2023-10-31 08:25:49 -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
47e7a13ce6 Emit signposts for request handling
This allows you to trace sourcekit-lsp in Instruments to get a feeling for how long requests take to be handled.
2023-10-30 13:53:59 -07: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
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
204b1ce8ba Merge pull request #935 from ahoppen/ahoppen/throw-error-instead-of-fallback
Remove the fallback value from `SourceKitServer.handleRequest`
2023-10-27 06:02:39 -07:00
Alex Hoppen
8457f84b12 Merge pull request #930 from ahoppen/ahoppen/log-reply
Increase log level for request responses
2023-10-27 06:01:51 -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
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
b88977201e Increase log level for request responses
The request responses are interesting to see to diagnose issues. Log them at the `log` instead of `debug` level instead.
2023-10-26 21:34:14 -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
996df8c597 Introduce a BarrierRequest that ensures all messages are handled before it replies
We could get into a race condition in `testAddFile` where the `DidChangeWatchedFilesNotification` would get handled after we try getting completion results that rely on it.

In a real-world use case, this is OK. Completion might still be incorrect until `DidChangeWatchedFilesNotification` gets handled but it will catch up eventually  - usually earlier than later because in real-world scenarios the `DidChangeWatchedFilesNotification` and completion request are more than a few milliseconds apart.

In test, however, we need to guarantee deterministic ordering. Introduce a `BarrierRequest` that has `TaskMetadata.globalConfigurationChange` and thus ensures that all notifications and requests before it have finished before returning. We can run this fake request after sending the `DidChangeWatchedFilesNotification` to make sure that it is handled.

An alternative would be to mark `DidChangeWatchedFilesNotification` as `TaskMetadata.globalConfigurationChange`. But I would really like to avoid introducing a global ordering barrier between requests for a notification that is, for example, sent whenever a `.swift` file in the `.build` directory changes (e.g. on every package update).
2023-10-26 18:23:41 -07:00
Alex Hoppen
a0ab315719 Remove an unnecessary capture of self 2023-10-26 18:23:40 -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
George
170b44bb05 Add support for compile databases not at the root of the workspace 2023-10-21 05:17:01 +00: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
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