diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/typing.rs | 38 | ||||
-rw-r--r-- | crates/ra_ide_db/src/change.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 18 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 1 |
5 files changed, 35 insertions, 35 deletions
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 533306e2e..83776d2b6 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs | |||
@@ -21,7 +21,9 @@ use ra_ide_db::{source_change::SourceFileEdit, RootDatabase}; | |||
21 | use ra_syntax::{ | 21 | use ra_syntax::{ |
22 | algo::find_node_at_offset, | 22 | algo::find_node_at_offset, |
23 | ast::{self, AstToken}, | 23 | ast::{self, AstToken}, |
24 | AstNode, SourceFile, TextRange, TextSize, | 24 | AstNode, SourceFile, |
25 | SyntaxKind::{FIELD_EXPR, METHOD_CALL_EXPR}, | ||
26 | TextRange, TextSize, | ||
25 | }; | 27 | }; |
26 | 28 | ||
27 | use ra_text_edit::TextEdit; | 29 | use ra_text_edit::TextEdit; |
@@ -98,9 +100,12 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> { | |||
98 | }; | 100 | }; |
99 | let current_indent_len = TextSize::of(current_indent); | 101 | let current_indent_len = TextSize::of(current_indent); |
100 | 102 | ||
103 | let parent = whitespace.syntax().parent(); | ||
101 | // Make sure dot is a part of call chain | 104 | // Make sure dot is a part of call chain |
102 | let field_expr = ast::FieldExpr::cast(whitespace.syntax().parent())?; | 105 | if !matches!(parent.kind(), FIELD_EXPR | METHOD_CALL_EXPR) { |
103 | let prev_indent = leading_indent(field_expr.syntax())?; | 106 | return None; |
107 | } | ||
108 | let prev_indent = leading_indent(&parent)?; | ||
104 | let target_indent = format!(" {}", prev_indent); | 109 | let target_indent = format!(" {}", prev_indent); |
105 | let target_indent_len = TextSize::of(&target_indent); | 110 | let target_indent_len = TextSize::of(&target_indent); |
106 | if current_indent_len == target_indent_len { | 111 | if current_indent_len == target_indent_len { |
@@ -143,11 +148,11 @@ mod tests { | |||
143 | }) | 148 | }) |
144 | } | 149 | } |
145 | 150 | ||
146 | fn type_char(char_typed: char, before: &str, after: &str) { | 151 | fn type_char(char_typed: char, ra_fixture_before: &str, ra_fixture_after: &str) { |
147 | let actual = do_type_char(char_typed, before) | 152 | let actual = do_type_char(char_typed, ra_fixture_before) |
148 | .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); | 153 | .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); |
149 | 154 | ||
150 | assert_eq_text!(after, &actual); | 155 | assert_eq_text!(ra_fixture_after, &actual); |
151 | } | 156 | } |
152 | 157 | ||
153 | fn type_char_noop(char_typed: char, before: &str) { | 158 | fn type_char_noop(char_typed: char, before: &str) { |
@@ -249,6 +254,27 @@ fn foo() { | |||
249 | } | 254 | } |
250 | 255 | ||
251 | #[test] | 256 | #[test] |
257 | fn indents_new_chain_call_with_let() { | ||
258 | type_char( | ||
259 | '.', | ||
260 | r#" | ||
261 | fn main() { | ||
262 | let _ = foo | ||
263 | <|> | ||
264 | bar() | ||
265 | } | ||
266 | "#, | ||
267 | r#" | ||
268 | fn main() { | ||
269 | let _ = foo | ||
270 | . | ||
271 | bar() | ||
272 | } | ||
273 | "#, | ||
274 | ); | ||
275 | } | ||
276 | |||
277 | #[test] | ||
252 | fn indents_continued_chain_call() { | 278 | fn indents_continued_chain_call() { |
253 | type_char( | 279 | type_char( |
254 | '.', | 280 | '.', |
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs index 5dbe1c1b7..2fc796a85 100644 --- a/crates/ra_ide_db/src/change.rs +++ b/crates/ra_ide_db/src/change.rs | |||
@@ -16,7 +16,7 @@ use rustc_hash::FxHashMap; | |||
16 | 16 | ||
17 | use crate::{ | 17 | use crate::{ |
18 | symbol_index::{SymbolIndex, SymbolsDatabase}, | 18 | symbol_index::{SymbolIndex, SymbolsDatabase}, |
19 | DebugData, RootDatabase, | 19 | RootDatabase, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | #[derive(Default)] | 22 | #[derive(Default)] |
@@ -26,7 +26,6 @@ pub struct AnalysisChange { | |||
26 | files_changed: Vec<(FileId, Arc<String>)>, | 26 | files_changed: Vec<(FileId, Arc<String>)>, |
27 | libraries_added: Vec<LibraryData>, | 27 | libraries_added: Vec<LibraryData>, |
28 | crate_graph: Option<CrateGraph>, | 28 | crate_graph: Option<CrateGraph>, |
29 | debug_data: DebugData, | ||
30 | } | 29 | } |
31 | 30 | ||
32 | impl fmt::Debug for AnalysisChange { | 31 | impl fmt::Debug for AnalysisChange { |
@@ -87,10 +86,6 @@ impl AnalysisChange { | |||
87 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { | 86 | pub fn set_crate_graph(&mut self, graph: CrateGraph) { |
88 | self.crate_graph = Some(graph); | 87 | self.crate_graph = Some(graph); |
89 | } | 88 | } |
90 | |||
91 | pub fn set_debug_root_path(&mut self, source_root_id: SourceRootId, path: String) { | ||
92 | self.debug_data.root_paths.insert(source_root_id, path); | ||
93 | } | ||
94 | } | 89 | } |
95 | 90 | ||
96 | #[derive(Debug)] | 91 | #[derive(Debug)] |
@@ -218,8 +213,6 @@ impl RootDatabase { | |||
218 | if let Some(crate_graph) = change.crate_graph { | 213 | if let Some(crate_graph) = change.crate_graph { |
219 | self.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH) | 214 | self.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH) |
220 | } | 215 | } |
221 | |||
222 | Arc::make_mut(&mut self.debug_data).merge(change.debug_data) | ||
223 | } | 216 | } |
224 | 217 | ||
225 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { | 218 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { |
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 480fd4576..a808de4f1 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -17,9 +17,9 @@ use hir::db::{AstDatabase, DefDatabase}; | |||
17 | use ra_db::{ | 17 | use ra_db::{ |
18 | salsa::{self, Database, Durability}, | 18 | salsa::{self, Database, Durability}, |
19 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, | 19 | Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, |
20 | SourceRootId, Upcast, | 20 | Upcast, |
21 | }; | 21 | }; |
22 | use rustc_hash::{FxHashMap, FxHashSet}; | 22 | use rustc_hash::FxHashSet; |
23 | 23 | ||
24 | use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; | 24 | use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; |
25 | 25 | ||
@@ -36,7 +36,6 @@ use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; | |||
36 | #[derive(Debug)] | 36 | #[derive(Debug)] |
37 | pub struct RootDatabase { | 37 | pub struct RootDatabase { |
38 | runtime: salsa::Runtime<RootDatabase>, | 38 | runtime: salsa::Runtime<RootDatabase>, |
39 | pub(crate) debug_data: Arc<DebugData>, | ||
40 | pub last_gc: crate::wasm_shims::Instant, | 39 | pub last_gc: crate::wasm_shims::Instant, |
41 | pub last_gc_check: crate::wasm_shims::Instant, | 40 | pub last_gc_check: crate::wasm_shims::Instant, |
42 | } | 41 | } |
@@ -98,7 +97,6 @@ impl RootDatabase { | |||
98 | runtime: salsa::Runtime::default(), | 97 | runtime: salsa::Runtime::default(), |
99 | last_gc: crate::wasm_shims::Instant::now(), | 98 | last_gc: crate::wasm_shims::Instant::now(), |
100 | last_gc_check: crate::wasm_shims::Instant::now(), | 99 | last_gc_check: crate::wasm_shims::Instant::now(), |
101 | debug_data: Default::default(), | ||
102 | }; | 100 | }; |
103 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); | 101 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); |
104 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); | 102 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); |
@@ -121,7 +119,6 @@ impl salsa::ParallelDatabase for RootDatabase { | |||
121 | runtime: self.runtime.snapshot(self), | 119 | runtime: self.runtime.snapshot(self), |
122 | last_gc: self.last_gc, | 120 | last_gc: self.last_gc, |
123 | last_gc_check: self.last_gc_check, | 121 | last_gc_check: self.last_gc_check, |
124 | debug_data: Arc::clone(&self.debug_data), | ||
125 | }) | 122 | }) |
126 | } | 123 | } |
127 | } | 124 | } |
@@ -135,14 +132,3 @@ fn line_index(db: &impl LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> { | |||
135 | let text = db.file_text(file_id); | 132 | let text = db.file_text(file_id); |
136 | Arc::new(LineIndex::new(&*text)) | 133 | Arc::new(LineIndex::new(&*text)) |
137 | } | 134 | } |
138 | |||
139 | #[derive(Debug, Default, Clone)] | ||
140 | pub(crate) struct DebugData { | ||
141 | pub(crate) root_paths: FxHashMap<SourceRootId, String>, | ||
142 | } | ||
143 | |||
144 | impl DebugData { | ||
145 | pub(crate) fn merge(&mut self, other: DebugData) { | ||
146 | self.root_paths.extend(other.root_paths.into_iter()); | ||
147 | } | ||
148 | } | ||
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 45af96317..97367d7c6 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -111,10 +111,6 @@ pub(crate) fn load( | |||
111 | vfs.root2path(root) | 111 | vfs.root2path(root) |
112 | ); | 112 | ); |
113 | analysis_change.add_root(source_root_id, is_local); | 113 | analysis_change.add_root(source_root_id, is_local); |
114 | analysis_change.set_debug_root_path( | ||
115 | source_root_id, | ||
116 | source_roots[&source_root_id].path().display().to_string(), | ||
117 | ); | ||
118 | 114 | ||
119 | let vfs_root_path = vfs.root2path(root); | 115 | let vfs_root_path = vfs.root2path(root); |
120 | if extern_dirs.contains(&vfs_root_path) { | 116 | if extern_dirs.contains(&vfs_root_path) { |
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 96d91b12d..21116e165 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -126,7 +126,6 @@ impl GlobalState { | |||
126 | let vfs_root_path = vfs.root2path(r); | 126 | let vfs_root_path = vfs.root2path(r); |
127 | let is_local = local_roots.iter().any(|it| vfs_root_path.starts_with(it)); | 127 | let is_local = local_roots.iter().any(|it| vfs_root_path.starts_with(it)); |
128 | change.add_root(SourceRootId(r.0), is_local); | 128 | change.add_root(SourceRootId(r.0), is_local); |
129 | change.set_debug_root_path(SourceRootId(r.0), vfs_root_path.display().to_string()); | ||
130 | 129 | ||
131 | // FIXME: add path2root in vfs to simpily this logic | 130 | // FIXME: add path2root in vfs to simpily this logic |
132 | if extern_dirs.contains(&vfs_root_path) { | 131 | if extern_dirs.contains(&vfs_root_path) { |