Skip to content

Commit

Permalink
Merge pull request #18589 from SomeoneToIgnore/proper-resolve-adverti…
Browse files Browse the repository at this point in the history
…sement

Advertise completions and inlay hints resolve server capabilities based on the client capabilities
  • Loading branch information
Veykril authored Dec 3, 2024
2 parents aa38be8 + 4261ac7 commit c4e040e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
14 changes: 13 additions & 1 deletion crates/ide-completion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ide_db::{
},
items_locator,
syntax_helpers::tree_diff::diff,
FilePosition, RootDatabase,
FilePosition, FxHashSet, RootDatabase,
};

use crate::{
Expand Down Expand Up @@ -50,6 +50,18 @@ pub struct CompletionFieldsToResolve {
}

impl CompletionFieldsToResolve {
pub fn from_client_capabilities(client_capability_fields: &FxHashSet<&str>) -> Self {
Self {
resolve_label_details: client_capability_fields.contains("labelDetails"),
resolve_tags: client_capability_fields.contains("tags"),
resolve_detail: client_capability_fields.contains("detail"),
resolve_documentation: client_capability_fields.contains("documentation"),
resolve_filter_text: client_capability_fields.contains("filterText"),
resolve_text_edit: client_capability_fields.contains("textEdit"),
resolve_command: client_capability_fields.contains("command"),
}
}

pub const fn empty() -> Self {
Self {
resolve_label_details: false,
Expand Down
12 changes: 11 additions & 1 deletion crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use hir::{
sym, ClosureStyle, HasVisibility, HirDisplay, HirDisplayError, HirWrite, ModuleDef,
ModuleDefId, Semantics,
};
use ide_db::text_edit::TextEdit;
use ide_db::{famous_defs::FamousDefs, FileRange, RootDatabase};
use ide_db::{text_edit::TextEdit, FxHashSet};
use itertools::Itertools;
use smallvec::{smallvec, SmallVec};
use span::{Edition, EditionedFileId};
Expand Down Expand Up @@ -289,6 +289,16 @@ pub struct InlayFieldsToResolve {
}

impl InlayFieldsToResolve {
pub fn from_client_capabilities(client_capability_fields: &FxHashSet<&str>) -> Self {
Self {
resolve_text_edits: client_capability_fields.contains("textEdits"),
resolve_hint_tooltip: client_capability_fields.contains("tooltip"),
resolve_label_tooltip: client_capability_fields.contains("label.tooltip"),
resolve_label_location: client_capability_fields.contains("label.location"),
resolve_label_command: client_capability_fields.contains("label.command"),
}
}

pub const fn empty() -> Self {
Self {
resolve_text_edits: false,
Expand Down
22 changes: 6 additions & 16 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,15 +1446,9 @@ impl Config {
limit: self.completion_limit(source_root).to_owned(),
enable_term_search: self.completion_termSearch_enable(source_root).to_owned(),
term_search_fuel: self.completion_termSearch_fuel(source_root).to_owned() as u64,
fields_to_resolve: CompletionFieldsToResolve {
resolve_label_details: client_capability_fields.contains("labelDetails"),
resolve_tags: client_capability_fields.contains("tags"),
resolve_detail: client_capability_fields.contains("detail"),
resolve_documentation: client_capability_fields.contains("documentation"),
resolve_filter_text: client_capability_fields.contains("filterText"),
resolve_text_edit: client_capability_fields.contains("textEdit"),
resolve_command: client_capability_fields.contains("command"),
},
fields_to_resolve: CompletionFieldsToResolve::from_client_capabilities(
&client_capability_fields,
),
}
}

Expand Down Expand Up @@ -1614,13 +1608,9 @@ impl Config {
} else {
None
},
fields_to_resolve: InlayFieldsToResolve {
resolve_text_edits: client_capability_fields.contains("textEdits"),
resolve_hint_tooltip: client_capability_fields.contains("tooltip"),
resolve_label_tooltip: client_capability_fields.contains("label.tooltip"),
resolve_label_location: client_capability_fields.contains("label.location"),
resolve_label_command: client_capability_fields.contains("label.command"),
},
fields_to_resolve: InlayFieldsToResolve::from_client_capabilities(
&client_capability_fields,
),
implicit_drop_hints: self.inlayHints_implicitDrops_enable().to_owned(),
range_exclusive_hints: self.inlayHints_rangeExclusiveHints_enable().to_owned(),
}
Expand Down
19 changes: 15 additions & 4 deletions crates/rust-analyzer/src/lsp/capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Advertises the capabilities of the LSP Server.
use ide::{CompletionFieldsToResolve, InlayFieldsToResolve};
use ide_db::{line_index::WideEncoding, FxHashSet};
use lsp_types::{
CallHierarchyServerCapability, CodeActionKind, CodeActionOptions, CodeActionProviderCapability,
Expand Down Expand Up @@ -40,7 +41,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
})),
hover_provider: Some(HoverProviderCapability::Simple(true)),
completion_provider: Some(CompletionOptions {
resolve_provider: config.caps().completions_resolve_provider(),
resolve_provider: Some(config.caps().completions_resolve_provider()),
trigger_characters: Some(vec![
":".to_owned(),
".".to_owned(),
Expand Down Expand Up @@ -136,7 +137,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
inlay_hint_provider: Some(OneOf::Right(InlayHintServerCapabilities::Options(
InlayHintOptions {
work_done_progress_options: Default::default(),
resolve_provider: Some(true),
resolve_provider: Some(config.caps().inlay_hints_resolve_provider()),
},
))),
inline_value_provider: None,
Expand Down Expand Up @@ -176,8 +177,18 @@ impl ClientCapabilities {
Self(caps)
}

fn completions_resolve_provider(&self) -> Option<bool> {
self.completion_item_edit_resolve().then_some(true)
fn completions_resolve_provider(&self) -> bool {
let client_capabilities = self.completion_resolve_support_properties();
let fields_to_resolve =
CompletionFieldsToResolve::from_client_capabilities(&client_capabilities);
fields_to_resolve != CompletionFieldsToResolve::empty()
}

fn inlay_hints_resolve_provider(&self) -> bool {
let client_capabilities = self.inlay_hint_resolve_support_properties();
let fields_to_resolve =
InlayFieldsToResolve::from_client_capabilities(&client_capabilities);
fields_to_resolve != InlayFieldsToResolve::empty()
}

fn experimental_bool(&self, index: &'static str) -> bool {
Expand Down

0 comments on commit c4e040e

Please sign in to comment.