diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-13 11:00:05 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-13 11:00:05 +0100 |
commit | 8870a5ea138bb4ba048140d90d728721c4b4ad4b (patch) | |
tree | e355901a2d197f2b7cceb35a732a111afed58198 | |
parent | b5cb16fb90b4a1076604c5795552ee4abe07a057 (diff) | |
parent | c81f6230da98fd3e3fa91c0896d65922a1ed4a24 (diff) |
Merge #5743
5743: Remove ra_fmt crate
r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | Cargo.lock | 10 | ||||
-rw-r--r-- | crates/ra_assists/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | 16 | ||||
-rw-r--r-- | crates/ra_assists/src/utils/insert_use.rs | 27 | ||||
-rw-r--r-- | crates/ra_fmt/Cargo.toml | 15 | ||||
-rw-r--r-- | crates/ra_fmt/src/lib.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_ide/src/typing.rs | 5 |
8 files changed, 32 insertions, 71 deletions
diff --git a/Cargo.lock b/Cargo.lock index 18c979b39..5f7b85b05 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -955,7 +955,6 @@ dependencies = [ | |||
955 | "itertools", | 955 | "itertools", |
956 | "profile", | 956 | "profile", |
957 | "ra_db", | 957 | "ra_db", |
958 | "ra_fmt", | ||
959 | "ra_hir", | 958 | "ra_hir", |
960 | "ra_ide_db", | 959 | "ra_ide_db", |
961 | "rustc-hash", | 960 | "rustc-hash", |
@@ -981,14 +980,6 @@ dependencies = [ | |||
981 | ] | 980 | ] |
982 | 981 | ||
983 | [[package]] | 982 | [[package]] |
984 | name = "ra_fmt" | ||
985 | version = "0.1.0" | ||
986 | dependencies = [ | ||
987 | "itertools", | ||
988 | "syntax", | ||
989 | ] | ||
990 | |||
991 | [[package]] | ||
992 | name = "ra_hir" | 983 | name = "ra_hir" |
993 | version = "0.1.0" | 984 | version = "0.1.0" |
994 | dependencies = [ | 985 | dependencies = [ |
@@ -1092,7 +1083,6 @@ dependencies = [ | |||
1092 | "profile", | 1083 | "profile", |
1093 | "ra_assists", | 1084 | "ra_assists", |
1094 | "ra_db", | 1085 | "ra_db", |
1095 | "ra_fmt", | ||
1096 | "ra_hir", | 1086 | "ra_hir", |
1097 | "ra_ide_db", | 1087 | "ra_ide_db", |
1098 | "ra_ssr", | 1088 | "ra_ssr", |
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index abc290463..83e44c124 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml | |||
@@ -17,7 +17,6 @@ stdx = { path = "../stdx" } | |||
17 | 17 | ||
18 | syntax = { path = "../syntax" } | 18 | syntax = { path = "../syntax" } |
19 | text_edit = { path = "../text_edit" } | 19 | text_edit = { path = "../text_edit" } |
20 | ra_fmt = { path = "../ra_fmt" } | ||
21 | profile = { path = "../profile" } | 20 | profile = { path = "../profile" } |
22 | ra_db = { path = "../ra_db" } | 21 | ra_db = { path = "../ra_db" } |
23 | ra_ide_db = { path = "../ra_ide_db" } | 22 | ra_ide_db = { path = "../ra_ide_db" } |
diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs index 6e9f2d0fc..497f887cd 100644 --- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -1,12 +1,11 @@ | |||
1 | use hir::{EnumVariant, Module, ModuleDef, Name}; | 1 | use hir::{EnumVariant, Module, ModuleDef, Name}; |
2 | use ra_db::FileId; | 2 | use ra_db::FileId; |
3 | use ra_fmt::leading_indent; | ||
4 | use ra_ide_db::{defs::Definition, search::Reference, RootDatabase}; | 3 | use ra_ide_db::{defs::Definition, search::Reference, RootDatabase}; |
5 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |
6 | use syntax::{ | 5 | use syntax::{ |
7 | algo::find_node_at_offset, | 6 | algo::find_node_at_offset, |
8 | ast::{self, ArgListOwner, AstNode, NameOwner, VisibilityOwner}, | 7 | ast::{self, edit::IndentLevel, ArgListOwner, AstNode, NameOwner, VisibilityOwner}, |
9 | SourceFile, SyntaxNode, TextRange, TextSize, | 8 | SourceFile, TextRange, TextSize, |
10 | }; | 9 | }; |
11 | 10 | ||
12 | use crate::{ | 11 | use crate::{ |
@@ -72,7 +71,7 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
72 | } | 71 | } |
73 | extract_struct_def( | 72 | extract_struct_def( |
74 | builder, | 73 | builder, |
75 | enum_ast.syntax(), | 74 | &enum_ast, |
76 | &variant_name, | 75 | &variant_name, |
77 | &field_list.to_string(), | 76 | &field_list.to_string(), |
78 | start_offset, | 77 | start_offset, |
@@ -112,9 +111,10 @@ fn insert_import( | |||
112 | Some(()) | 111 | Some(()) |
113 | } | 112 | } |
114 | 113 | ||
114 | // FIXME: this should use strongly-typed `make`, rather than string manipulation. | ||
115 | fn extract_struct_def( | 115 | fn extract_struct_def( |
116 | builder: &mut AssistBuilder, | 116 | builder: &mut AssistBuilder, |
117 | enum_ast: &SyntaxNode, | 117 | enum_: &ast::Enum, |
118 | variant_name: &str, | 118 | variant_name: &str, |
119 | variant_list: &str, | 119 | variant_list: &str, |
120 | start_offset: TextSize, | 120 | start_offset: TextSize, |
@@ -126,11 +126,7 @@ fn extract_struct_def( | |||
126 | } else { | 126 | } else { |
127 | "".to_string() | 127 | "".to_string() |
128 | }; | 128 | }; |
129 | let indent = if let Some(indent) = leading_indent(enum_ast) { | 129 | let indent = IndentLevel::from_node(enum_.syntax()); |
130 | indent.to_string() | ||
131 | } else { | ||
132 | "".to_string() | ||
133 | }; | ||
134 | let struct_def = format!( | 130 | let struct_def = format!( |
135 | r#"{}struct {}{}; | 131 | r#"{}struct {}{}; |
136 | 132 | ||
diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs index f89c288da..50a62ee82 100644 --- a/crates/ra_assists/src/utils/insert_use.rs +++ b/crates/ra_assists/src/utils/insert_use.rs | |||
@@ -2,13 +2,15 @@ | |||
2 | // FIXME: rewrite according to the plan, outlined in | 2 | // FIXME: rewrite according to the plan, outlined in |
3 | // https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553 | 3 | // https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553 |
4 | 4 | ||
5 | use std::iter::successors; | ||
6 | |||
5 | use either::Either; | 7 | use either::Either; |
6 | use hir::{self, ModPath}; | 8 | use hir::{self, ModPath}; |
7 | use syntax::{ | 9 | use syntax::{ |
8 | ast::{self, NameOwner, VisibilityOwner}, | 10 | ast::{self, NameOwner, VisibilityOwner}, |
9 | AstNode, Direction, SmolStr, | 11 | AstNode, AstToken, Direction, SmolStr, |
10 | SyntaxKind::{PATH, PATH_SEGMENT}, | 12 | SyntaxKind::{PATH, PATH_SEGMENT}, |
11 | SyntaxNode, T, | 13 | SyntaxNode, SyntaxToken, T, |
12 | }; | 14 | }; |
13 | use text_edit::TextEditBuilder; | 15 | use text_edit::TextEditBuilder; |
14 | 16 | ||
@@ -442,7 +444,7 @@ fn make_assist_add_new_use( | |||
442 | edit: &mut TextEditBuilder, | 444 | edit: &mut TextEditBuilder, |
443 | ) { | 445 | ) { |
444 | if let Some(anchor) = anchor { | 446 | if let Some(anchor) = anchor { |
445 | let indent = ra_fmt::leading_indent(anchor); | 447 | let indent = leading_indent(anchor); |
446 | let mut buf = String::new(); | 448 | let mut buf = String::new(); |
447 | if after { | 449 | if after { |
448 | buf.push_str("\n"); | 450 | buf.push_str("\n"); |
@@ -524,3 +526,22 @@ fn make_assist_add_nested_import( | |||
524 | edit.insert(end, "}".to_string()); | 526 | edit.insert(end, "}".to_string()); |
525 | } | 527 | } |
526 | } | 528 | } |
529 | |||
530 | /// If the node is on the beginning of the line, calculate indent. | ||
531 | fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> { | ||
532 | for token in prev_tokens(node.first_token()?) { | ||
533 | if let Some(ws) = ast::Whitespace::cast(token.clone()) { | ||
534 | let ws_text = ws.text(); | ||
535 | if let Some(pos) = ws_text.rfind('\n') { | ||
536 | return Some(ws_text[pos + 1..].into()); | ||
537 | } | ||
538 | } | ||
539 | if token.text().contains('\n') { | ||
540 | break; | ||
541 | } | ||
542 | } | ||
543 | return None; | ||
544 | fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> { | ||
545 | successors(token.prev_token(), |token| token.prev_token()) | ||
546 | } | ||
547 | } | ||
diff --git a/crates/ra_fmt/Cargo.toml b/crates/ra_fmt/Cargo.toml deleted file mode 100644 index d42ca62be..000000000 --- a/crates/ra_fmt/Cargo.toml +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_fmt" | ||
4 | version = "0.1.0" | ||
5 | authors = ["rust-analyzer developers"] | ||
6 | publish = false | ||
7 | license = "MIT OR Apache-2.0" | ||
8 | |||
9 | [lib] | ||
10 | doctest = false | ||
11 | |||
12 | [dependencies] | ||
13 | itertools = "0.9.0" | ||
14 | |||
15 | syntax = { path = "../syntax" } | ||
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs deleted file mode 100644 index b92477f9e..000000000 --- a/crates/ra_fmt/src/lib.rs +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | //! This crate provides some utilities for indenting rust code. | ||
2 | |||
3 | use std::iter::successors; | ||
4 | |||
5 | use syntax::{ | ||
6 | ast::{self, AstToken}, | ||
7 | SmolStr, SyntaxNode, SyntaxToken, | ||
8 | }; | ||
9 | |||
10 | /// If the node is on the beginning of the line, calculate indent. | ||
11 | pub fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> { | ||
12 | for token in prev_tokens(node.first_token()?) { | ||
13 | if let Some(ws) = ast::Whitespace::cast(token.clone()) { | ||
14 | let ws_text = ws.text(); | ||
15 | if let Some(pos) = ws_text.rfind('\n') { | ||
16 | return Some(ws_text[pos + 1..].into()); | ||
17 | } | ||
18 | } | ||
19 | if token.text().contains('\n') { | ||
20 | break; | ||
21 | } | ||
22 | } | ||
23 | None | ||
24 | } | ||
25 | |||
26 | fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> { | ||
27 | successors(token.prev_token(), |token| token.prev_token()) | ||
28 | } | ||
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index c60e55545..938398a41 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml | |||
@@ -26,7 +26,6 @@ text_edit = { path = "../text_edit" } | |||
26 | ra_db = { path = "../ra_db" } | 26 | ra_db = { path = "../ra_db" } |
27 | ra_ide_db = { path = "../ra_ide_db" } | 27 | ra_ide_db = { path = "../ra_ide_db" } |
28 | cfg = { path = "../cfg" } | 28 | cfg = { path = "../cfg" } |
29 | ra_fmt = { path = "../ra_fmt" } | ||
30 | profile = { path = "../profile" } | 29 | profile = { path = "../profile" } |
31 | test_utils = { path = "../test_utils" } | 30 | test_utils = { path = "../test_utils" } |
32 | ra_assists = { path = "../ra_assists" } | 31 | ra_assists = { path = "../ra_assists" } |
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index c408b1d52..7897c57b7 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs | |||
@@ -16,11 +16,10 @@ | |||
16 | mod on_enter; | 16 | mod on_enter; |
17 | 17 | ||
18 | use ra_db::{FilePosition, SourceDatabase}; | 18 | use ra_db::{FilePosition, SourceDatabase}; |
19 | use ra_fmt::leading_indent; | ||
20 | use ra_ide_db::{source_change::SourceFileEdit, RootDatabase}; | 19 | use ra_ide_db::{source_change::SourceFileEdit, RootDatabase}; |
21 | use syntax::{ | 20 | use syntax::{ |
22 | algo::find_node_at_offset, | 21 | algo::find_node_at_offset, |
23 | ast::{self, AstToken}, | 22 | ast::{self, edit::IndentLevel, AstToken}, |
24 | AstNode, SourceFile, | 23 | AstNode, SourceFile, |
25 | SyntaxKind::{FIELD_EXPR, METHOD_CALL_EXPR}, | 24 | SyntaxKind::{FIELD_EXPR, METHOD_CALL_EXPR}, |
26 | TextRange, TextSize, | 25 | TextRange, TextSize, |
@@ -104,7 +103,7 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> { | |||
104 | if !matches!(parent.kind(), FIELD_EXPR | METHOD_CALL_EXPR) { | 103 | if !matches!(parent.kind(), FIELD_EXPR | METHOD_CALL_EXPR) { |
105 | return None; | 104 | return None; |
106 | } | 105 | } |
107 | let prev_indent = leading_indent(&parent)?; | 106 | let prev_indent = IndentLevel::from_node(&parent); |
108 | let target_indent = format!(" {}", prev_indent); | 107 | let target_indent = format!(" {}", prev_indent); |
109 | let target_indent_len = TextSize::of(&target_indent); | 108 | let target_indent_len = TextSize::of(&target_indent); |
110 | if current_indent_len == target_indent_len { | 109 | if current_indent_len == target_indent_len { |