Group file source edits by FileId
This commit is contained in:
@@ -12,10 +12,10 @@ pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> {
|
||||
match_finder.add_rule(rule)?;
|
||||
}
|
||||
let edits = match_finder.edits();
|
||||
for edit in edits {
|
||||
if let Some(path) = vfs.file_path(edit.file_id).as_path() {
|
||||
let mut contents = db.file_text(edit.file_id).to_string();
|
||||
edit.edit.apply(&mut contents);
|
||||
for (file_id, edit) in edits.edits {
|
||||
if let Some(path) = vfs.file_path(file_id).as_path() {
|
||||
let mut contents = db.file_text(file_id).to_string();
|
||||
edit.apply(&mut contents);
|
||||
std::fs::write(path, contents)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,15 +260,15 @@ pub(crate) fn handle_on_type_formatting(
|
||||
}
|
||||
|
||||
let edit = snap.analysis.on_char_typed(position, char_typed)?;
|
||||
let mut edit = match edit {
|
||||
let edit = match edit {
|
||||
Some(it) => it,
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
// This should be a single-file edit
|
||||
let edit = edit.source_file_edits.pop().unwrap();
|
||||
let (_, edit) = edit.source_file_edits.edits.into_iter().next().unwrap();
|
||||
|
||||
let change = to_proto::text_edit_vec(&line_index, line_endings, edit.edit);
|
||||
let change = to_proto::text_edit_vec(&line_index, line_endings, edit);
|
||||
Ok(Some(change))
|
||||
}
|
||||
|
||||
@@ -463,8 +463,12 @@ pub(crate) fn handle_will_rename_files(
|
||||
.collect();
|
||||
|
||||
// Drop file system edits since we're just renaming things on the same level
|
||||
let edits = source_changes.into_iter().map(|it| it.source_file_edits).flatten().collect();
|
||||
let source_change = SourceChange::from_edits(edits, Vec::new());
|
||||
let mut source_changes = source_changes.into_iter();
|
||||
let mut source_file_edits =
|
||||
source_changes.next().map_or_else(Default::default, |it| it.source_file_edits);
|
||||
// no collect here because we want to merge text edits on same file ids
|
||||
source_file_edits.extend(source_changes.map(|it| it.source_file_edits.edits).flatten());
|
||||
let source_change = SourceChange::from_edits(source_file_edits, Vec::new());
|
||||
|
||||
let workspace_edit = to_proto::workspace_edit(&snap, source_change)?;
|
||||
Ok(Some(workspace_edit))
|
||||
|
||||
@@ -8,8 +8,7 @@ use ide::{
|
||||
Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId,
|
||||
FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel,
|
||||
InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess,
|
||||
RenameError, Runnable, Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange,
|
||||
TextSize,
|
||||
RenameError, Runnable, Severity, SourceChange, SymbolKind, TextEdit, TextRange, TextSize,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
||||
@@ -634,13 +633,13 @@ pub(crate) fn goto_definition_response(
|
||||
pub(crate) fn snippet_text_document_edit(
|
||||
snap: &GlobalStateSnapshot,
|
||||
is_snippet: bool,
|
||||
source_file_edit: SourceFileEdit,
|
||||
file_id: FileId,
|
||||
edit: TextEdit,
|
||||
) -> Result<lsp_ext::SnippetTextDocumentEdit> {
|
||||
let text_document = optional_versioned_text_document_identifier(snap, source_file_edit.file_id);
|
||||
let line_index = snap.analysis.file_line_index(source_file_edit.file_id)?;
|
||||
let line_endings = snap.file_line_endings(source_file_edit.file_id);
|
||||
let edits = source_file_edit
|
||||
.edit
|
||||
let text_document = optional_versioned_text_document_identifier(snap, file_id);
|
||||
let line_index = snap.analysis.file_line_index(file_id)?;
|
||||
let line_endings = snap.file_line_endings(file_id);
|
||||
let edits = edit
|
||||
.into_iter()
|
||||
.map(|it| snippet_text_edit(&line_index, line_endings, is_snippet, it))
|
||||
.collect();
|
||||
@@ -699,8 +698,8 @@ pub(crate) fn snippet_workspace_edit(
|
||||
let ops = snippet_text_document_ops(snap, op);
|
||||
document_changes.extend_from_slice(&ops);
|
||||
}
|
||||
for edit in source_change.source_file_edits {
|
||||
let edit = snippet_text_document_edit(&snap, source_change.is_snippet, edit)?;
|
||||
for (file_id, edit) in source_change.source_file_edits.edits {
|
||||
let edit = snippet_text_document_edit(&snap, source_change.is_snippet, file_id, edit)?;
|
||||
document_changes.push(lsp_ext::SnippetDocumentChangeOperation::Edit(edit));
|
||||
}
|
||||
let workspace_edit =
|
||||
|
||||
Reference in New Issue
Block a user