Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/source_change.rs')
-rw-r--r--crates/ide-db/src/source_change.rs45
1 files changed, 34 insertions, 11 deletions
diff --git a/crates/ide-db/src/source_change.rs b/crates/ide-db/src/source_change.rs
index 34642d7eaf..b4d0b0dc9f 100644
--- a/crates/ide-db/src/source_change.rs
+++ b/crates/ide-db/src/source_change.rs
@@ -3,7 +3,7 @@
//!
//! It can be viewed as a dual for `Change`.
-use std::{collections::hash_map::Entry, iter, mem};
+use std::{collections::hash_map::Entry, fmt, iter, mem};
use crate::text_edit::{TextEdit, TextEditBuilder};
use crate::{assists::Command, syntax_helpers::tree_diff::diff, SnippetCap};
@@ -18,23 +18,33 @@ use syntax::{
AstNode, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize,
};
+/// An annotation ID associated with an indel, to describe changes.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct ChangeAnnotationId(u32);
+
+impl fmt::Display for ChangeAnnotationId {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::Display::fmt(&self.0, f)
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct ChangeAnnotation {
+ pub label: String,
+ pub needs_confirmation: bool,
+ pub description: Option<String>,
+}
+
#[derive(Default, Debug, Clone)]
pub struct SourceChange {
pub source_file_edits: IntMap<FileId, (TextEdit, Option<SnippetEdit>)>,
pub file_system_edits: Vec<FileSystemEdit>,
pub is_snippet: bool,
+ pub annotations: FxHashMap<ChangeAnnotationId, ChangeAnnotation>,
+ next_annotation_id: u32,
}
impl SourceChange {
- /// Creates a new SourceChange with the given label
- /// from the edits.
- pub fn from_edits(
- source_file_edits: IntMap<FileId, (TextEdit, Option<SnippetEdit>)>,
- file_system_edits: Vec<FileSystemEdit>,
- ) -> Self {
- SourceChange { source_file_edits, file_system_edits, is_snippet: false }
- }
-
pub fn from_text_edit(file_id: impl Into<FileId>, edit: TextEdit) -> Self {
SourceChange {
source_file_edits: iter::once((file_id.into(), (edit, None))).collect(),
@@ -42,6 +52,13 @@ impl SourceChange {
}
}
+ pub fn insert_annotation(&mut self, annotation: ChangeAnnotation) -> ChangeAnnotationId {
+ let id = ChangeAnnotationId(self.next_annotation_id);
+ self.next_annotation_id += 1;
+ self.annotations.insert(id, annotation);
+ id
+ }
+
/// Inserts a [`TextEdit`] for the given [`FileId`]. This properly handles merging existing
/// edits for a file if some already exist.
pub fn insert_source_edit(&mut self, file_id: impl Into<FileId>, edit: TextEdit) {
@@ -120,7 +137,12 @@ impl From<IntMap<FileId, TextEdit>> for SourceChange {
fn from(source_file_edits: IntMap<FileId, TextEdit>) -> SourceChange {
let source_file_edits =
source_file_edits.into_iter().map(|(file_id, edit)| (file_id, (edit, None))).collect();
- SourceChange { source_file_edits, file_system_edits: Vec::new(), is_snippet: false }
+ SourceChange {
+ source_file_edits,
+ file_system_edits: Vec::new(),
+ is_snippet: false,
+ ..SourceChange::default()
+ }
}
}
@@ -482,6 +504,7 @@ impl From<FileSystemEdit> for SourceChange {
source_file_edits: Default::default(),
file_system_edits: vec![edit],
is_snippet: false,
+ ..SourceChange::default()
}
}
}