Rollup merge of #133158 - lnicola:sync-from-ra, r=lnicola

Subtree update of `rust-analyzer`

r? `@ghost`
This commit is contained in:
Jacob Pratt 2024-11-18 02:24:36 -05:00 committed by GitHub
commit 194c76ef0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 15 deletions

View File

@ -2625,18 +2625,18 @@ checksum = "672423d4fea7ffa2f6c25ba60031ea13dc6258070556f125cc4d790007d4a155"
[[package]] [[package]]
name = "xshell" name = "xshell"
version = "0.2.6" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437" checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d"
dependencies = [ dependencies = [
"xshell-macros", "xshell-macros",
] ]
[[package]] [[package]]
name = "xshell-macros" name = "xshell-macros"
version = "0.2.6" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547"
[[package]] [[package]]
name = "xtask" name = "xtask"

View File

@ -1,7 +1,7 @@
use either::Either; use either::Either;
use ide_db::FxHashMap; use ide_db::FxHashMap;
use itertools::Itertools; use itertools::Itertools;
use syntax::{ast, ted, AstNode, SmolStr, ToSmolStr}; use syntax::{ast, syntax_editor::SyntaxEditor, AstNode, SmolStr, SyntaxElement, ToSmolStr};
use crate::{AssistContext, AssistId, AssistKind, Assists}; use crate::{AssistContext, AssistId, AssistKind, Assists};
@ -24,6 +24,11 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
let record = let record =
path.syntax().parent().and_then(<Either<ast::RecordExpr, ast::RecordPat>>::cast)?; path.syntax().parent().and_then(<Either<ast::RecordExpr, ast::RecordPat>>::cast)?;
let parent_node = match ctx.covering_element() {
SyntaxElement::Node(n) => n,
SyntaxElement::Token(t) => t.parent()?,
};
let ranks = compute_fields_ranks(&path, ctx)?; let ranks = compute_fields_ranks(&path, ctx)?;
let get_rank_of_field = |of: Option<SmolStr>| { let get_rank_of_field = |of: Option<SmolStr>| {
*ranks.get(of.unwrap_or_default().trim_start_matches("r#")).unwrap_or(&usize::MAX) *ranks.get(of.unwrap_or_default().trim_start_matches("r#")).unwrap_or(&usize::MAX)
@ -65,23 +70,31 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
AssistId("reorder_fields", AssistKind::RefactorRewrite), AssistId("reorder_fields", AssistKind::RefactorRewrite),
"Reorder record fields", "Reorder record fields",
target, target,
|builder| match fields { |builder| {
Either::Left((sorted, field_list)) => { let mut editor = builder.make_editor(&parent_node);
replace(builder.make_mut(field_list).fields(), sorted)
} match fields {
Either::Right((sorted, field_list)) => { Either::Left((sorted, field_list)) => {
replace(builder.make_mut(field_list).fields(), sorted) replace(&mut editor, field_list.fields(), sorted)
}
Either::Right((sorted, field_list)) => {
replace(&mut editor, field_list.fields(), sorted)
}
} }
builder.add_file_edits(ctx.file_id(), editor);
}, },
) )
} }
fn replace<T: AstNode + PartialEq>( fn replace<T: AstNode + PartialEq>(
editor: &mut SyntaxEditor,
fields: impl Iterator<Item = T>, fields: impl Iterator<Item = T>,
sorted_fields: impl IntoIterator<Item = T>, sorted_fields: impl IntoIterator<Item = T>,
) { ) {
fields.zip(sorted_fields).for_each(|(field, sorted_field)| { fields.zip(sorted_fields).for_each(|(field, sorted_field)| {
ted::replace(field.syntax(), sorted_field.syntax().clone_for_update()) // FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
editor.replace(field.syntax(), sorted_field.syntax().clone_for_update())
}); });
} }

View File

@ -511,12 +511,16 @@ pub(crate) fn handle_document_diagnostics(
.into_iter() .into_iter()
.filter_map(|d| { .filter_map(|d| {
let file = d.range.file_id; let file = d.range.file_id;
let diagnostic = convert_diagnostic(&line_index, d);
if file == file_id { if file == file_id {
let diagnostic = convert_diagnostic(&line_index, d);
return Some(diagnostic); return Some(diagnostic);
} }
if supports_related { if supports_related {
related_documents.entry(file).or_insert_with(Vec::new).push(diagnostic); let (diagnostics, line_index) = related_documents
.entry(file)
.or_insert_with(|| (Vec::new(), snap.file_line_index(file).ok()));
let diagnostic = convert_diagnostic(line_index.as_mut()?, d);
diagnostics.push(diagnostic);
} }
None None
}); });
@ -529,7 +533,7 @@ pub(crate) fn handle_document_diagnostics(
related_documents: related_documents.is_empty().not().then(|| { related_documents: related_documents.is_empty().not().then(|| {
related_documents related_documents
.into_iter() .into_iter()
.map(|(id, items)| { .map(|(id, (items, _))| {
( (
to_proto::url(&snap, id), to_proto::url(&snap, id),
lsp_types::DocumentDiagnosticReportKind::Full( lsp_types::DocumentDiagnosticReportKind::Full(