mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Refactor formatting code out of ra_ida_api_light into ra_fmt.
This commit is contained in:
parent
12e3b4c70b
commit
02dd0cfd8c
10 changed files with 33 additions and 10 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -900,8 +900,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_db 0.1.0",
|
||||
"ra_fmt 0.1.0",
|
||||
"ra_hir 0.1.0",
|
||||
"ra_ide_api_light 0.1.0",
|
||||
"ra_syntax 0.1.0",
|
||||
"ra_text_edit 0.1.0",
|
||||
"test_utils 0.1.0",
|
||||
|
@ -932,6 +932,14 @@ dependencies = [
|
|||
"test_utils 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ra_fmt"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_syntax 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ra_hir"
|
||||
version = "0.1.0"
|
||||
|
@ -986,6 +994,7 @@ dependencies = [
|
|||
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proptest 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ra_fmt 0.1.0",
|
||||
"ra_syntax 0.1.0",
|
||||
"ra_text_edit 0.1.0",
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -7,9 +7,9 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
|||
[dependencies]
|
||||
join_to_string = "0.1.3"
|
||||
|
||||
ra_ide_api_light = { path = "../ra_ide_api_light" }
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_text_edit = { path = "../ra_text_edit" }
|
||||
ra_fmt = { path = "../ra_fmt" }
|
||||
ra_db = { path = "../ra_db" }
|
||||
hir = { path = "../ra_hir", package = "ra_hir" }
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use ra_syntax::{
|
|||
SourceFile, TextRange, AstNode, TextUnit, SyntaxNode,
|
||||
algo::{find_leaf_at_offset, find_node_at_offset, find_covering_node, LeafAtOffset},
|
||||
};
|
||||
use ra_ide_api_light::formatting::{leading_indent, reindent};
|
||||
use ra_fmt::{leading_indent, reindent};
|
||||
|
||||
use crate::{AssistLabel, AssistAction};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ra_syntax::{AstNode, ast};
|
||||
use ra_ide_api_light::formatting::extract_trivial_expression;
|
||||
use ra_fmt::extract_trivial_expression;
|
||||
use hir::db::HirDatabase;
|
||||
|
||||
use crate::{AssistCtx, Assist};
|
||||
|
|
11
crates/ra_fmt/Cargo.toml
Normal file
11
crates/ra_fmt/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
edition = "2018"
|
||||
name = "ra_fmt"
|
||||
version = "0.1.0"
|
||||
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
itertools = "0.8.0"
|
||||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
|
@ -1,3 +1,5 @@
|
|||
//! This crate provides some utilities for indenting rust code.
|
||||
//!
|
||||
use itertools::Itertools;
|
||||
use ra_syntax::{
|
||||
AstNode,
|
||||
|
@ -50,7 +52,7 @@ pub fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
|
|||
Some(expr)
|
||||
}
|
||||
|
||||
pub(crate) fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str {
|
||||
pub fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str {
|
||||
match left.kind() {
|
||||
L_PAREN | L_BRACK => return "",
|
||||
L_CURLY => {
|
|
@ -13,6 +13,7 @@ rustc-hash = "1.0"
|
|||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_text_edit = { path = "../ra_text_edit" }
|
||||
ra_fmt = { path = "../ra_fmt" }
|
||||
|
||||
[dev-dependencies]
|
||||
test_utils = { path = "../test_utils" }
|
||||
|
|
|
@ -5,10 +5,11 @@ use ra_syntax::{
|
|||
algo::find_covering_node,
|
||||
ast,
|
||||
};
|
||||
|
||||
use ra_fmt::{
|
||||
compute_ws, extract_trivial_expression
|
||||
};
|
||||
use crate::{
|
||||
LocalEdit, TextEditBuilder,
|
||||
formatting::{compute_ws, extract_trivial_expression},
|
||||
};
|
||||
|
||||
pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
//! This usually means functions which take syntax tree as an input and produce
|
||||
//! an edit or some auxiliary info.
|
||||
|
||||
pub mod formatting;
|
||||
mod extend_selection;
|
||||
mod folding_ranges;
|
||||
mod line_index;
|
||||
|
|
|
@ -4,8 +4,8 @@ use ra_syntax::{
|
|||
algo::{find_node_at_offset, find_leaf_at_offset, LeafAtOffset},
|
||||
ast::{self, AstToken},
|
||||
};
|
||||
|
||||
use crate::{LocalEdit, TextEditBuilder, formatting::leading_indent};
|
||||
use ra_fmt::leading_indent;
|
||||
use crate::{LocalEdit, TextEditBuilder};
|
||||
|
||||
pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> {
|
||||
let comment =
|
||||
|
|
Loading…
Reference in a new issue