diff options
author | Andrea Pretto <[email protected]> | 2019-02-08 17:58:27 +0000 |
---|---|---|
committer | Andrea Pretto <[email protected]> | 2019-02-08 17:58:27 +0000 |
commit | 02dd0cfd8c7bf50cfb26c3c5178be5af4f3fdd25 (patch) | |
tree | 7fe910ed99307268a06e5668bb4401b6c6916fdb /crates | |
parent | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (diff) |
Refactor formatting code out of ra_ida_api_light into ra_fmt.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/replace_if_let_with_match.rs | 2 | ||||
-rw-r--r-- | crates/ra_fmt/Cargo.toml | 11 | ||||
-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.toml | 1 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/join_lines.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/typing.rs | 4 |
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] |
8 | join_to_string = "0.1.3" | 8 | join_to_string = "0.1.3" |
9 | 9 | ||
10 | ra_ide_api_light = { path = "../ra_ide_api_light" } | ||
11 | ra_syntax = { path = "../ra_syntax" } | 10 | ra_syntax = { path = "../ra_syntax" } |
12 | ra_text_edit = { path = "../ra_text_edit" } | 11 | ra_text_edit = { path = "../ra_text_edit" } |
12 | ra_fmt = { path = "../ra_fmt" } | ||
13 | ra_db = { path = "../ra_db" } | 13 | ra_db = { path = "../ra_db" } |
14 | hir = { path = "../ra_hir", package = "ra_hir" } | 14 | hir = { 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 | }; |
8 | use ra_ide_api_light::formatting::{leading_indent, reindent}; | 8 | use ra_fmt::{leading_indent, reindent}; |
9 | 9 | ||
10 | use crate::{AssistLabel, AssistAction}; | 10 | use 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 @@ | |||
1 | use ra_syntax::{AstNode, ast}; | 1 | use ra_syntax::{AstNode, ast}; |
2 | use ra_ide_api_light::formatting::extract_trivial_expression; | 2 | use ra_fmt::extract_trivial_expression; |
3 | use hir::db::HirDatabase; | 3 | use hir::db::HirDatabase; |
4 | 4 | ||
5 | use crate::{AssistCtx, Assist}; | 5 | use 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] | ||
2 | edition = "2018" | ||
3 | name = "ra_fmt" | ||
4 | version = "0.1.0" | ||
5 | authors = ["Aleksey Kladov <[email protected]>"] | ||
6 | publish = false | ||
7 | |||
8 | [dependencies] | ||
9 | itertools = "0.8.0" | ||
10 | |||
11 | ra_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 | //! | ||
1 | use itertools::Itertools; | 3 | use itertools::Itertools; |
2 | use ra_syntax::{ | 4 | use 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 | ||
53 | pub(crate) fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str { | 55 | pub 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 | ||
14 | ra_syntax = { path = "../ra_syntax" } | 14 | ra_syntax = { path = "../ra_syntax" } |
15 | ra_text_edit = { path = "../ra_text_edit" } | 15 | ra_text_edit = { path = "../ra_text_edit" } |
16 | ra_fmt = { path = "../ra_fmt" } | ||
16 | 17 | ||
17 | [dev-dependencies] | 18 | [dev-dependencies] |
18 | test_utils = { path = "../test_utils" } | 19 | test_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 | 8 | use ra_fmt::{ | |
9 | compute_ws, extract_trivial_expression | ||
10 | }; | ||
9 | use crate::{ | 11 | use crate::{ |
10 | LocalEdit, TextEditBuilder, | 12 | LocalEdit, TextEditBuilder, |
11 | formatting::{compute_ws, extract_trivial_expression}, | ||
12 | }; | 13 | }; |
13 | 14 | ||
14 | pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { | 15 | pub 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 | ||
6 | pub mod formatting; | ||
7 | mod extend_selection; | 6 | mod extend_selection; |
8 | mod folding_ranges; | 7 | mod folding_ranges; |
9 | mod line_index; | 8 | mod 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 | 7 | use ra_fmt::leading_indent; | |
8 | use crate::{LocalEdit, TextEditBuilder, formatting::leading_indent}; | 8 | use crate::{LocalEdit, TextEditBuilder}; |
9 | 9 | ||
10 | pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { | 10 | pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { |
11 | let comment = | 11 | let comment = |