Skip to content

Commit 0527e3b

Browse files
committed
rename Edit to TextEdit and AtomEdit to AtomTextEdit
1 parent 7344d28 commit 0527e3b

File tree

11 files changed

+92
-87
lines changed

11 files changed

+92
-87
lines changed

crates/ra_analysis/src/completion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod reference_completion;
22

33
use ra_editor::find_node_at_offset;
4-
use ra_text_edit::AtomEdit;
4+
use ra_text_edit::AtomTextEdit;
55
use ra_syntax::{
66
algo::visit::{visitor_ctx, VisitorCtx},
77
ast,
@@ -34,7 +34,7 @@ pub(crate) fn completions(
3434
let original_file = db.source_file(position.file_id);
3535
// Insert a fake ident to get a valid parse tree
3636
let file = {
37-
let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string());
37+
let edit = AtomTextEdit::insert(position.offset, "intellijRulezz".to_string());
3838
original_file.reparse(&edit)
3939
};
4040

crates/ra_analysis/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub mod mock_analysis;
1919
use std::{fmt, sync::Arc};
2020

2121
use ra_syntax::{SourceFileNode, TextRange, TextUnit};
22-
use ra_text_edit::AtomEdit;
22+
use ra_text_edit::AtomTextEdit;
2323
use ra_db::FileResolverImp;
2424
use rayon::prelude::*;
2525
use relative_path::RelativePathBuf;
@@ -121,7 +121,7 @@ pub struct SourceChange {
121121
#[derive(Debug)]
122122
pub struct SourceFileNodeEdit {
123123
pub file_id: FileId,
124-
pub edits: Vec<AtomEdit>,
124+
pub edits: Vec<AtomTextEdit>,
125125
}
126126

127127
#[derive(Debug)]

crates/ra_editor/src/code_actions.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use ra_syntax::{
88
SyntaxNodeRef, TextRange, TextUnit,
99
};
1010

11-
use crate::{find_node_at_offset, Edit, EditBuilder};
11+
use crate::{find_node_at_offset, TextEdit, TextEditBuilder};
1212

1313
#[derive(Debug)]
1414
pub struct LocalEdit {
15-
pub edit: Edit,
15+
pub edit: TextEdit,
1616
pub cursor_position: Option<TextUnit>,
1717
}
1818

@@ -26,7 +26,7 @@ pub fn flip_comma<'a>(
2626
let prev = non_trivia_sibling(comma, Direction::Prev)?;
2727
let next = non_trivia_sibling(comma, Direction::Next)?;
2828
Some(move || {
29-
let mut edit = EditBuilder::new();
29+
let mut edit = TextEditBuilder::new();
3030
edit.replace(prev.range(), next.text().to_string());
3131
edit.replace(next.range(), prev.text().to_string());
3232
LocalEdit {
@@ -49,7 +49,7 @@ pub fn add_derive<'a>(
4949
.filter(|(name, _arg)| name == "derive")
5050
.map(|(_name, arg)| arg)
5151
.next();
52-
let mut edit = EditBuilder::new();
52+
let mut edit = TextEditBuilder::new();
5353
let offset = match derive_attr {
5454
None => {
5555
edit.insert(node_start, "#[derive()]\n".to_string());
@@ -82,7 +82,7 @@ pub fn add_impl<'a>(
8282

8383
Some(move || {
8484
let type_params = nominal.type_param_list();
85-
let mut edit = EditBuilder::new();
85+
let mut edit = TextEditBuilder::new();
8686
let start_offset = nominal.syntax().range().end();
8787
let mut buf = String::new();
8888
buf.push_str("\n\nimpl");
@@ -129,7 +129,7 @@ pub fn introduce_variable<'a>(
129129
}
130130
return Some(move || {
131131
let mut buf = String::new();
132-
let mut edit = EditBuilder::new();
132+
let mut edit = TextEditBuilder::new();
133133

134134
buf.push_str("let var_name = ");
135135
expr.syntax().text().push_to(&mut buf);

crates/ra_editor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::{
1515
symbols::{file_structure, file_symbols, FileSymbol, StructureNode},
1616
typing::{join_lines, on_enter, on_eq_typed},
1717
};
18-
use ra_text_edit::{Edit, EditBuilder};
18+
use ra_text_edit::{TextEdit, TextEditBuilder};
1919
use ra_syntax::{
2020
algo::find_leaf_at_offset,
2121
ast::{self, AstNode, NameOwner},

crates/ra_editor/src/typing.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ra_syntax::{
1010
};
1111
use ra_text_edit::text_utils::contains_offset_nonstrict;
1212

13-
use crate::{find_node_at_offset, EditBuilder, LocalEdit};
13+
use crate::{find_node_at_offset, TextEditBuilder, LocalEdit};
1414

1515
pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
1616
let range = if range.is_empty() {
@@ -19,7 +19,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
1919
let pos = match text.find('\n') {
2020
None => {
2121
return LocalEdit {
22-
edit: EditBuilder::new().finish(),
22+
edit: TextEditBuilder::new().finish(),
2323
cursor_position: None,
2424
};
2525
}
@@ -31,7 +31,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
3131
};
3232

3333
let node = find_covering_node(file.syntax(), range);
34-
let mut edit = EditBuilder::new();
34+
let mut edit = TextEditBuilder::new();
3535
for node in node.descendants() {
3636
let text = match node.leaf_text() {
3737
Some(text) => text,
@@ -73,7 +73,7 @@ pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> {
7373
let indent = node_indent(file, comment.syntax())?;
7474
let inserted = format!("\n{}{} ", indent, prefix);
7575
let cursor_position = offset + TextUnit::of_str(&inserted);
76-
let mut edit = EditBuilder::new();
76+
let mut edit = TextEditBuilder::new();
7777
edit.insert(offset, inserted);
7878
Some(LocalEdit {
7979
edit: edit.finish(),
@@ -123,15 +123,20 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit>
123123
return None;
124124
}
125125
let offset = let_stmt.syntax().range().end();
126-
let mut edit = EditBuilder::new();
126+
let mut edit = TextEditBuilder::new();
127127
edit.insert(offset, ";".to_string());
128128
Some(LocalEdit {
129129
edit: edit.finish(),
130130
cursor_position: None,
131131
})
132132
}
133133

134-
fn remove_newline(edit: &mut EditBuilder, node: SyntaxNodeRef, node_text: &str, offset: TextUnit) {
134+
fn remove_newline(
135+
edit: &mut TextEditBuilder,
136+
node: SyntaxNodeRef,
137+
node_text: &str,
138+
offset: TextUnit,
139+
) {
135140
if node.kind() != WHITESPACE || node_text.bytes().filter(|&b| b == b'\n').count() != 1 {
136141
// The node is either the first or the last in the file
137142
let suff = &node_text[TextRange::from_to(
@@ -192,7 +197,7 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
192197
}
193198
}
194199

195-
fn join_single_expr_block(edit: &mut EditBuilder, node: SyntaxNodeRef) -> Option<()> {
200+
fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> {
196201
let block = ast::Block::cast(node.parent()?)?;
197202
let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?;
198203
let expr = single_expr(block)?;
@@ -270,14 +275,14 @@ fn foo() {
270275
fn test_join_lines_lambda_block() {
271276
check_join_lines(
272277
r"
273-
pub fn reparse(&self, edit: &AtomEdit) -> File {
278+
pub fn reparse(&self, edit: &AtomTextEdit) -> File {
274279
<|>self.incremental_reparse(edit).unwrap_or_else(|| {
275280
self.full_reparse(edit)
276281
})
277282
}
278283
",
279284
r"
280-
pub fn reparse(&self, edit: &AtomEdit) -> File {
285+
pub fn reparse(&self, edit: &AtomTextEdit) -> File {
281286
<|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
282287
}
283288
",

crates/ra_lsp_server/src/conv.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use languageserver_types::{
2-
Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
3-
TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier,
2+
self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
3+
TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier,
44
};
55
use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition};
66
use ra_editor::{LineCol, LineIndex};
7-
use ra_text_edit::{AtomEdit, Edit};
7+
use ra_text_edit::{AtomTextEdit, TextEdit};
88
use ra_syntax::{SyntaxKind, TextRange, TextUnit};
99

1010
use crate::{req, server_world::ServerWorld, Result};
@@ -92,24 +92,24 @@ impl ConvWith for Range {
9292
}
9393
}
9494

95-
impl ConvWith for Edit {
95+
impl ConvWith for TextEdit {
9696
type Ctx = LineIndex;
97-
type Output = Vec<TextEdit>;
97+
type Output = Vec<languageserver_types::TextEdit>;
9898

99-
fn conv_with(self, line_index: &LineIndex) -> Vec<TextEdit> {
99+
fn conv_with(self, line_index: &LineIndex) -> Vec<languageserver_types::TextEdit> {
100100
self.into_atoms()
101101
.into_iter()
102102
.map_conv_with(line_index)
103103
.collect()
104104
}
105105
}
106106

107-
impl ConvWith for AtomEdit {
107+
impl ConvWith for AtomTextEdit {
108108
type Ctx = LineIndex;
109-
type Output = TextEdit;
109+
type Output = languageserver_types::TextEdit;
110110

111-
fn conv_with(self, line_index: &LineIndex) -> TextEdit {
112-
TextEdit {
111+
fn conv_with(self, line_index: &LineIndex) -> languageserver_types::TextEdit {
112+
languageserver_types::TextEdit {
113113
range: self.delete.conv_with(line_index),
114114
new_text: self.insert,
115115
}
@@ -229,7 +229,7 @@ impl TryConvWith for SourceChange {
229229
fn translate_offset_with_edit(
230230
pre_edit_index: &LineIndex,
231231
offset: TextUnit,
232-
edits: &[AtomEdit],
232+
edits: &[AtomTextEdit],
233233
) -> LineCol {
234234
let fallback = pre_edit_index.line_col(offset);
235235
let edit = match edits.first() {

crates/ra_syntax/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use crate::{
4747
},
4848
};
4949

50-
use ra_text_edit::AtomEdit;
50+
use ra_text_edit::AtomTextEdit;
5151
use crate::yellow::GreenNode;
5252

5353
/// `SourceFileNode` represents a parse tree for a single Rust file.
@@ -68,15 +68,15 @@ impl SourceFileNode {
6868
parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root);
6969
SourceFileNode::new(green, errors)
7070
}
71-
pub fn reparse(&self, edit: &AtomEdit) -> SourceFileNode {
71+
pub fn reparse(&self, edit: &AtomTextEdit) -> SourceFileNode {
7272
self.incremental_reparse(edit)
7373
.unwrap_or_else(|| self.full_reparse(edit))
7474
}
75-
pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<SourceFileNode> {
75+
pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<SourceFileNode> {
7676
reparsing::incremental_reparse(self.syntax(), edit, self.errors())
7777
.map(|(green_node, errors)| SourceFileNode::new(green_node, errors))
7878
}
79-
fn full_reparse(&self, edit: &AtomEdit) -> SourceFileNode {
79+
fn full_reparse(&self, edit: &AtomTextEdit) -> SourceFileNode {
8080
let text =
8181
text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert);
8282
SourceFileNode::parse(&text)

crates/ra_syntax/src/reparsing.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use crate::parser_impl;
66
use crate::text_utils::replace_range;
77
use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef};
88
use crate::{SyntaxKind::*, TextRange, TextUnit};
9-
use ra_text_edit::AtomEdit;
9+
use ra_text_edit::AtomTextEdit;
1010

1111
pub(crate) fn incremental_reparse(
1212
node: SyntaxNodeRef,
13-
edit: &AtomEdit,
13+
edit: &AtomTextEdit,
1414
errors: Vec<SyntaxError>,
1515
) -> Option<(GreenNode, Vec<SyntaxError>)> {
1616
let (node, green, new_errors) =
@@ -22,7 +22,7 @@ pub(crate) fn incremental_reparse(
2222

2323
fn reparse_leaf<'node>(
2424
node: SyntaxNodeRef<'node>,
25-
edit: &AtomEdit,
25+
edit: &AtomTextEdit,
2626
) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> {
2727
let node = algo::find_covering_node(node, edit.delete);
2828
match node.kind() {
@@ -48,7 +48,7 @@ fn reparse_leaf<'node>(
4848

4949
fn reparse_block<'node>(
5050
node: SyntaxNodeRef<'node>,
51-
edit: &AtomEdit,
51+
edit: &AtomTextEdit,
5252
) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> {
5353
let (node, reparser) = find_reparsable_node(node, edit.delete)?;
5454
let text = get_text_after_edit(node, &edit);
@@ -61,7 +61,7 @@ fn reparse_block<'node>(
6161
Some((node, green, new_errors))
6262
}
6363

64-
fn get_text_after_edit(node: SyntaxNodeRef, edit: &AtomEdit) -> String {
64+
fn get_text_after_edit(node: SyntaxNodeRef, edit: &AtomTextEdit) -> String {
6565
replace_range(
6666
node.text().to_string(),
6767
edit.delete - node.range().start(),
@@ -139,7 +139,7 @@ fn merge_errors(
139139
old_errors: Vec<SyntaxError>,
140140
new_errors: Vec<SyntaxError>,
141141
old_node: SyntaxNodeRef,
142-
edit: &AtomEdit,
142+
edit: &AtomTextEdit,
143143
) -> Vec<SyntaxError> {
144144
let mut res = Vec::new();
145145
for e in old_errors {
@@ -166,7 +166,7 @@ mod tests {
166166
where
167167
for<'a> F: Fn(
168168
SyntaxNodeRef<'a>,
169-
&AtomEdit,
169+
&AtomTextEdit,
170170
) -> Option<(SyntaxNodeRef<'a>, GreenNode, Vec<SyntaxError>)>,
171171
{
172172
let (range, before) = extract_range(before);
@@ -175,7 +175,7 @@ mod tests {
175175
let fully_reparsed = SourceFileNode::parse(&after);
176176
let incrementally_reparsed = {
177177
let f = SourceFileNode::parse(&before);
178-
let edit = AtomEdit {
178+
let edit = AtomTextEdit {
179179
delete: range,
180180
insert: replace_with.to_string(),
181181
};

0 commit comments

Comments
 (0)