mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
kill text utils
This commit is contained in:
parent
f553837c1c
commit
921689b70d
4 changed files with 13 additions and 19 deletions
|
@ -31,7 +31,6 @@ mod parser_impl;
|
|||
mod reparsing;
|
||||
mod string_lexing;
|
||||
mod syntax_kinds;
|
||||
pub mod text_utils;
|
||||
/// Utilities for simple uses of the parser.
|
||||
pub mod utils;
|
||||
mod validation;
|
||||
|
@ -75,8 +74,7 @@ impl SourceFile {
|
|||
.map(|(green_node, errors)| SourceFile::new(green_node, errors))
|
||||
}
|
||||
fn full_reparse(&self, edit: &AtomTextEdit) -> TreePtr<SourceFile> {
|
||||
let text =
|
||||
text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert);
|
||||
let text = edit.apply(self.syntax().text().to_string());
|
||||
SourceFile::parse(&text)
|
||||
}
|
||||
pub fn errors(&self) -> Vec<SyntaxError> {
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::grammar;
|
|||
use crate::lexer::{tokenize, Token};
|
||||
use crate::parser_api::Parser;
|
||||
use crate::parser_impl;
|
||||
use crate::text_utils::replace_range;
|
||||
use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNode};
|
||||
use crate::{SyntaxKind::*, TextRange, TextUnit};
|
||||
use ra_text_edit::AtomTextEdit;
|
||||
|
@ -62,11 +61,8 @@ fn reparse_block<'node>(
|
|||
}
|
||||
|
||||
fn get_text_after_edit(node: &SyntaxNode, edit: &AtomTextEdit) -> String {
|
||||
replace_range(
|
||||
node.text().to_string(),
|
||||
edit.delete - node.range().start(),
|
||||
&edit.insert,
|
||||
)
|
||||
let edit = AtomTextEdit::replace(edit.delete - node.range().start(), edit.insert.clone());
|
||||
edit.apply(node.text().to_string())
|
||||
}
|
||||
|
||||
fn is_contextual_kw(text: &str) -> bool {
|
||||
|
@ -156,7 +152,7 @@ fn merge_errors(
|
|||
mod tests {
|
||||
use test_utils::{extract_range, assert_eq_text};
|
||||
|
||||
use crate::{SourceFile, AstNode, text_utils::replace_range, utils::dump_tree};
|
||||
use crate::{SourceFile, AstNode, utils::dump_tree};
|
||||
use super::*;
|
||||
|
||||
fn do_check<F>(before: &str, replace_with: &str, reparser: F)
|
||||
|
@ -167,7 +163,8 @@ mod tests {
|
|||
) -> Option<(&'a SyntaxNode, GreenNode, Vec<SyntaxError>)>,
|
||||
{
|
||||
let (range, before) = extract_range(before);
|
||||
let after = replace_range(before.clone(), range, replace_with);
|
||||
let edit = AtomTextEdit::replace(range, replace_with.to_owned());
|
||||
let after = edit.apply(before.clone());
|
||||
|
||||
let fully_reparsed = SourceFile::parse(&after);
|
||||
let incrementally_reparsed = {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
use crate::TextRange;
|
||||
|
||||
pub fn replace_range(mut text: String, range: TextRange, replace_with: &str) -> String {
|
||||
let start = u32::from(range.start()) as usize;
|
||||
let end = u32::from(range.end()) as usize;
|
||||
text.replace_range(start..end, replace_with);
|
||||
text
|
||||
}
|
|
@ -28,4 +28,11 @@ impl AtomTextEdit {
|
|||
pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit {
|
||||
AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text)
|
||||
}
|
||||
|
||||
pub fn apply(&self, mut text: String) -> String {
|
||||
let start = u32::from(self.delete.start()) as usize;
|
||||
let end = u32::from(self.delete.end()) as usize;
|
||||
text.replace_range(start..end, &self.insert);
|
||||
text
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue