Skip to content

Commit 29fc409

Browse files
bors[bot]matklad
andauthored
Merge #4131
4131: Switch to text-size r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 27a7718 + e873469 commit 29fc409

File tree

439 files changed

+26954
-26996
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

439 files changed

+26954
-26996
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_assists/src/assist_ctx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ra_fmt::{leading_indent, reindent};
55
use ra_ide_db::RootDatabase;
66
use ra_syntax::{
77
algo::{self, find_covering_element, find_node_at_offset},
8-
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit,
8+
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
99
TokenAtOffset,
1010
};
1111
use ra_text_edit::TextEditBuilder;
@@ -178,7 +178,7 @@ impl<'a> AssistGroup<'a> {
178178
#[derive(Default)]
179179
pub(crate) struct ActionBuilder {
180180
edit: TextEditBuilder,
181-
cursor_position: Option<TextUnit>,
181+
cursor_position: Option<TextSize>,
182182
target: Option<TextRange>,
183183
file: AssistFile,
184184
}
@@ -211,12 +211,12 @@ impl ActionBuilder {
211211
}
212212

213213
/// Append specified `text` at the given `offset`
214-
pub(crate) fn insert(&mut self, offset: TextUnit, text: impl Into<String>) {
214+
pub(crate) fn insert(&mut self, offset: TextSize, text: impl Into<String>) {
215215
self.edit.insert(offset, text.into())
216216
}
217217

218218
/// Specify desired position of the cursor after the assist is applied.
219-
pub(crate) fn set_cursor(&mut self, offset: TextUnit) {
219+
pub(crate) fn set_cursor(&mut self, offset: TextSize) {
220220
self.cursor_position = Some(offset)
221221
}
222222

crates/ra_assists/src/handlers/add_custom_impl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use ra_syntax::{
22
ast::{self, AstNode},
33
Direction, SmolStr,
44
SyntaxKind::{IDENT, WHITESPACE},
5-
TextRange, TextUnit,
5+
TextRange, TextSize,
66
};
77
use stdx::SepBy;
88

@@ -60,7 +60,6 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
6060
.collect::<Vec<SmolStr>>();
6161
let has_more_derives = !new_attr_input.is_empty();
6262
let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string();
63-
let new_attr_input_len = new_attr_input.len();
6463

6564
let mut buf = String::new();
6665
buf.push_str("\n\nimpl ");
@@ -70,8 +69,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
7069
buf.push_str(" {\n");
7170

7271
let cursor_delta = if has_more_derives {
72+
let delta = input.syntax().text_range().len() - TextSize::of(&new_attr_input);
7373
edit.replace(input.syntax().text_range(), new_attr_input);
74-
input.syntax().text_range().len() - TextUnit::from_usize(new_attr_input_len)
74+
delta
7575
} else {
7676
let attr_range = attr.syntax().text_range();
7777
edit.delete(attr_range);
@@ -81,13 +81,13 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
8181
.next_sibling_or_token()
8282
.filter(|t| t.kind() == WHITESPACE)
8383
.map(|t| t.text_range())
84-
.unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0)));
84+
.unwrap_or_else(|| TextRange::new(TextSize::from(0), TextSize::from(0)));
8585
edit.delete(line_break_range);
8686

8787
attr_range.len() + line_break_range.len()
8888
};
8989

90-
edit.set_cursor(start_offset + TextUnit::of_str(&buf) - cursor_delta);
90+
edit.set_cursor(start_offset + TextSize::of(&buf) - cursor_delta);
9191
buf.push_str("\n}");
9292
edit.insert(start_offset, buf);
9393
})

crates/ra_assists/src/handlers/add_derive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ra_syntax::{
22
ast::{self, AstNode, AttrsOwner},
33
SyntaxKind::{COMMENT, WHITESPACE},
4-
TextUnit,
4+
TextSize,
55
};
66

77
use crate::{Assist, AssistCtx, AssistId};
@@ -37,17 +37,17 @@ pub(crate) fn add_derive(ctx: AssistCtx) -> Option<Assist> {
3737
let offset = match derive_attr {
3838
None => {
3939
edit.insert(node_start, "#[derive()]\n");
40-
node_start + TextUnit::of_str("#[derive(")
40+
node_start + TextSize::of("#[derive(")
4141
}
42-
Some(tt) => tt.syntax().text_range().end() - TextUnit::of_char(')'),
42+
Some(tt) => tt.syntax().text_range().end() - TextSize::of(')'),
4343
};
4444
edit.target(nominal.syntax().text_range());
4545
edit.set_cursor(offset)
4646
})
4747
}
4848

4949
// Insert `derive` after doc comments.
50-
fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> {
50+
fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> {
5151
let non_ws_child = nominal
5252
.syntax()
5353
.children_with_tokens()

crates/ra_assists/src/handlers/add_explicit_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option<Assist> {
3737
let stmt_range = stmt.syntax().text_range();
3838
let eq_range = stmt.eq_token()?.text_range();
3939
// Assist should only be applicable if cursor is between 'let' and '='
40-
let let_range = TextRange::from_to(stmt_range.start(), eq_range.start());
41-
let cursor_in_range = ctx.frange.range.is_subrange(&let_range);
40+
let let_range = TextRange::new(stmt_range.start(), eq_range.start());
41+
let cursor_in_range = let_range.contains_range(ctx.frange.range);
4242
if !cursor_in_range {
4343
return None;
4444
}

crates/ra_assists/src/handlers/add_from_impl_for_enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ra_syntax::{
22
ast::{self, AstNode, NameOwner},
3-
TextUnit,
3+
TextSize,
44
};
55
use stdx::format_to;
66

@@ -65,7 +65,7 @@ impl From<{0}> for {1} {{
6565
variant_name
6666
);
6767
edit.insert(start_offset, buf);
68-
edit.set_cursor(start_offset + TextUnit::of_str("\n\n"));
68+
edit.set_cursor(start_offset + TextSize::of("\n\n"));
6969
},
7070
)
7171
}

crates/ra_assists/src/handlers/add_function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ra_syntax::{
22
ast::{self, AstNode},
3-
SyntaxKind, SyntaxNode, TextUnit,
3+
SyntaxKind, SyntaxNode, TextSize,
44
};
55

66
use crate::{Assist, AssistCtx, AssistFile, AssistId};
@@ -69,8 +69,8 @@ pub(crate) fn add_function(ctx: AssistCtx) -> Option<Assist> {
6969
}
7070

7171
struct FunctionTemplate {
72-
insert_offset: TextUnit,
73-
cursor_offset: TextUnit,
72+
insert_offset: TextSize,
73+
cursor_offset: TextSize,
7474
fn_def: ast::SourceFile,
7575
file: AssistFile,
7676
}
@@ -129,7 +129,7 @@ impl FunctionBuilder {
129129
let fn_def = indent_once.increase_indent(fn_def);
130130
let fn_def = ast::make::add_trailing_newlines(1, fn_def);
131131
let fn_def = indent.increase_indent(fn_def);
132-
(fn_def, it.syntax().text_range().start() + TextUnit::from_usize(1))
132+
(fn_def, it.syntax().text_range().start() + TextSize::of('{'))
133133
}
134134
};
135135

crates/ra_assists/src/handlers/add_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ra_syntax::{
22
ast::{self, AstNode, NameOwner, TypeParamsOwner},
3-
TextUnit,
3+
TextSize,
44
};
55
use stdx::{format_to, SepBy};
66

@@ -51,7 +51,7 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
5151
format_to!(buf, "<{}>", generic_params)
5252
}
5353
buf.push_str(" {\n");
54-
edit.set_cursor(start_offset + TextUnit::of_str(&buf));
54+
edit.set_cursor(start_offset + TextSize::of(&buf));
5555
buf.push_str("\n}");
5656
edit.insert(start_offset, buf);
5757
})

crates/ra_assists/src/handlers/add_new.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ra_syntax::{
33
ast::{
44
self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner,
55
},
6-
TextUnit, T,
6+
TextSize, T,
77
};
88
use stdx::{format_to, SepBy};
99

@@ -77,16 +77,16 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> {
7777
.text_range()
7878
.end();
7979

80-
Some((start, TextUnit::from_usize(1)))
80+
Some((start, TextSize::of("\n")))
8181
})
8282
.unwrap_or_else(|| {
8383
buf = generate_impl_text(&strukt, &buf);
8484
let start = strukt.syntax().text_range().end();
8585

86-
(start, TextUnit::from_usize(3))
86+
(start, TextSize::of("\n}\n"))
8787
});
8888

89-
edit.set_cursor(start_offset + TextUnit::of_str(&buf) - end_offset);
89+
edit.set_cursor(start_offset + TextSize::of(&buf) - end_offset);
9090
edit.insert(start_offset, buf);
9191
})
9292
}

crates/ra_assists/src/handlers/apply_demorgan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn apply_demorgan(ctx: AssistCtx) -> Option<Assist> {
2626
let op = expr.op_kind()?;
2727
let op_range = expr.op_token()?.text_range();
2828
let opposite_op = opposite_logic_op(op)?;
29-
let cursor_in_range = ctx.frange.range.is_subrange(&op_range);
29+
let cursor_in_range = op_range.contains_range(ctx.frange.range);
3030
if !cursor_in_range {
3131
return None;
3232
}

0 commit comments

Comments
 (0)