mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Rollup merge of #133158 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
This commit is contained in:
commit
194c76ef0a
@ -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"
|
||||
|
@ -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};
|
||||
|
||||
@ -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)
|
||||
@ -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())
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
});
|
||||
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user