Skip to content

Commit 759941a

Browse files
authored
Rollup merge of #133158 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? ``@ghost``
2 parents d6afa09 + 647749a commit 759941a

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

src/tools/rust-analyzer/Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -2625,18 +2625,18 @@ checksum = "672423d4fea7ffa2f6c25ba60031ea13dc6258070556f125cc4d790007d4a155"
26252625

26262626
[[package]]
26272627
name = "xshell"
2628-
version = "0.2.6"
2628+
version = "0.2.7"
26292629
source = "registry+https://github.com/rust-lang/crates.io-index"
2630-
checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437"
2630+
checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d"
26312631
dependencies = [
26322632
"xshell-macros",
26332633
]
26342634

26352635
[[package]]
26362636
name = "xshell-macros"
2637-
version = "0.2.6"
2637+
version = "0.2.7"
26382638
source = "registry+https://github.com/rust-lang/crates.io-index"
2639-
checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852"
2639+
checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547"
26402640

26412641
[[package]]
26422642
name = "xtask"

src/tools/rust-analyzer/crates/ide-assists/src/handlers/reorder_fields.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use either::Either;
22
use ide_db::FxHashMap;
33
use itertools::Itertools;
4-
use syntax::{ast, ted, AstNode, SmolStr, ToSmolStr};
4+
use syntax::{ast, syntax_editor::SyntaxEditor, AstNode, SmolStr, SyntaxElement, ToSmolStr};
55

66
use crate::{AssistContext, AssistId, AssistKind, Assists};
77

@@ -24,6 +24,11 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
2424
let record =
2525
path.syntax().parent().and_then(<Either<ast::RecordExpr, ast::RecordPat>>::cast)?;
2626

27+
let parent_node = match ctx.covering_element() {
28+
SyntaxElement::Node(n) => n,
29+
SyntaxElement::Token(t) => t.parent()?,
30+
};
31+
2732
let ranks = compute_fields_ranks(&path, ctx)?;
2833
let get_rank_of_field = |of: Option<SmolStr>| {
2934
*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
6570
AssistId("reorder_fields", AssistKind::RefactorRewrite),
6671
"Reorder record fields",
6772
target,
68-
|builder| match fields {
69-
Either::Left((sorted, field_list)) => {
70-
replace(builder.make_mut(field_list).fields(), sorted)
71-
}
72-
Either::Right((sorted, field_list)) => {
73-
replace(builder.make_mut(field_list).fields(), sorted)
73+
|builder| {
74+
let mut editor = builder.make_editor(&parent_node);
75+
76+
match fields {
77+
Either::Left((sorted, field_list)) => {
78+
replace(&mut editor, field_list.fields(), sorted)
79+
}
80+
Either::Right((sorted, field_list)) => {
81+
replace(&mut editor, field_list.fields(), sorted)
82+
}
7483
}
84+
85+
builder.add_file_edits(ctx.file_id(), editor);
7586
},
7687
)
7788
}
7889

7990
fn replace<T: AstNode + PartialEq>(
91+
editor: &mut SyntaxEditor,
8092
fields: impl Iterator<Item = T>,
8193
sorted_fields: impl IntoIterator<Item = T>,
8294
) {
8395
fields.zip(sorted_fields).for_each(|(field, sorted_field)| {
84-
ted::replace(field.syntax(), sorted_field.syntax().clone_for_update())
96+
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
97+
editor.replace(field.syntax(), sorted_field.syntax().clone_for_update())
8598
});
8699
}
87100

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,16 @@ pub(crate) fn handle_document_diagnostics(
511511
.into_iter()
512512
.filter_map(|d| {
513513
let file = d.range.file_id;
514-
let diagnostic = convert_diagnostic(&line_index, d);
515514
if file == file_id {
515+
let diagnostic = convert_diagnostic(&line_index, d);
516516
return Some(diagnostic);
517517
}
518518
if supports_related {
519-
related_documents.entry(file).or_insert_with(Vec::new).push(diagnostic);
519+
let (diagnostics, line_index) = related_documents
520+
.entry(file)
521+
.or_insert_with(|| (Vec::new(), snap.file_line_index(file).ok()));
522+
let diagnostic = convert_diagnostic(line_index.as_mut()?, d);
523+
diagnostics.push(diagnostic);
520524
}
521525
None
522526
});
@@ -529,7 +533,7 @@ pub(crate) fn handle_document_diagnostics(
529533
related_documents: related_documents.is_empty().not().then(|| {
530534
related_documents
531535
.into_iter()
532-
.map(|(id, items)| {
536+
.map(|(id, (items, _))| {
533537
(
534538
to_proto::url(&snap, id),
535539
lsp_types::DocumentDiagnosticReportKind::Full(

0 commit comments

Comments
 (0)