aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/Cargo.toml3
-rw-r--r--crates/ra_ide/src/join_lines.rs27
-rw-r--r--crates/ra_ide/src/lib.rs2
-rw-r--r--crates/ra_ide/src/mock_analysis.rs2
-rw-r--r--crates/ra_ide/src/parent_module.rs2
-rw-r--r--crates/ra_ide/src/runnables.rs2
-rw-r--r--crates/ra_ide/src/typing.rs5
7 files changed, 32 insertions, 11 deletions
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index 8e0fa5917..938398a41 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -25,8 +25,7 @@ syntax = { path = "../syntax" }
25text_edit = { path = "../text_edit" } 25text_edit = { path = "../text_edit" }
26ra_db = { path = "../ra_db" } 26ra_db = { path = "../ra_db" }
27ra_ide_db = { path = "../ra_ide_db" } 27ra_ide_db = { path = "../ra_ide_db" }
28ra_cfg = { path = "../ra_cfg" } 28cfg = { path = "../cfg" }
29ra_fmt = { path = "../ra_fmt" }
30profile = { path = "../profile" } 29profile = { path = "../profile" }
31test_utils = { path = "../test_utils" } 30test_utils = { path = "../test_utils" }
32ra_assists = { path = "../ra_assists" } 31ra_assists = { path = "../ra_assists" }
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs
index 35cec87f6..f5c310701 100644
--- a/crates/ra_ide/src/join_lines.rs
+++ b/crates/ra_ide/src/join_lines.rs
@@ -1,10 +1,10 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use ra_fmt::{compute_ws, extract_trivial_expression}; 2use ra_assists::utils::extract_trivial_expression;
3use syntax::{ 3use syntax::{
4 algo::{find_covering_element, non_trivia_sibling}, 4 algo::{find_covering_element, non_trivia_sibling},
5 ast::{self, AstNode, AstToken}, 5 ast::{self, AstNode, AstToken},
6 Direction, NodeOrToken, SourceFile, 6 Direction, NodeOrToken, SourceFile,
7 SyntaxKind::{self, WHITESPACE}, 7 SyntaxKind::{self, USE_TREE, WHITESPACE},
8 SyntaxNode, SyntaxToken, TextRange, TextSize, T, 8 SyntaxNode, SyntaxToken, TextRange, TextSize, T,
9}; 9};
10use text_edit::{TextEdit, TextEditBuilder}; 10use text_edit::{TextEdit, TextEditBuilder};
@@ -168,6 +168,29 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
168 matches!((left, right), (T![,], T![')']) | (T![,], T![']'])) 168 matches!((left, right), (T![,], T![')']) | (T![,], T![']']))
169} 169}
170 170
171fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {
172 match left {
173 T!['('] | T!['['] => return "",
174 T!['{'] => {
175 if let USE_TREE = right {
176 return "";
177 }
178 }
179 _ => (),
180 }
181 match right {
182 T![')'] | T![']'] => return "",
183 T!['}'] => {
184 if let USE_TREE = left {
185 return "";
186 }
187 }
188 T![.] => return "",
189 _ => (),
190 }
191 " "
192}
193
171#[cfg(test)] 194#[cfg(test)]
172mod tests { 195mod tests {
173 use syntax::SourceFile; 196 use syntax::SourceFile;
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 20967ba99..1fdf17800 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -47,7 +47,7 @@ mod typing;
47 47
48use std::sync::Arc; 48use std::sync::Arc;
49 49
50use ra_cfg::CfgOptions; 50use cfg::CfgOptions;
51use ra_db::{ 51use ra_db::{
52 salsa::{self, ParallelDatabase}, 52 salsa::{self, ParallelDatabase},
53 CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, 53 CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath,
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index c7e0f4b58..a4691f028 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -1,7 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use ra_cfg::CfgOptions; 4use cfg::CfgOptions;
5use ra_db::{CrateName, FileSet, SourceRoot, VfsPath}; 5use ra_db::{CrateName, FileSet, SourceRoot, VfsPath};
6use test_utils::{ 6use test_utils::{
7 extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER, 7 extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER,
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs
index 69af0c86a..b78388e6b 100644
--- a/crates/ra_ide/src/parent_module.rs
+++ b/crates/ra_ide/src/parent_module.rs
@@ -63,7 +63,7 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
63 63
64#[cfg(test)] 64#[cfg(test)]
65mod tests { 65mod tests {
66 use ra_cfg::CfgOptions; 66 use cfg::CfgOptions;
67 use ra_db::Env; 67 use ra_db::Env;
68 use test_utils::mark; 68 use test_utils::mark;
69 69
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs
index 54cb3b309..fb40762cf 100644
--- a/crates/ra_ide/src/runnables.rs
+++ b/crates/ra_ide/src/runnables.rs
@@ -1,8 +1,8 @@
1use std::fmt; 1use std::fmt;
2 2
3use cfg::CfgExpr;
3use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; 4use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
4use itertools::Itertools; 5use itertools::Itertools;
5use ra_cfg::CfgExpr;
6use ra_ide_db::RootDatabase; 6use ra_ide_db::RootDatabase;
7use syntax::{ 7use syntax::{
8 ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner}, 8 ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner},
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs
index c408b1d52..7897c57b7 100644
--- a/crates/ra_ide/src/typing.rs
+++ b/crates/ra_ide/src/typing.rs
@@ -16,11 +16,10 @@
16mod on_enter; 16mod on_enter;
17 17
18use ra_db::{FilePosition, SourceDatabase}; 18use ra_db::{FilePosition, SourceDatabase};
19use ra_fmt::leading_indent;
20use ra_ide_db::{source_change::SourceFileEdit, RootDatabase}; 19use ra_ide_db::{source_change::SourceFileEdit, RootDatabase};
21use syntax::{ 20use syntax::{
22 algo::find_node_at_offset, 21 algo::find_node_at_offset,
23 ast::{self, AstToken}, 22 ast::{self, edit::IndentLevel, AstToken},
24 AstNode, SourceFile, 23 AstNode, SourceFile,
25 SyntaxKind::{FIELD_EXPR, METHOD_CALL_EXPR}, 24 SyntaxKind::{FIELD_EXPR, METHOD_CALL_EXPR},
26 TextRange, TextSize, 25 TextRange, TextSize,
@@ -104,7 +103,7 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
104 if !matches!(parent.kind(), FIELD_EXPR | METHOD_CALL_EXPR) { 103 if !matches!(parent.kind(), FIELD_EXPR | METHOD_CALL_EXPR) {
105 return None; 104 return None;
106 } 105 }
107 let prev_indent = leading_indent(&parent)?; 106 let prev_indent = IndentLevel::from_node(&parent);
108 let target_indent = format!(" {}", prev_indent); 107 let target_indent = format!(" {}", prev_indent);
109 let target_indent_len = TextSize::of(&target_indent); 108 let target_indent_len = TextSize::of(&target_indent);
110 if current_indent_len == target_indent_len { 109 if current_indent_len == target_indent_len {