extract AtomEdit and Edit into new ra_text_edit crate
This commit is contained in:
@@ -41,13 +41,13 @@ pub use rowan::{SmolStr, TextRange, TextUnit};
|
||||
pub use crate::{
|
||||
ast::AstNode,
|
||||
lexer::{tokenize, Token},
|
||||
reparsing::AtomEdit,
|
||||
syntax_kinds::SyntaxKind,
|
||||
yellow::{
|
||||
Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location,
|
||||
},
|
||||
};
|
||||
|
||||
use ra_text_edit::AtomEdit;
|
||||
use crate::yellow::GreenNode;
|
||||
|
||||
/// `SourceFileNode` represents a parse tree for a single Rust file.
|
||||
|
||||
@@ -6,29 +6,7 @@ use crate::parser_impl;
|
||||
use crate::text_utils::replace_range;
|
||||
use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef};
|
||||
use crate::{SyntaxKind::*, TextRange, TextUnit};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AtomEdit {
|
||||
pub delete: TextRange,
|
||||
pub insert: String,
|
||||
}
|
||||
|
||||
impl AtomEdit {
|
||||
pub fn replace(range: TextRange, replace_with: String) -> AtomEdit {
|
||||
AtomEdit {
|
||||
delete: range,
|
||||
insert: replace_with,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete(range: TextRange) -> AtomEdit {
|
||||
AtomEdit::replace(range, String::new())
|
||||
}
|
||||
|
||||
pub fn insert(offset: TextUnit, text: String) -> AtomEdit {
|
||||
AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text)
|
||||
}
|
||||
}
|
||||
use ra_text_edit::AtomEdit;
|
||||
|
||||
pub(crate) fn incremental_reparse(
|
||||
node: SyntaxNodeRef,
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
use crate::{TextRange, TextUnit};
|
||||
|
||||
pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool {
|
||||
range.start() <= offset && offset <= range.end()
|
||||
}
|
||||
use crate::TextRange;
|
||||
|
||||
pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> {
|
||||
let start = r1.start().max(r2.start());
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use std::{fmt, ops};
|
||||
|
||||
use ra_text_edit::text_utils::contains_offset_nonstrict;
|
||||
use crate::{
|
||||
text_utils::{contains_offset_nonstrict, intersect},
|
||||
text_utils::intersect,
|
||||
SyntaxNodeRef, TextRange, TextUnit,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user