]> git.lizzy.rs Git - rust.git/commitdiff
Remove ra_fmt crate
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 13 Aug 2020 09:56:11 +0000 (11:56 +0200)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 13 Aug 2020 09:59:42 +0000 (11:59 +0200)
Cargo.lock
crates/ra_assists/Cargo.toml
crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
crates/ra_assists/src/utils/insert_use.rs
crates/ra_fmt/Cargo.toml [deleted file]
crates/ra_fmt/src/lib.rs [deleted file]
crates/ra_ide/Cargo.toml
crates/ra_ide/src/typing.rs

index 18c979b39e59fd513cf6ba3285542c8629e075bf..5f7b85b0593eff879f9e3af45f254d4ac45d9d79 100644 (file)
@@ -955,7 +955,6 @@ dependencies = [
  "itertools",
  "profile",
  "ra_db",
- "ra_fmt",
  "ra_hir",
  "ra_ide_db",
  "rustc-hash",
@@ -980,14 +979,6 @@ dependencies = [
  "vfs",
 ]
 
-[[package]]
-name = "ra_fmt"
-version = "0.1.0"
-dependencies = [
- "itertools",
- "syntax",
-]
-
 [[package]]
 name = "ra_hir"
 version = "0.1.0"
@@ -1092,7 +1083,6 @@ dependencies = [
  "profile",
  "ra_assists",
  "ra_db",
- "ra_fmt",
  "ra_hir",
  "ra_ide_db",
  "ra_ssr",
index abc290463a4d66c5f864a2c43ad3f30c8b850917..83e44c124365dd7bbb3a95808e833cb05a052eb7 100644 (file)
@@ -17,7 +17,6 @@ stdx = { path = "../stdx" }
 
 syntax = { path = "../syntax" }
 text_edit = { path = "../text_edit" }
-ra_fmt = { path = "../ra_fmt" }
 profile = { path = "../profile" }
 ra_db = { path = "../ra_db" }
 ra_ide_db = { path = "../ra_ide_db" }
index b4e19b3dc7aeabf59209341d9b86ad5ab99e5e65..497f887cd1deb85503a060fd6e477c1253a47758 100644 (file)
@@ -1,11 +1,10 @@
 use hir::{EnumVariant, Module, ModuleDef, Name};
 use ra_db::FileId;
-use ra_fmt::leading_indent;
 use ra_ide_db::{defs::Definition, search::Reference, RootDatabase};
 use rustc_hash::FxHashSet;
 use syntax::{
     algo::find_node_at_offset,
-    ast::{self, ArgListOwner, AstNode, NameOwner, VisibilityOwner},
+    ast::{self, edit::IndentLevel, ArgListOwner, AstNode, NameOwner, VisibilityOwner},
     SourceFile, TextRange, TextSize,
 };
 
@@ -112,7 +111,7 @@ fn insert_import(
     Some(())
 }
 
-// FIXME: this should use strongly-typed `make`, rather than string manipulation1
+// FIXME: this should use strongly-typed `make`, rather than string manipulation.
 fn extract_struct_def(
     builder: &mut AssistBuilder,
     enum_: &ast::Enum,
@@ -127,11 +126,7 @@ fn extract_struct_def(
     } else {
         "".to_string()
     };
-    let indent = if let Some(indent) = leading_indent(enum_.syntax()) {
-        indent.to_string()
-    } else {
-        "".to_string()
-    };
+    let indent = IndentLevel::from_node(enum_.syntax());
     let struct_def = format!(
         r#"{}struct {}{};
 
index f89c288da45892088c05552dccad3df7e3486bff..50a62ee8296b2e10d5c7102ef93aa36e416502b3 100644 (file)
@@ -2,13 +2,15 @@
 // FIXME: rewrite according to the plan, outlined in
 // https://github.com/rust-analyzer/rust-analyzer/issues/3301#issuecomment-592931553
 
+use std::iter::successors;
+
 use either::Either;
 use hir::{self, ModPath};
 use syntax::{
     ast::{self, NameOwner, VisibilityOwner},
-    AstNode, Direction, SmolStr,
+    AstNode, AstToken, Direction, SmolStr,
     SyntaxKind::{PATH, PATH_SEGMENT},
-    SyntaxNode, T,
+    SyntaxNode, SyntaxToken, T,
 };
 use text_edit::TextEditBuilder;
 
@@ -442,7 +444,7 @@ fn make_assist_add_new_use(
     edit: &mut TextEditBuilder,
 ) {
     if let Some(anchor) = anchor {
-        let indent = ra_fmt::leading_indent(anchor);
+        let indent = leading_indent(anchor);
         let mut buf = String::new();
         if after {
             buf.push_str("\n");
@@ -524,3 +526,22 @@ fn make_assist_add_nested_import(
         edit.insert(end, "}".to_string());
     }
 }
+
+/// If the node is on the beginning of the line, calculate indent.
+fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> {
+    for token in prev_tokens(node.first_token()?) {
+        if let Some(ws) = ast::Whitespace::cast(token.clone()) {
+            let ws_text = ws.text();
+            if let Some(pos) = ws_text.rfind('\n') {
+                return Some(ws_text[pos + 1..].into());
+            }
+        }
+        if token.text().contains('\n') {
+            break;
+        }
+    }
+    return None;
+    fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
+        successors(token.prev_token(), |token| token.prev_token())
+    }
+}
diff --git a/crates/ra_fmt/Cargo.toml b/crates/ra_fmt/Cargo.toml
deleted file mode 100644 (file)
index d42ca62..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-[package]
-edition = "2018"
-name = "ra_fmt"
-version = "0.1.0"
-authors = ["rust-analyzer developers"]
-publish = false
-license = "MIT OR Apache-2.0"
-
-[lib]
-doctest = false
-
-[dependencies]
-itertools = "0.9.0"
-
-syntax = { path = "../syntax" }
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs
deleted file mode 100644 (file)
index b92477f..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//! This crate provides some utilities for indenting rust code.
-
-use std::iter::successors;
-
-use syntax::{
-    ast::{self, AstToken},
-    SmolStr, SyntaxNode, SyntaxToken,
-};
-
-/// If the node is on the beginning of the line, calculate indent.
-pub fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> {
-    for token in prev_tokens(node.first_token()?) {
-        if let Some(ws) = ast::Whitespace::cast(token.clone()) {
-            let ws_text = ws.text();
-            if let Some(pos) = ws_text.rfind('\n') {
-                return Some(ws_text[pos + 1..].into());
-            }
-        }
-        if token.text().contains('\n') {
-            break;
-        }
-    }
-    None
-}
-
-fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
-    successors(token.prev_token(), |token| token.prev_token())
-}
index c60e555455e1e3f8141e67f92e84f163f7821700..938398a41a277f957f295973b4a03a0b9ad8afad 100644 (file)
@@ -26,7 +26,6 @@ text_edit = { path = "../text_edit" }
 ra_db = { path = "../ra_db" }
 ra_ide_db = { path = "../ra_ide_db" }
 cfg = { path = "../cfg" }
-ra_fmt = { path = "../ra_fmt" }
 profile = { path = "../profile" }
 test_utils = { path = "../test_utils" }
 ra_assists = { path = "../ra_assists" }
index c408b1d52187d12f4526da1429d7e7be01f5389b..7897c57b77b7312016eb67bb7d4df7b00db39365 100644 (file)
 mod on_enter;
 
 use ra_db::{FilePosition, SourceDatabase};
-use ra_fmt::leading_indent;
 use ra_ide_db::{source_change::SourceFileEdit, RootDatabase};
 use syntax::{
     algo::find_node_at_offset,
-    ast::{self, AstToken},
+    ast::{self, edit::IndentLevel, AstToken},
     AstNode, SourceFile,
     SyntaxKind::{FIELD_EXPR, METHOD_CALL_EXPR},
     TextRange, TextSize,
@@ -104,7 +103,7 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
     if !matches!(parent.kind(), FIELD_EXPR | METHOD_CALL_EXPR) {
         return None;
     }
-    let prev_indent = leading_indent(&parent)?;
+    let prev_indent = IndentLevel::from_node(&parent);
     let target_indent = format!("    {}", prev_indent);
     let target_indent_len = TextSize::of(&target_indent);
     if current_indent_len == target_indent_len {