aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-09 09:56:54 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-09 09:56:54 +0000
commit34398a8756b56c323d3b4b2ef32fbca32d88a105 (patch)
tree92ebf0ec790945116e152fce7a9e3cc749c6b8e0
parent3e8351fb0607f8711749b00d80f68bf25de01a76 (diff)
parent02dd0cfd8c7bf50cfb26c3c5178be5af4f3fdd25 (diff)
Merge #766
766: Formatting code into ra_fmt r=matklad a=eulerdisk As discussed https://github.com/rust-analyzer/rust-analyzer/pull/762#discussion_r254905885 I did only move the code without other improvements. Co-authored-by: Andrea Pretto <[email protected]>
-rw-r--r--Cargo.lock11
-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
10 files changed, 33 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5ce4a8084..9c65b39f7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -902,8 +902,8 @@ version = "0.1.0"
902dependencies = [ 902dependencies = [
903 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 903 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
904 "ra_db 0.1.0", 904 "ra_db 0.1.0",
905 "ra_fmt 0.1.0",
905 "ra_hir 0.1.0", 906 "ra_hir 0.1.0",
906 "ra_ide_api_light 0.1.0",
907 "ra_syntax 0.1.0", 907 "ra_syntax 0.1.0",
908 "ra_text_edit 0.1.0", 908 "ra_text_edit 0.1.0",
909 "test_utils 0.1.0", 909 "test_utils 0.1.0",
@@ -935,6 +935,14 @@ dependencies = [
935] 935]
936 936
937[[package]] 937[[package]]
938name = "ra_fmt"
939version = "0.1.0"
940dependencies = [
941 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
942 "ra_syntax 0.1.0",
943]
944
945[[package]]
938name = "ra_hir" 946name = "ra_hir"
939version = "0.1.0" 947version = "0.1.0"
940dependencies = [ 948dependencies = [
@@ -988,6 +996,7 @@ dependencies = [
988 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 996 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
989 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 997 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
990 "proptest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 998 "proptest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
999 "ra_fmt 0.1.0",
991 "ra_syntax 0.1.0", 1000 "ra_syntax 0.1.0",
992 "ra_text_edit 0.1.0", 1001 "ra_text_edit 0.1.0",
993 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1002 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
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 41c8ac2f6..e240c35d6 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 a22ec5584..f74ab3c67 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 =