Skip to content

Commit c2a05b4

Browse files
authored
[ty] Use bitflags for resolved client capabilities (#19393)
## Summary This PR updates the `ResolvedClientCapabilities` to be represented as `bitflags`. This allows us to remove the `Arc` as the type becomes copy. Additionally, this PR also fixed the goto definition and declaration code to use the `textDocument.definition.linkSupport` and `textDocument.declaration.linkSupport` client capability. This PR also removes the unused client capabilities which are `code_action_deferred_edit_resolution`, `apply_edit`, and `document_changes` which are all related to auto-fix ability.
1 parent fae0b5c commit c2a05b4

File tree

13 files changed

+157
-125
lines changed

13 files changed

+157
-125
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty_server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ty_python_semantic = { workspace = true }
2323
ty_vendored = { workspace = true }
2424

2525
anyhow = { workspace = true }
26+
bitflags = { workspace = true }
2627
crossbeam = { workspace = true }
2728
jod-thread = { workspace = true }
2829
lsp-server = { workspace = true }

crates/ty_server/src/server/api/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(super) fn clear_diagnostics(key: &DocumentKey, client: &Client) {
6464
///
6565
/// [publish diagnostics notification]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics
6666
pub(super) fn publish_diagnostics(session: &Session, key: &DocumentKey, client: &Client) {
67-
if session.client_capabilities().pull_diagnostics {
67+
if session.client_capabilities().supports_pull_diagnostics() {
6868
return;
6969
}
7070

crates/ty_server/src/server/api/notifications/did_change_watched_files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl SyncNotificationHandler for DidChangeWatchedFiles {
9696
let client_capabilities = session.client_capabilities();
9797

9898
if project_changed {
99-
if client_capabilities.diagnostics_refresh {
99+
if client_capabilities.supports_workspace_diagnostic_refresh() {
100100
client.send_request::<types::request::WorkspaceDiagnosticRefresh>(
101101
session,
102102
(),
@@ -111,7 +111,7 @@ impl SyncNotificationHandler for DidChangeWatchedFiles {
111111
// TODO: always publish diagnostics for notebook files (since they don't use pull diagnostics)
112112
}
113113

114-
if client_capabilities.inlay_refresh {
114+
if client_capabilities.supports_inlay_hint_refresh() {
115115
client.send_request::<types::request::InlayHintRefreshRequest>(session, (), |_, ()| {});
116116
}
117117

crates/ty_server/src/server/api/requests/goto_declaration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl BackgroundDocumentRequestHandler for GotoDeclarationRequestHandler {
5252

5353
if snapshot
5454
.resolved_client_capabilities()
55-
.type_definition_link_support
55+
.supports_declaration_link()
5656
{
5757
let src = Some(ranged.range);
5858
let links: Vec<_> = ranged

crates/ty_server/src/server/api/requests/goto_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl BackgroundDocumentRequestHandler for GotoDefinitionRequestHandler {
5252

5353
if snapshot
5454
.resolved_client_capabilities()
55-
.type_definition_link_support
55+
.supports_definition_link()
5656
{
5757
let src = Some(ranged.range);
5858
let links: Vec<_> = ranged

crates/ty_server/src/server/api/requests/goto_type_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl BackgroundDocumentRequestHandler for GotoTypeDefinitionRequestHandler {
5252

5353
if snapshot
5454
.resolved_client_capabilities()
55-
.type_definition_link_support
55+
.supports_type_definition_link()
5656
{
5757
let src = Some(ranged.range);
5858
let links: Vec<_> = ranged

crates/ty_server/src/server/api/requests/hover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl BackgroundDocumentRequestHandler for HoverRequestHandler {
5252

5353
let (markup_kind, lsp_markup_kind) = if snapshot
5454
.resolved_client_capabilities()
55-
.hover_prefer_markdown
55+
.prefers_markdown_in_hover()
5656
{
5757
(MarkupKind::Markdown, lsp_types::MarkupKind::Markdown)
5858
} else {

crates/ty_server/src/server/api/requests/semantic_tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl BackgroundDocumentRequestHandler for SemanticTokensRequestHandler {
4141
snapshot.encoding(),
4242
snapshot
4343
.resolved_client_capabilities()
44-
.semantic_tokens_multiline_support,
44+
.supports_multiline_semantic_tokens(),
4545
);
4646

4747
Ok(Some(SemanticTokensResult::Tokens(SemanticTokens {

crates/ty_server/src/server/api/requests/semantic_tokens_range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl BackgroundDocumentRequestHandler for SemanticTokensRangeRequestHandler {
5151
snapshot.encoding(),
5252
snapshot
5353
.resolved_client_capabilities()
54-
.semantic_tokens_multiline_support,
54+
.supports_multiline_semantic_tokens(),
5555
);
5656

5757
Ok(Some(SemanticTokensRangeResult::Tokens(SemanticTokens {

0 commit comments

Comments
 (0)