diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/change.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_scope.rs | 67 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 12 |
4 files changed, 59 insertions, 38 deletions
diff --git a/crates/ra_ide/src/change.rs b/crates/ra_ide/src/change.rs index 45a58690b..18dad2ea3 100644 --- a/crates/ra_ide/src/change.rs +++ b/crates/ra_ide/src/change.rs | |||
@@ -145,6 +145,8 @@ impl LibraryData { | |||
145 | root_id: SourceRootId, | 145 | root_id: SourceRootId, |
146 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, | 146 | files: Vec<(FileId, RelativePathBuf, Arc<String>)>, |
147 | ) -> LibraryData { | 147 | ) -> LibraryData { |
148 | let _p = profile("LibraryData::prepare"); | ||
149 | |||
148 | #[cfg(not(feature = "wasm"))] | 150 | #[cfg(not(feature = "wasm"))] |
149 | let iter = files.par_iter(); | 151 | let iter = files.par_iter(); |
150 | #[cfg(feature = "wasm")] | 152 | #[cfg(feature = "wasm")] |
diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs index 458d7525e..64b04ec2b 100644 --- a/crates/ra_ide/src/completion/complete_scope.rs +++ b/crates/ra_ide/src/completion/complete_scope.rs | |||
@@ -6,6 +6,7 @@ use ra_text_edit::TextEditBuilder; | |||
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | 7 | ||
8 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; | 8 | use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; |
9 | use hir::{ModPath, PathKind}; | ||
9 | 10 | ||
10 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | 11 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { |
11 | if !ctx.is_trivial_path { | 12 | if !ctx.is_trivial_path { |
@@ -54,58 +55,76 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | |||
54 | } | 55 | } |
55 | } | 56 | } |
56 | 57 | ||
57 | fn build_import_label(name: &str, path: &[SmolStr]) -> String { | 58 | fn build_import_label(name: &str, path: &ModPath) -> String { |
58 | let mut buf = String::with_capacity(64); | 59 | let mut buf = String::with_capacity(64); |
59 | buf.push_str(name); | 60 | buf.push_str(name); |
60 | buf.push_str(" ("); | 61 | buf.push_str(" ("); |
61 | fmt_import_path(path, &mut buf); | 62 | buf.push_str(&path.to_string()); |
62 | buf.push_str(")"); | 63 | buf.push_str(")"); |
63 | buf | 64 | buf |
64 | } | 65 | } |
65 | 66 | ||
66 | fn fmt_import_path(path: &[SmolStr], buf: &mut String) { | ||
67 | let mut segments = path.iter(); | ||
68 | if let Some(s) = segments.next() { | ||
69 | buf.push_str(&s); | ||
70 | } | ||
71 | for s in segments { | ||
72 | buf.push_str("::"); | ||
73 | buf.push_str(&s); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | #[derive(Debug, Clone, Default)] | 67 | #[derive(Debug, Clone, Default)] |
78 | pub(crate) struct ImportResolver { | 68 | pub(crate) struct ImportResolver { |
79 | // todo: use fst crate or something like that | 69 | // todo: use fst crate or something like that |
80 | dummy_names: Vec<(SmolStr, Vec<SmolStr>)>, | 70 | dummy_names: Vec<(SmolStr, ModPath)>, |
81 | } | 71 | } |
82 | 72 | ||
83 | impl ImportResolver { | 73 | impl ImportResolver { |
84 | pub(crate) fn new() -> Self { | 74 | pub(crate) fn new() -> Self { |
75 | use hir::name; | ||
76 | |||
85 | let dummy_names = vec![ | 77 | let dummy_names = vec![ |
86 | (SmolStr::new("fmt"), vec![SmolStr::new("std"), SmolStr::new("fmt")]), | 78 | ( |
87 | (SmolStr::new("io"), vec![SmolStr::new("std"), SmolStr::new("io")]), | 79 | SmolStr::new("fmt"), |
88 | (SmolStr::new("iter"), vec![SmolStr::new("std"), SmolStr::new("iter")]), | 80 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![fmt]] }, |
89 | (SmolStr::new("hash"), vec![SmolStr::new("std"), SmolStr::new("hash")]), | 81 | ), |
82 | ( | ||
83 | SmolStr::new("io"), | ||
84 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![io]] }, | ||
85 | ), | ||
86 | ( | ||
87 | SmolStr::new("iter"), | ||
88 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![iter]] }, | ||
89 | ), | ||
90 | ( | ||
91 | SmolStr::new("hash"), | ||
92 | ModPath { kind: PathKind::Plain, segments: vec![name![std], name![hash]] }, | ||
93 | ), | ||
90 | ( | 94 | ( |
91 | SmolStr::new("Debug"), | 95 | SmolStr::new("Debug"), |
92 | vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Debug")], | 96 | ModPath { |
97 | kind: PathKind::Plain, | ||
98 | segments: vec![name![std], name![fmt], name![Debug]], | ||
99 | }, | ||
93 | ), | 100 | ), |
94 | ( | 101 | ( |
95 | SmolStr::new("Display"), | 102 | SmolStr::new("Display"), |
96 | vec![SmolStr::new("std"), SmolStr::new("fmt"), SmolStr::new("Display")], | 103 | ModPath { |
104 | kind: PathKind::Plain, | ||
105 | segments: vec![name![std], name![fmt], name![Display]], | ||
106 | }, | ||
97 | ), | 107 | ), |
98 | ( | 108 | ( |
99 | SmolStr::new("Hash"), | 109 | SmolStr::new("Hash"), |
100 | vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hash")], | 110 | ModPath { |
111 | kind: PathKind::Plain, | ||
112 | segments: vec![name![std], name![hash], name![Hash]], | ||
113 | }, | ||
101 | ), | 114 | ), |
102 | ( | 115 | ( |
103 | SmolStr::new("Hasher"), | 116 | SmolStr::new("Hasher"), |
104 | vec![SmolStr::new("std"), SmolStr::new("hash"), SmolStr::new("Hasher")], | 117 | ModPath { |
118 | kind: PathKind::Plain, | ||
119 | segments: vec![name![std], name![hash], name![Hasher]], | ||
120 | }, | ||
105 | ), | 121 | ), |
106 | ( | 122 | ( |
107 | SmolStr::new("Iterator"), | 123 | SmolStr::new("Iterator"), |
108 | vec![SmolStr::new("std"), SmolStr::new("iter"), SmolStr::new("Iterator")], | 124 | ModPath { |
125 | kind: PathKind::Plain, | ||
126 | segments: vec![name![std], name![iter], name![Iterator]], | ||
127 | }, | ||
109 | ), | 128 | ), |
110 | ]; | 129 | ]; |
111 | 130 | ||
@@ -115,7 +134,7 @@ impl ImportResolver { | |||
115 | // Returns a map of importable items filtered by name. | 134 | // Returns a map of importable items filtered by name. |
116 | // The map associates item name with its full path. | 135 | // The map associates item name with its full path. |
117 | // todo: should return Resolutions | 136 | // todo: should return Resolutions |
118 | pub(crate) fn all_names(&self, name: &str) -> FxHashMap<SmolStr, Vec<SmolStr>> { | 137 | pub(crate) fn all_names(&self, name: &str) -> FxHashMap<SmolStr, ModPath> { |
119 | if name.len() > 1 { | 138 | if name.len() > 1 { |
120 | self.dummy_names.iter().filter(|(n, _)| n.contains(name)).cloned().collect() | 139 | self.dummy_names.iter().filter(|(n, _)| n.contains(name)).cloned().collect() |
121 | } else { | 140 | } else { |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 393ca9447..de447a5aa 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -376,7 +376,7 @@ fn main() { | |||
376 | let mut start = 0; | 376 | let mut start = 0; |
377 | (0..2).for_each(|increment| { | 377 | (0..2).for_each(|increment| { |
378 | start += increment; | 378 | start += increment; |
379 | }) | 379 | }); |
380 | 380 | ||
381 | let multiply = |a, b, c, d| a * b * c * d; | 381 | let multiply = |a, b, c, d| a * b * c * d; |
382 | let _: i32 = multiply(1, 2, 3, 4); | 382 | let _: i32 = multiply(1, 2, 3, 4); |
@@ -399,37 +399,37 @@ fn main() { | |||
399 | label: "i32", | 399 | label: "i32", |
400 | }, | 400 | }, |
401 | InlayHint { | 401 | InlayHint { |
402 | range: [114; 122), | 402 | range: [115; 123), |
403 | kind: TypeHint, | 403 | kind: TypeHint, |
404 | label: "|…| -> i32", | 404 | label: "|…| -> i32", |
405 | }, | 405 | }, |
406 | InlayHint { | 406 | InlayHint { |
407 | range: [126; 127), | 407 | range: [127; 128), |
408 | kind: TypeHint, | 408 | kind: TypeHint, |
409 | label: "i32", | 409 | label: "i32", |
410 | }, | 410 | }, |
411 | InlayHint { | 411 | InlayHint { |
412 | range: [129; 130), | 412 | range: [130; 131), |
413 | kind: TypeHint, | 413 | kind: TypeHint, |
414 | label: "i32", | 414 | label: "i32", |
415 | }, | 415 | }, |
416 | InlayHint { | 416 | InlayHint { |
417 | range: [132; 133), | 417 | range: [133; 134), |
418 | kind: TypeHint, | 418 | kind: TypeHint, |
419 | label: "i32", | 419 | label: "i32", |
420 | }, | 420 | }, |
421 | InlayHint { | 421 | InlayHint { |
422 | range: [135; 136), | 422 | range: [136; 137), |
423 | kind: TypeHint, | 423 | kind: TypeHint, |
424 | label: "i32", | 424 | label: "i32", |
425 | }, | 425 | }, |
426 | InlayHint { | 426 | InlayHint { |
427 | range: [200; 212), | 427 | range: [201; 213), |
428 | kind: TypeHint, | 428 | kind: TypeHint, |
429 | label: "&|…| -> i32", | 429 | label: "&|…| -> i32", |
430 | }, | 430 | }, |
431 | InlayHint { | 431 | InlayHint { |
432 | range: [235; 244), | 432 | range: [236; 245), |
433 | kind: TypeHint, | 433 | kind: TypeHint, |
434 | label: "|| -> i32", | 434 | label: "|| -> i32", |
435 | }, | 435 | }, |
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 626efb603..9a84c1c88 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -2,7 +2,9 @@ | |||
2 | 2 | ||
3 | use hir::ModuleSource; | 3 | use hir::ModuleSource; |
4 | use ra_db::{RelativePath, RelativePathBuf, SourceDatabase, SourceDatabaseExt}; | 4 | use ra_db::{RelativePath, RelativePathBuf, SourceDatabase, SourceDatabaseExt}; |
5 | use ra_syntax::{algo::find_node_at_offset, ast, tokenize, AstNode, SyntaxKind, SyntaxNode}; | 5 | use ra_syntax::{ |
6 | algo::find_node_at_offset, ast, lex_single_valid_syntax_kind, AstNode, SyntaxKind, SyntaxNode, | ||
7 | }; | ||
6 | use ra_text_edit::TextEdit; | 8 | use ra_text_edit::TextEdit; |
7 | 9 | ||
8 | use crate::{ | 10 | use crate::{ |
@@ -17,11 +19,9 @@ pub(crate) fn rename( | |||
17 | position: FilePosition, | 19 | position: FilePosition, |
18 | new_name: &str, | 20 | new_name: &str, |
19 | ) -> Option<RangeInfo<SourceChange>> { | 21 | ) -> Option<RangeInfo<SourceChange>> { |
20 | let tokens = tokenize(new_name); | 22 | match lex_single_valid_syntax_kind(new_name)? { |
21 | if tokens.len() != 1 | 23 | SyntaxKind::IDENT | SyntaxKind::UNDERSCORE => (), |
22 | || (tokens[0].kind != SyntaxKind::IDENT && tokens[0].kind != SyntaxKind::UNDERSCORE) | 24 | _ => return None, |
23 | { | ||
24 | return None; | ||
25 | } | 25 | } |
26 | 26 | ||
27 | let parse = db.parse(position.file_id); | 27 | let parse = db.parse(position.file_id); |