Skip to content

Commit 34398a8

Browse files
bors[bot]eulerdisk
andcommitted
Merge #766
766: Formatting code into ra_fmt r=matklad a=eulerdisk As discussed #762 (comment) I did only move the code without other improvements. Co-authored-by: Andrea Pretto <[email protected]>
2 parents 3e8351f + 02dd0cf commit 34398a8

File tree

10 files changed

+33
-10
lines changed

10 files changed

+33
-10
lines changed

Cargo.lock

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_assists/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ authors = ["Aleksey Kladov <[email protected]>"]
77
[dependencies]
88
join_to_string = "0.1.3"
99

10-
ra_ide_api_light = { path = "../ra_ide_api_light" }
1110
ra_syntax = { path = "../ra_syntax" }
1211
ra_text_edit = { path = "../ra_text_edit" }
12+
ra_fmt = { path = "../ra_fmt" }
1313
ra_db = { path = "../ra_db" }
1414
hir = { path = "../ra_hir", package = "ra_hir" }
1515

crates/ra_assists/src/assist_ctx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ra_syntax::{
55
SourceFile, TextRange, AstNode, TextUnit, SyntaxNode,
66
algo::{find_leaf_at_offset, find_node_at_offset, find_covering_node, LeafAtOffset},
77
};
8-
use ra_ide_api_light::formatting::{leading_indent, reindent};
8+
use ra_fmt::{leading_indent, reindent};
99

1010
use crate::{AssistLabel, AssistAction};
1111

crates/ra_assists/src/replace_if_let_with_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use ra_syntax::{AstNode, ast};
2-
use ra_ide_api_light::formatting::extract_trivial_expression;
2+
use ra_fmt::extract_trivial_expression;
33
use hir::db::HirDatabase;
44

55
use crate::{AssistCtx, Assist};

crates/ra_fmt/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -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" }

crates/ra_ide_api_light/src/formatting.rs renamed to crates/ra_fmt/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! This crate provides some utilities for indenting rust code.
2+
//!
13
use itertools::Itertools;
24
use ra_syntax::{
35
AstNode,
@@ -50,7 +52,7 @@ pub fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
5052
Some(expr)
5153
}
5254

53-
pub(crate) fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str {
55+
pub fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str {
5456
match left.kind() {
5557
L_PAREN | L_BRACK => return "",
5658
L_CURLY => {

crates/ra_ide_api_light/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc-hash = "1.0"
1313

1414
ra_syntax = { path = "../ra_syntax" }
1515
ra_text_edit = { path = "../ra_text_edit" }
16+
ra_fmt = { path = "../ra_fmt" }
1617

1718
[dev-dependencies]
1819
test_utils = { path = "../test_utils" }

crates/ra_ide_api_light/src/join_lines.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use ra_syntax::{
55
algo::find_covering_node,
66
ast,
77
};
8-
8+
use ra_fmt::{
9+
compute_ws, extract_trivial_expression
10+
};
911
use crate::{
1012
LocalEdit, TextEditBuilder,
11-
formatting::{compute_ws, extract_trivial_expression},
1213
};
1314

1415
pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {

crates/ra_ide_api_light/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! This usually means functions which take syntax tree as an input and produce
44
//! an edit or some auxiliary info.
55
6-
pub mod formatting;
76
mod extend_selection;
87
mod folding_ranges;
98
mod line_index;

crates/ra_ide_api_light/src/typing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use ra_syntax::{
44
algo::{find_node_at_offset, find_leaf_at_offset, LeafAtOffset},
55
ast::{self, AstToken},
66
};
7-
8-
use crate::{LocalEdit, TextEditBuilder, formatting::leading_indent};
7+
use ra_fmt::leading_indent;
8+
use crate::{LocalEdit, TextEditBuilder};
99

1010
pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> {
1111
let comment =

0 commit comments

Comments
 (0)