Skip to content

Commit

Permalink
Auto merge of #16182 - Veykril:world-symbols-focus-range, r=Veykril
Browse files Browse the repository at this point in the history
internal: Update world symbols request definiton, prefer focus range for macros

Prior to this, the symbol search would always jump to the defining macro call, not it jumps to the name in the macro call input if possible. This is a large improvement for assoc items in an attribute impl or trait.
  • Loading branch information
bors committed Dec 22, 2023
2 parents 20e09c6 + dca0e2e commit cd6a96f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ crossbeam-channel = "0.5.5"
dissimilar.workspace = true
itertools.workspace = true
scip = "0.3.1"
lsp-types = { version = "=0.94.0", features = ["proposed"] }
lsp-types = { version = "=0.95.0", features = ["proposed"] }
parking_lot = "0.12.1"
xflags = "0.3.0"
oorandom = "11.1.3"
Expand Down
2 changes: 2 additions & 0 deletions crates/rust-analyzer/src/caps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
"ssr": true,
"workspaceSymbolScopeKindFiltering": true,
})),
diagnostic_provider: None,
inline_completion_provider: None,
}
}

Expand Down
14 changes: 7 additions & 7 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ pub(crate) fn handle_document_symbol(
pub(crate) fn handle_workspace_symbol(
snap: GlobalStateSnapshot,
params: WorkspaceSymbolParams,
) -> anyhow::Result<Option<Vec<SymbolInformation>>> {
) -> anyhow::Result<Option<lsp_types::WorkspaceSymbolResponse>> {
let _p = profile::span("handle_workspace_symbol");

let config = snap.config.workspace_symbol();
Expand All @@ -479,7 +479,7 @@ pub(crate) fn handle_workspace_symbol(
res = exec_query(&snap, query)?;
}

return Ok(Some(res));
return Ok(Some(lsp_types::WorkspaceSymbolResponse::Nested(res)));

fn decide_search_scope_and_kind(
params: &WorkspaceSymbolParams,
Expand Down Expand Up @@ -519,13 +519,12 @@ pub(crate) fn handle_workspace_symbol(
fn exec_query(
snap: &GlobalStateSnapshot,
query: Query,
) -> anyhow::Result<Vec<SymbolInformation>> {
) -> anyhow::Result<Vec<lsp_types::WorkspaceSymbol>> {
let mut res = Vec::new();
for nav in snap.analysis.symbol_search(query)? {
let container_name = nav.container_name.as_ref().map(|v| v.to_string());

#[allow(deprecated)]
let info = SymbolInformation {
let info = lsp_types::WorkspaceSymbol {
name: match &nav.alias {
Some(alias) => format!("{} (alias for {})", alias, nav.name),
None => format!("{}", nav.name),
Expand All @@ -534,10 +533,11 @@ pub(crate) fn handle_workspace_symbol(
.kind
.map(to_proto::symbol_kind)
.unwrap_or(lsp_types::SymbolKind::VARIABLE),
// FIXME: Set deprecation
tags: None,
location: to_proto::location_from_nav(snap, nav)?,
container_name,
deprecated: None,
location: lsp_types::OneOf::Left(to_proto::location_from_nav(snap, nav)?),
data: None,
};
res.push(info);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ pub enum WorkspaceSymbol {}

impl Request for WorkspaceSymbol {
type Params = WorkspaceSymbolParams;
type Result = Option<Vec<lsp_types::SymbolInformation>>;
type Result = Option<lsp_types::WorkspaceSymbolResponse>;
const METHOD: &'static str = "workspace/symbol";
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ pub(crate) fn location_from_nav(
) -> Cancellable<lsp_types::Location> {
let url = url(snap, nav.file_id);
let line_index = snap.file_line_index(nav.file_id)?;
let range = range(&line_index, nav.full_range);
let range = range(&line_index, nav.focus_or_full_range());
let loc = lsp_types::Location::new(url, range);
Ok(loc)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/lsp-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ serde = { version = "1.0.192", features = ["derive"] }
crossbeam-channel = "0.5.6"

[dev-dependencies]
lsp-types = "=0.94"
lsp-types = "=0.95"
ctrlc = "3.4.1"

0 comments on commit cd6a96f

Please sign in to comment.