Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2625,18 +2625,18 @@ checksum = "672423d4fea7ffa2f6c25ba60031ea13dc6258070556f125cc4d790007d4a155"

[[package]]
name = "xshell"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437"
checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d"
dependencies = [
"xshell-macros",
]

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

[[package]]
name = "xtask"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use either::Either;
use ide_db::FxHashMap;
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};

Expand All @@ -24,6 +24,11 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
let record =
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 get_rank_of_field = |of: Option<SmolStr>| {
*ranks.get(of.unwrap_or_default().trim_start_matches("r#")).unwrap_or(&usize::MAX)
Expand Down Expand Up @@ -65,23 +70,31 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
AssistId("reorder_fields", AssistKind::RefactorRewrite),
"Reorder record fields",
target,
|builder| match fields {
Either::Left((sorted, field_list)) => {
replace(builder.make_mut(field_list).fields(), sorted)
}
Either::Right((sorted, field_list)) => {
replace(builder.make_mut(field_list).fields(), sorted)
|builder| {
let mut editor = builder.make_editor(&parent_node);

match fields {
Either::Left((sorted, field_list)) => {
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>(
editor: &mut SyntaxEditor,
fields: impl Iterator<Item = T>,
sorted_fields: impl IntoIterator<Item = T>,
) {
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())
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,16 @@ pub(crate) fn handle_document_diagnostics(
.into_iter()
.filter_map(|d| {
let file = d.range.file_id;
let diagnostic = convert_diagnostic(&line_index, d);
if file == file_id {
let diagnostic = convert_diagnostic(&line_index, d);
return Some(diagnostic);
}
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
});
Expand All @@ -529,7 +533,7 @@ pub(crate) fn handle_document_diagnostics(
related_documents: related_documents.is_empty().not().then(|| {
related_documents
.into_iter()
.map(|(id, items)| {
.map(|(id, (items, _))| {
(
to_proto::url(&snap, id),
lsp_types::DocumentDiagnosticReportKind::Full(
Expand Down
Loading