aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAndrea Pretto <[email protected]>2019-02-08 17:58:27 +0000
committerAndrea Pretto <[email protected]>2019-02-08 17:58:27 +0000
commit02dd0cfd8c7bf50cfb26c3c5178be5af4f3fdd25 (patch)
tree7fe910ed99307268a06e5668bb4401b6c6916fdb /crates
parent12e3b4c70b5ef23b2fdfc197296d483680e125f9 (diff)
Refactor formatting code out of ra_ida_api_light into ra_fmt.
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/Cargo.toml2
-rw-r--r--crates/ra_assists/src/assist_ctx.rs2
-rw-r--r--crates/ra_assists/src/replace_if_let_with_match.rs2
-rw-r--r--crates/ra_fmt/Cargo.toml11
-rw-r--r--crates/ra_fmt/src/lib.rs (renamed from crates/ra_ide_api_light/src/formatting.rs)4
-rw-r--r--crates/ra_ide_api_light/Cargo.toml1
-rw-r--r--crates/ra_ide_api_light/src/join_lines.rs5
-rw-r--r--crates/ra_ide_api_light/src/lib.rs1
-rw-r--r--crates/ra_ide_api_light/src/typing.rs4
9 files changed, 23 insertions, 9 deletions
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml
index 20bc253e3..71ab2dcd2 100644
--- a/crates/ra_assists/Cargo.toml
+++ b/crates/ra_assists/Cargo.toml
@@ -7,9 +7,9 @@ authors = ["Aleksey Kladov <[email protected]>"]
7[dependencies] 7[dependencies]
8join_to_string = "0.1.3" 8join_to_string = "0.1.3"
9 9
10ra_ide_api_light = { path = "../ra_ide_api_light" }
11ra_syntax = { path = "../ra_syntax" } 10ra_syntax = { path = "../ra_syntax" }
12ra_text_edit = { path = "../ra_text_edit" } 11ra_text_edit = { path = "../ra_text_edit" }
12ra_fmt = { path = "../ra_fmt" }
13ra_db = { path = "../ra_db" } 13ra_db = { path = "../ra_db" }
14hir = { path = "../ra_hir", package = "ra_hir" } 14hir = { path = "../ra_hir", package = "ra_hir" }
15 15
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index 0bf640241..7fb11d5f5 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -5,7 +5,7 @@ use ra_syntax::{
5 SourceFile, TextRange, AstNode, TextUnit, SyntaxNode, 5 SourceFile, TextRange, AstNode, TextUnit, SyntaxNode,
6 algo::{find_leaf_at_offset, find_node_at_offset, find_covering_node, LeafAtOffset}, 6 algo::{find_leaf_at_offset, find_node_at_offset, find_covering_node, LeafAtOffset},
7}; 7};
8use ra_ide_api_light::formatting::{leading_indent, reindent}; 8use ra_fmt::{leading_indent, reindent};
9 9
10use crate::{AssistLabel, AssistAction}; 10use crate::{AssistLabel, AssistAction};
11 11
diff --git a/crates/ra_assists/src/replace_if_let_with_match.rs b/crates/ra_assists/src/replace_if_let_with_match.rs
index 683f0d119..bdac381c2 100644
--- a/crates/ra_assists/src/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/replace_if_let_with_match.rs
@@ -1,5 +1,5 @@
1use ra_syntax::{AstNode, ast}; 1use ra_syntax::{AstNode, ast};
2use ra_ide_api_light::formatting::extract_trivial_expression; 2use ra_fmt::extract_trivial_expression;
3use hir::db::HirDatabase; 3use hir::db::HirDatabase;
4 4
5use crate::{AssistCtx, Assist}; 5use crate::{AssistCtx, Assist};
diff --git a/crates/ra_fmt/Cargo.toml b/crates/ra_fmt/Cargo.toml
new file mode 100644
index 000000000..1cf1b520f
--- /dev/null
+++ b/crates/ra_fmt/Cargo.toml
@@ -0,0 +1,11 @@
1[package]
2edition = "2018"
3name = "ra_fmt"
4version = "0.1.0"
5authors = ["Aleksey Kladov <[email protected]>"]
6publish = false
7
8[dependencies]
9itertools = "0.8.0"
10
11ra_syntax = { path = "../ra_syntax" }
diff --git a/crates/ra_ide_api_light/src/formatting.rs b/crates/ra_fmt/src/lib.rs
index 8bc03f974..62e6fb9c1 100644
--- a/crates/ra_ide_api_light/src/formatting.rs
+++ b/crates/ra_fmt/src/lib.rs
@@ -1,3 +1,5 @@
1//! This crate provides some utilities for indenting rust code.
2//!
1use itertools::Itertools; 3use itertools::Itertools;
2use ra_syntax::{ 4use ra_syntax::{
3 AstNode, 5 AstNode,
@@ -50,7 +52,7 @@ pub fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
50 Some(expr) 52 Some(expr)
51} 53}
52 54
53pub(crate) fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str { 55pub fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str {
54 match left.kind() { 56 match left.kind() {
55 L_PAREN | L_BRACK => return "", 57 L_PAREN | L_BRACK => return "",
56 L_CURLY => { 58 L_CURLY => {
diff --git a/crates/ra_ide_api_light/Cargo.toml b/crates/ra_ide_api_light/Cargo.toml
index c1e4314ce..86311e677 100644
--- a/crates/ra_ide_api_light/Cargo.toml
+++ b/crates/ra_ide_api_light/Cargo.toml
@@ -13,6 +13,7 @@ rustc-hash = "1.0"
13 13
14ra_syntax = { path = "../ra_syntax" } 14ra_syntax = { path = "../ra_syntax" }
15ra_text_edit = { path = "../ra_text_edit" } 15ra_text_edit = { path = "../ra_text_edit" }
16ra_fmt = { path = "../ra_fmt" }
16 17
17[dev-dependencies] 18[dev-dependencies]
18test_utils = { path = "../test_utils" } 19test_utils = { path = "../test_utils" }
diff --git a/crates/ra_ide_api_light/src/join_lines.rs b/crates/ra_ide_api_light/src/join_lines.rs
index 03770c52e..970afd327 100644
--- a/crates/ra_ide_api_light/src/join_lines.rs
+++ b/crates/ra_ide_api_light/src/join_lines.rs
@@ -5,10 +5,11 @@ use ra_syntax::{
5 algo::find_covering_node, 5 algo::find_covering_node,
6 ast, 6 ast,
7}; 7};
8 8use ra_fmt::{
9 compute_ws, extract_trivial_expression
10};
9use crate::{ 11use crate::{
10 LocalEdit, TextEditBuilder, 12 LocalEdit, TextEditBuilder,
11 formatting::{compute_ws, extract_trivial_expression},
12}; 13};
13 14
14pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { 15pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
diff --git a/crates/ra_ide_api_light/src/lib.rs b/crates/ra_ide_api_light/src/lib.rs
index f3078f51e..6d1ce8dbf 100644
--- a/crates/ra_ide_api_light/src/lib.rs
+++ b/crates/ra_ide_api_light/src/lib.rs
@@ -3,7 +3,6 @@
3//! This usually means functions which take syntax tree as an input and produce 3//! This usually means functions which take syntax tree as an input and produce
4//! an edit or some auxiliary info. 4//! an edit or some auxiliary info.
5 5
6pub mod formatting;
7mod extend_selection; 6mod extend_selection;
8mod folding_ranges; 7mod folding_ranges;
9mod line_index; 8mod line_index;
diff --git a/crates/ra_ide_api_light/src/typing.rs b/crates/ra_ide_api_light/src/typing.rs
index a08a5a8c5..9dd9f1c1d 100644
--- a/crates/ra_ide_api_light/src/typing.rs
+++ b/crates/ra_ide_api_light/src/typing.rs
@@ -4,8 +4,8 @@ use ra_syntax::{
4 algo::{find_node_at_offset, find_leaf_at_offset, LeafAtOffset}, 4 algo::{find_node_at_offset, find_leaf_at_offset, LeafAtOffset},
5 ast::{self, AstToken}, 5 ast::{self, AstToken},
6}; 6};
7 7use ra_fmt::leading_indent;
8use crate::{LocalEdit, TextEditBuilder, formatting::leading_indent}; 8use crate::{LocalEdit, TextEditBuilder};
9 9
10pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { 10pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> {
11 let comment = 11 let comment =