aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src/main_loop/handlers.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 246085005..e87e8db5d 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -23,7 +23,7 @@ use ra_ide::{
23 SearchScope, 23 SearchScope,
24}; 24};
25use ra_prof::profile; 25use ra_prof::profile;
26use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; 26use ra_syntax::{AstNode, SyntaxKind, TextRange, TextSize};
27use rustc_hash::FxHashMap; 27use rustc_hash::FxHashMap;
28use serde::{Deserialize, Serialize}; 28use serde::{Deserialize, Serialize};
29use serde_json::to_value; 29use serde_json::to_value;
@@ -97,7 +97,7 @@ pub fn handle_selection_range(
97 .map(|position| { 97 .map(|position| {
98 let mut ranges = Vec::new(); 98 let mut ranges = Vec::new();
99 { 99 {
100 let mut range = TextRange::from_to(position, position); 100 let mut range = TextRange::new(position, position);
101 loop { 101 loop {
102 ranges.push(range); 102 ranges.push(range);
103 let frange = FileRange { file_id, range }; 103 let frange = FileRange { file_id, range };
@@ -184,11 +184,11 @@ pub fn handle_on_type_formatting(
184 184
185 // in `ra_ide`, the `on_type` invariant is that 185 // in `ra_ide`, the `on_type` invariant is that
186 // `text.char_at(position) == typed_char`. 186 // `text.char_at(position) == typed_char`.
187 position.offset -= TextUnit::of_char('.'); 187 position.offset -= TextSize::of('.');
188 let char_typed = params.ch.chars().next().unwrap_or('\0'); 188 let char_typed = params.ch.chars().next().unwrap_or('\0');
189 assert!({ 189 assert!({
190 let text = world.analysis().file_text(position.file_id)?; 190 let text = world.analysis().file_text(position.file_id)?;
191 text[position.offset.to_usize()..].starts_with(char_typed) 191 text[usize::from(position.offset)..].starts_with(char_typed)
192 }); 192 });
193 193
194 // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`, 194 // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,
@@ -413,7 +413,7 @@ pub fn handle_runnables(
413 args: check_args, 413 args: check_args,
414 extra_args: Vec::new(), 414 extra_args: Vec::new(),
415 env: FxHashMap::default(), 415 env: FxHashMap::default(),
416 cwd: workspace_root.map(|root| root.to_string_lossy().to_string()), 416 cwd: workspace_root.map(|root| root.to_owned()),
417 }); 417 });
418 Ok(res) 418 Ok(res)
419} 419}
@@ -432,7 +432,7 @@ pub fn handle_completion(
432 let syntax = source_file.syntax(); 432 let syntax = source_file.syntax();
433 let text = syntax.text(); 433 let text = syntax.text();
434 if let Some(next_char) = text.char_at(position.offset) { 434 if let Some(next_char) = text.char_at(position.offset) {
435 let diff = TextUnit::of_char(next_char) + TextUnit::of_char(':'); 435 let diff = TextSize::of(next_char) + TextSize::of(':');
436 let prev_char = position.offset - diff; 436 let prev_char = position.offset - diff;
437 if text.char_at(prev_char) != Some(':') { 437 if text.char_at(prev_char) != Some(':') {
438 res = true; 438 res = true;
@@ -621,7 +621,7 @@ pub fn handle_formatting(
621 let crate_ids = world.analysis().crate_for(file_id)?; 621 let crate_ids = world.analysis().crate_for(file_id)?;
622 622
623 let file_line_index = world.analysis().file_line_index(file_id)?; 623 let file_line_index = world.analysis().file_line_index(file_id)?;
624 let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); 624 let end_position = TextSize::of(file.as_str()).conv_with(&file_line_index);
625 625
626 let mut rustfmt = match &world.config.rustfmt { 626 let mut rustfmt = match &world.config.rustfmt {
627 RustfmtConfig::Rustfmt { extra_args } => { 627 RustfmtConfig::Rustfmt { extra_args } => {
@@ -727,7 +727,7 @@ pub fn handle_code_action(
727 let fixes_from_diagnostics = diagnostics 727 let fixes_from_diagnostics = diagnostics
728 .into_iter() 728 .into_iter()
729 .filter_map(|d| Some((d.range, d.fix?))) 729 .filter_map(|d| Some((d.range, d.fix?)))
730 .filter(|(diag_range, _fix)| diag_range.intersection(&range).is_some()) 730 .filter(|(diag_range, _fix)| diag_range.intersect(range).is_some())
731 .map(|(_range, fix)| fix); 731 .map(|(_range, fix)| fix);
732 732
733 for source_edit in fixes_from_diagnostics { 733 for source_edit in fixes_from_diagnostics {
@@ -752,7 +752,7 @@ pub fn handle_code_action(
752 752
753 for fix in world.check_fixes.get(&file_id).into_iter().flatten() { 753 for fix in world.check_fixes.get(&file_id).into_iter().flatten() {
754 let fix_range = fix.range.conv_with(&line_index); 754 let fix_range = fix.range.conv_with(&line_index);
755 if fix_range.intersection(&range).is_none() { 755 if fix_range.intersect(range).is_none() {
756 continue; 756 continue;
757 } 757 }
758 res.push(fix.action.clone()); 758 res.push(fix.action.clone());
@@ -1013,7 +1013,7 @@ fn to_lsp_runnable(
1013 m.insert("RUST_BACKTRACE".to_string(), "short".to_string()); 1013 m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
1014 m 1014 m
1015 }, 1015 },
1016 cwd: world.workspace_root_for(file_id).map(|root| root.to_string_lossy().to_string()), 1016 cwd: world.workspace_root_for(file_id).map(|root| root.to_owned()),
1017 }) 1017 })
1018} 1018}
1019 1019
@@ -1136,7 +1136,7 @@ pub fn handle_semantic_tokens(
1136 let (token_index, modifier_bitset) = highlight_range.highlight.conv(); 1136 let (token_index, modifier_bitset) = highlight_range.highlight.conv();
1137 for mut range in line_index.lines(highlight_range.range) { 1137 for mut range in line_index.lines(highlight_range.range) {
1138 if text[range].ends_with('\n') { 1138 if text[range].ends_with('\n') {
1139 range = TextRange::from_to(range.start(), range.end() - TextUnit::of_char('\n')); 1139 range = TextRange::new(range.start(), range.end() - TextSize::of('\n'));
1140 } 1140 }
1141 let range = range.conv_with(&line_index); 1141 let range = range.conv_with(&line_index);
1142 builder.push(range, token_index, modifier_bitset); 1142 builder.push(range, token_index, modifier_bitset);