aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock25
-rw-r--r--crates/ra_ide/src/typing.rs38
-rw-r--r--crates/ra_ide_db/src/change.rs9
-rw-r--r--crates/ra_ide_db/src/lib.rs18
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs4
-rw-r--r--crates/rust-analyzer/src/global_state.rs1
6 files changed, 48 insertions, 47 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2cb34fa20..308e36836 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -247,12 +247,13 @@ dependencies = [
247 247
248[[package]] 248[[package]]
249name = "crossbeam-queue" 249name = "crossbeam-queue"
250version = "0.2.2" 250version = "0.2.3"
251source = "registry+https://github.com/rust-lang/crates.io-index" 251source = "registry+https://github.com/rust-lang/crates.io-index"
252checksum = "ab6bffe714b6bb07e42f201352c34f51fefd355ace793f9e638ebd52d23f98d2" 252checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570"
253dependencies = [ 253dependencies = [
254 "cfg-if", 254 "cfg-if",
255 "crossbeam-utils", 255 "crossbeam-utils",
256 "maybe-uninit",
256] 257]
257 258
258[[package]] 259[[package]]
@@ -565,9 +566,9 @@ dependencies = [
565 566
566[[package]] 567[[package]]
567name = "jod-thread" 568name = "jod-thread"
568version = "0.1.1" 569version = "0.1.2"
569source = "registry+https://github.com/rust-lang/crates.io-index" 570source = "registry+https://github.com/rust-lang/crates.io-index"
570checksum = "4022656272c3e564a7cdebcaaba6518d844b0d0c1836597196efb5bfeb98bb49" 571checksum = "8b23360e99b8717f20aaa4598f5a6541efbe30630039fbc7706cf954a87947ae"
571 572
572[[package]] 573[[package]]
573name = "kernel32-sys" 574name = "kernel32-sys"
@@ -1520,9 +1521,9 @@ dependencies = [
1520 1521
1521[[package]] 1522[[package]]
1522name = "serde_json" 1523name = "serde_json"
1523version = "1.0.53" 1524version = "1.0.55"
1524source = "registry+https://github.com/rust-lang/crates.io-index" 1525source = "registry+https://github.com/rust-lang/crates.io-index"
1525checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2" 1526checksum = "ec2c5d7e739bc07a3e73381a39d61fdb5f671c60c1df26a130690665803d8226"
1526dependencies = [ 1527dependencies = [
1527 "itoa", 1528 "itoa",
1528 "ryu", 1529 "ryu",
@@ -1542,9 +1543,9 @@ dependencies = [
1542 1543
1543[[package]] 1544[[package]]
1544name = "serde_yaml" 1545name = "serde_yaml"
1545version = "0.8.12" 1546version = "0.8.13"
1546source = "registry+https://github.com/rust-lang/crates.io-index" 1547source = "registry+https://github.com/rust-lang/crates.io-index"
1547checksum = "16c7a592a1ec97c9c1c68d75b6e537dcbf60c7618e038e7841e00af1d9ccf0c4" 1548checksum = "ae3e2dd40a7cdc18ca80db804b7f461a39bb721160a85c9a1fa30134bf3c02a5"
1548dependencies = [ 1549dependencies = [
1549 "dtoa", 1550 "dtoa",
1550 "linked-hash-map", 1551 "linked-hash-map",
@@ -1585,9 +1586,9 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
1585 1586
1586[[package]] 1587[[package]]
1587name = "syn" 1588name = "syn"
1588version = "1.0.30" 1589version = "1.0.31"
1589source = "registry+https://github.com/rust-lang/crates.io-index" 1590source = "registry+https://github.com/rust-lang/crates.io-index"
1590checksum = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2" 1591checksum = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6"
1591dependencies = [ 1592dependencies = [
1592 "proc-macro2", 1593 "proc-macro2",
1593 "quote", 1594 "quote",
@@ -1596,9 +1597,9 @@ dependencies = [
1596 1597
1597[[package]] 1598[[package]]
1598name = "synstructure" 1599name = "synstructure"
1599version = "0.12.3" 1600version = "0.12.4"
1600source = "registry+https://github.com/rust-lang/crates.io-index" 1601source = "registry+https://github.com/rust-lang/crates.io-index"
1601checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" 1602checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
1602dependencies = [ 1603dependencies = [
1603 "proc-macro2", 1604 "proc-macro2",
1604 "quote", 1605 "quote",
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};
21use ra_syntax::{ 21use 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
27use ra_text_edit::TextEdit; 29use 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#"
261fn main() {
262 let _ = foo
263 <|>
264 bar()
265}
266"#,
267 r#"
268fn 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
17use crate::{ 17use 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
32impl fmt::Debug for AnalysisChange { 31impl 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};
17use ra_db::{ 17use 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};
22use rustc_hash::{FxHashMap, FxHashSet}; 22use rustc_hash::FxHashSet;
23 23
24use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; 24use 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)]
37pub struct RootDatabase { 37pub 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)]
140pub(crate) struct DebugData {
141 pub(crate) root_paths: FxHashMap<SourceRootId, String>,
142}
143
144impl 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) {