mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Move atom edit to libsyntax2
This commit is contained in:
parent
87cd57d56a
commit
32c8ea9307
3 changed files with 35 additions and 27 deletions
|
@ -64,7 +64,7 @@ impl File {
|
|||
validate_block_structure(root.borrowed());
|
||||
File { root }
|
||||
}
|
||||
pub fn parse(text: &str) -> Self {
|
||||
pub fn parse(text: &str) -> File {
|
||||
let tokens = tokenize(&text);
|
||||
let (root, errors) = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens);
|
||||
File::new(root, errors)
|
||||
|
@ -112,3 +112,23 @@ fn validate_block_structure(root: SyntaxNodeRef) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue