From 6a77ec7bbe6ddbf663dce9529d11d1bb56c5489a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:35:29 +0200 Subject: [PATCH 1/4] Rename ra_hir_ty -> hir_ty --- Cargo.lock | 60 +++++++++---------- crates/{ra_hir_ty => hir_ty}/Cargo.toml | 23 ++++--- crates/{ra_hir_ty => hir_ty}/src/autoderef.rs | 0 crates/{ra_hir_ty => hir_ty}/src/db.rs | 0 .../{ra_hir_ty => hir_ty}/src/diagnostics.rs | 0 .../src/diagnostics/expr.rs | 0 .../src/diagnostics/match_check.rs | 0 .../src/diagnostics/unsafe_check.rs | 0 crates/{ra_hir_ty => hir_ty}/src/display.rs | 0 crates/{ra_hir_ty => hir_ty}/src/infer.rs | 0 .../{ra_hir_ty => hir_ty}/src/infer/coerce.rs | 0 .../{ra_hir_ty => hir_ty}/src/infer/expr.rs | 0 crates/{ra_hir_ty => hir_ty}/src/infer/pat.rs | 0 .../{ra_hir_ty => hir_ty}/src/infer/path.rs | 0 .../{ra_hir_ty => hir_ty}/src/infer/unify.rs | 0 crates/{ra_hir_ty => hir_ty}/src/lib.rs | 0 crates/{ra_hir_ty => hir_ty}/src/lower.rs | 0 .../src/method_resolution.rs | 0 crates/{ra_hir_ty => hir_ty}/src/op.rs | 0 crates/{ra_hir_ty => hir_ty}/src/primitive.rs | 0 crates/{ra_hir_ty => hir_ty}/src/test_db.rs | 0 crates/{ra_hir_ty => hir_ty}/src/tests.rs | 2 +- .../src/tests/coercion.rs | 0 .../src/tests/display_source_code.rs | 0 .../{ra_hir_ty => hir_ty}/src/tests/macros.rs | 0 .../src/tests/method_resolution.rs | 0 .../src/tests/never_type.rs | 0 .../src/tests/patterns.rs | 0 .../src/tests/regression.rs | 0 .../{ra_hir_ty => hir_ty}/src/tests/simple.rs | 0 .../{ra_hir_ty => hir_ty}/src/tests/traits.rs | 0 crates/{ra_hir_ty => hir_ty}/src/traits.rs | 0 .../{ra_hir_ty => hir_ty}/src/traits/chalk.rs | 0 .../src/traits/chalk/interner.rs | 0 .../src/traits/chalk/mapping.rs | 0 .../src/traits/chalk/tls.rs | 0 crates/{ra_hir_ty => hir_ty}/src/utils.rs | 0 crates/ra_hir/Cargo.toml | 2 +- crates/rust-analyzer/Cargo.toml | 2 +- xtask/tests/tidy.rs | 2 +- 40 files changed, 44 insertions(+), 47 deletions(-) rename crates/{ra_hir_ty => hir_ty}/Cargo.toml (95%) rename crates/{ra_hir_ty => hir_ty}/src/autoderef.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/db.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/diagnostics.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/diagnostics/expr.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/diagnostics/match_check.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/diagnostics/unsafe_check.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/display.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/infer.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/infer/coerce.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/infer/expr.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/infer/pat.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/infer/path.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/infer/unify.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/lib.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/lower.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/method_resolution.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/op.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/primitive.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/test_db.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests.rs (99%) rename crates/{ra_hir_ty => hir_ty}/src/tests/coercion.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/display_source_code.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/macros.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/method_resolution.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/never_type.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/patterns.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/regression.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/simple.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/tests/traits.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/traits.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/traits/chalk.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/traits/chalk/interner.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/traits/chalk/mapping.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/traits/chalk/tls.rs (100%) rename crates/{ra_hir_ty => hir_ty}/src/utils.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 702bd5191d77..6ecea36470e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,6 +507,34 @@ dependencies = [ "tt", ] +[[package]] +name = "hir_ty" +version = "0.0.0" +dependencies = [ + "arena", + "arrayvec", + "base_db", + "chalk-ir", + "chalk-recursive", + "chalk-solve", + "ena", + "expect", + "hir_def", + "hir_expand", + "itertools", + "log", + "profile", + "rustc-hash", + "scoped-tls", + "smallvec", + "stdx", + "syntax", + "test_utils", + "tracing", + "tracing-subscriber", + "tracing-tree", +] + [[package]] name = "home" version = "0.5.3" @@ -1063,41 +1091,13 @@ dependencies = [ "either", "hir_def", "hir_expand", - "itertools", - "log", - "profile", - "ra_hir_ty", - "rustc-hash", - "stdx", - "syntax", -] - -[[package]] -name = "ra_hir_ty" -version = "0.1.0" -dependencies = [ - "arena", - "arrayvec", - "base_db", - "chalk-ir", - "chalk-recursive", - "chalk-solve", - "ena", - "expect", - "hir_def", - "hir_expand", + "hir_ty", "itertools", "log", "profile", "rustc-hash", - "scoped-tls", - "smallvec", "stdx", "syntax", - "test_utils", - "tracing", - "tracing-subscriber", - "tracing-tree", ] [[package]] @@ -1237,6 +1237,7 @@ dependencies = [ "expect", "flycheck", "hir_def", + "hir_ty", "itertools", "jod-thread", "log", @@ -1251,7 +1252,6 @@ dependencies = [ "profile", "project_model", "ra_hir", - "ra_hir_ty", "ra_ide", "ra_ide_db", "ra_ssr", diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml similarity index 95% rename from crates/ra_hir_ty/Cargo.toml rename to crates/hir_ty/Cargo.toml index d430b08ca7e2..83b5013a9021 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml @@ -1,9 +1,9 @@ [package] -edition = "2018" -name = "ra_hir_ty" -version = "0.1.0" -authors = ["rust-analyzer developers"] +name = "hir_ty" +version = "0.0.0" license = "MIT OR Apache-2.0" +authors = ["rust-analyzer developers"] +edition = "2018" [lib] doctest = false @@ -15,9 +15,12 @@ smallvec = "1.2.0" ena = "0.14.0" log = "0.4.8" rustc-hash = "1.1.0" +scoped-tls = "1" +chalk-solve = { version = "0.21.0" } +chalk-ir = { version = "0.21.0" } +chalk-recursive = { version = "0.21.0" } stdx = { path = "../stdx" } - hir_def = { path = "../hir_def" } hir_expand = { path = "../hir_expand" } arena = { path = "../arena" } @@ -26,15 +29,9 @@ profile = { path = "../profile" } syntax = { path = "../syntax" } test_utils = { path = "../test_utils" } -scoped-tls = "1" - -chalk-solve = { version = "0.21.0" } -chalk-ir = { version = "0.21.0" } -chalk-recursive = { version = "0.21.0" } - [dev-dependencies] -expect = { path = "../expect" } - tracing = "0.1" tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } tracing-tree = { version = "0.1.4" } + +expect = { path = "../expect" } diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs similarity index 100% rename from crates/ra_hir_ty/src/autoderef.rs rename to crates/hir_ty/src/autoderef.rs diff --git a/crates/ra_hir_ty/src/db.rs b/crates/hir_ty/src/db.rs similarity index 100% rename from crates/ra_hir_ty/src/db.rs rename to crates/hir_ty/src/db.rs diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/hir_ty/src/diagnostics.rs similarity index 100% rename from crates/ra_hir_ty/src/diagnostics.rs rename to crates/hir_ty/src/diagnostics.rs diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs similarity index 100% rename from crates/ra_hir_ty/src/diagnostics/expr.rs rename to crates/hir_ty/src/diagnostics/expr.rs diff --git a/crates/ra_hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs similarity index 100% rename from crates/ra_hir_ty/src/diagnostics/match_check.rs rename to crates/hir_ty/src/diagnostics/match_check.rs diff --git a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs similarity index 100% rename from crates/ra_hir_ty/src/diagnostics/unsafe_check.rs rename to crates/hir_ty/src/diagnostics/unsafe_check.rs diff --git a/crates/ra_hir_ty/src/display.rs b/crates/hir_ty/src/display.rs similarity index 100% rename from crates/ra_hir_ty/src/display.rs rename to crates/hir_ty/src/display.rs diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs similarity index 100% rename from crates/ra_hir_ty/src/infer.rs rename to crates/hir_ty/src/infer.rs diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs similarity index 100% rename from crates/ra_hir_ty/src/infer/coerce.rs rename to crates/hir_ty/src/infer/coerce.rs diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs similarity index 100% rename from crates/ra_hir_ty/src/infer/expr.rs rename to crates/hir_ty/src/infer/expr.rs diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs similarity index 100% rename from crates/ra_hir_ty/src/infer/pat.rs rename to crates/hir_ty/src/infer/pat.rs diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs similarity index 100% rename from crates/ra_hir_ty/src/infer/path.rs rename to crates/hir_ty/src/infer/path.rs diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs similarity index 100% rename from crates/ra_hir_ty/src/infer/unify.rs rename to crates/hir_ty/src/infer/unify.rs diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs similarity index 100% rename from crates/ra_hir_ty/src/lib.rs rename to crates/hir_ty/src/lib.rs diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs similarity index 100% rename from crates/ra_hir_ty/src/lower.rs rename to crates/hir_ty/src/lower.rs diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs similarity index 100% rename from crates/ra_hir_ty/src/method_resolution.rs rename to crates/hir_ty/src/method_resolution.rs diff --git a/crates/ra_hir_ty/src/op.rs b/crates/hir_ty/src/op.rs similarity index 100% rename from crates/ra_hir_ty/src/op.rs rename to crates/hir_ty/src/op.rs diff --git a/crates/ra_hir_ty/src/primitive.rs b/crates/hir_ty/src/primitive.rs similarity index 100% rename from crates/ra_hir_ty/src/primitive.rs rename to crates/hir_ty/src/primitive.rs diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs similarity index 100% rename from crates/ra_hir_ty/src/test_db.rs rename to crates/hir_ty/src/test_db.rs diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs similarity index 99% rename from crates/ra_hir_ty/src/tests.rs rename to crates/hir_ty/src/tests.rs index f6b172c3afe7..c953925ecb58 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs @@ -35,7 +35,7 @@ use crate::{ // These tests compare the inference results for all expressions in a file // against snapshots of the expected results using expect. Use -// `env UPDATE_EXPECT=1 cargo test -p ra_hir_ty` to update the snapshots. +// `env UPDATE_EXPECT=1 cargo test -p hir_ty` to update the snapshots. fn setup_tracing() -> tracing::subscriber::DefaultGuard { use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/coercion.rs rename to crates/hir_ty/src/tests/coercion.rs diff --git a/crates/ra_hir_ty/src/tests/display_source_code.rs b/crates/hir_ty/src/tests/display_source_code.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/display_source_code.rs rename to crates/hir_ty/src/tests/display_source_code.rs diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/macros.rs rename to crates/hir_ty/src/tests/macros.rs diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/method_resolution.rs rename to crates/hir_ty/src/tests/method_resolution.rs diff --git a/crates/ra_hir_ty/src/tests/never_type.rs b/crates/hir_ty/src/tests/never_type.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/never_type.rs rename to crates/hir_ty/src/tests/never_type.rs diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/patterns.rs rename to crates/hir_ty/src/tests/patterns.rs diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/regression.rs rename to crates/hir_ty/src/tests/regression.rs diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/simple.rs rename to crates/hir_ty/src/tests/simple.rs diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs similarity index 100% rename from crates/ra_hir_ty/src/tests/traits.rs rename to crates/hir_ty/src/tests/traits.rs diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs similarity index 100% rename from crates/ra_hir_ty/src/traits.rs rename to crates/hir_ty/src/traits.rs diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs similarity index 100% rename from crates/ra_hir_ty/src/traits/chalk.rs rename to crates/hir_ty/src/traits/chalk.rs diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs similarity index 100% rename from crates/ra_hir_ty/src/traits/chalk/interner.rs rename to crates/hir_ty/src/traits/chalk/interner.rs diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs similarity index 100% rename from crates/ra_hir_ty/src/traits/chalk/mapping.rs rename to crates/hir_ty/src/traits/chalk/mapping.rs diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/traits/chalk/tls.rs similarity index 100% rename from crates/ra_hir_ty/src/traits/chalk/tls.rs rename to crates/hir_ty/src/traits/chalk/tls.rs diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs similarity index 100% rename from crates/ra_hir_ty/src/utils.rs rename to crates/hir_ty/src/utils.rs diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index edca5dc6f81e..61cc099ac71d 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml @@ -22,4 +22,4 @@ base_db = { path = "../base_db" } profile = { path = "../profile" } hir_expand = { path = "../hir_expand" } hir_def = { path = "../hir_def" } -hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } +hir_ty = { path = "../hir_ty" } diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 0dee719de559..e17fe47daeb1 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -51,7 +51,7 @@ ra_ide_db = { path = "../ra_ide_db" } ra_ssr = { path = "../ra_ssr" } hir = { path = "../ra_hir", package = "ra_hir" } hir_def = { path = "../hir_def" } -hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } +hir_ty = { path = "../hir_ty" } proc_macro_srv = { path = "../proc_macro_srv" } [target.'cfg(windows)'.dependencies] diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index dc367d1e03a2..5a5bd4a3ee34 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -201,7 +201,7 @@ impl TidyDocs { "project_model", "syntax", "tt", - "ra_hir_ty", + "hir_ty", ]; let mut has_fixmes = From ae71a631fd657368e8593feb5e025d23147afe60 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:36:55 +0200 Subject: [PATCH 2/4] Rename ra_hir -> hir --- Cargo.lock | 46 +++++++++---------- crates/{ra_hir => hir}/Cargo.toml | 9 ++-- crates/{ra_hir => hir}/src/code_model.rs | 0 crates/{ra_hir => hir}/src/db.rs | 0 crates/{ra_hir => hir}/src/diagnostics.rs | 0 crates/{ra_hir => hir}/src/from_id.rs | 0 crates/{ra_hir => hir}/src/has_source.rs | 0 crates/{ra_hir => hir}/src/lib.rs | 4 +- crates/{ra_hir => hir}/src/semantics.rs | 0 .../src/semantics/source_to_def.rs | 0 crates/{ra_hir => hir}/src/source_analyzer.rs | 0 crates/ra_assists/Cargo.toml | 2 +- crates/ra_ide/Cargo.toml | 2 +- crates/ra_ide/src/lib.rs | 2 +- crates/ra_ide_db/Cargo.toml | 2 +- crates/ra_ssr/Cargo.toml | 2 +- crates/rust-analyzer/Cargo.toml | 2 +- docs/dev/README.md | 6 +-- docs/dev/architecture.md | 6 +-- docs/dev/guide.md | 38 +++++++-------- xtask/tests/tidy.rs | 2 +- 21 files changed, 61 insertions(+), 62 deletions(-) rename crates/{ra_hir => hir}/Cargo.toml (92%) rename crates/{ra_hir => hir}/src/code_model.rs (100%) rename crates/{ra_hir => hir}/src/db.rs (100%) rename crates/{ra_hir => hir}/src/diagnostics.rs (100%) rename crates/{ra_hir => hir}/src/from_id.rs (100%) rename crates/{ra_hir => hir}/src/has_source.rs (100%) rename crates/{ra_hir => hir}/src/lib.rs (92%) rename crates/{ra_hir => hir}/src/semantics.rs (100%) rename crates/{ra_hir => hir}/src/semantics/source_to_def.rs (100%) rename crates/{ra_hir => hir}/src/source_analyzer.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 6ecea36470e0..ae71ea9fdbde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -463,6 +463,24 @@ dependencies = [ "libc", ] +[[package]] +name = "hir" +version = "0.0.0" +dependencies = [ + "arrayvec", + "base_db", + "either", + "hir_def", + "hir_expand", + "hir_ty", + "itertools", + "log", + "profile", + "rustc-hash", + "stdx", + "syntax", +] + [[package]] name = "hir_def" version = "0.0.0" @@ -1071,9 +1089,9 @@ version = "0.1.0" dependencies = [ "base_db", "either", + "hir", "itertools", "profile", - "ra_hir", "ra_ide_db", "rustc-hash", "stdx", @@ -1082,24 +1100,6 @@ dependencies = [ "text_edit", ] -[[package]] -name = "ra_hir" -version = "0.1.0" -dependencies = [ - "arrayvec", - "base_db", - "either", - "hir_def", - "hir_expand", - "hir_ty", - "itertools", - "log", - "profile", - "rustc-hash", - "stdx", - "syntax", -] - [[package]] name = "ra_ide" version = "0.1.0" @@ -1108,13 +1108,13 @@ dependencies = [ "cfg", "either", "expect", + "hir", "indexmap", "itertools", "log", "oorandom", "profile", "ra_assists", - "ra_hir", "ra_ide_db", "ra_ssr", "rustc-hash", @@ -1131,10 +1131,10 @@ dependencies = [ "base_db", "either", "fst", + "hir", "log", "once_cell", "profile", - "ra_hir", "rayon", "rustc-hash", "stdx", @@ -1149,7 +1149,7 @@ version = "0.1.0" dependencies = [ "base_db", "expect", - "ra_hir", + "hir", "ra_ide_db", "rustc-hash", "syntax", @@ -1236,6 +1236,7 @@ dependencies = [ "env_logger", "expect", "flycheck", + "hir", "hir_def", "hir_ty", "itertools", @@ -1251,7 +1252,6 @@ dependencies = [ "proc_macro_srv", "profile", "project_model", - "ra_hir", "ra_ide", "ra_ide_db", "ra_ssr", diff --git a/crates/ra_hir/Cargo.toml b/crates/hir/Cargo.toml similarity index 92% rename from crates/ra_hir/Cargo.toml rename to crates/hir/Cargo.toml index 61cc099ac71d..dbb2986b6007 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/hir/Cargo.toml @@ -1,9 +1,9 @@ [package] -edition = "2018" -name = "ra_hir" -version = "0.1.0" -authors = ["rust-analyzer developers"] +name = "hir" +version = "0.0.0" license = "MIT OR Apache-2.0" +authors = ["rust-analyzer developers"] +edition = "2018" [lib] doctest = false @@ -13,7 +13,6 @@ log = "0.4.8" rustc-hash = "1.1.0" either = "1.5.3" arrayvec = "0.5.1" - itertools = "0.9.0" stdx = { path = "../stdx" } diff --git a/crates/ra_hir/src/code_model.rs b/crates/hir/src/code_model.rs similarity index 100% rename from crates/ra_hir/src/code_model.rs rename to crates/hir/src/code_model.rs diff --git a/crates/ra_hir/src/db.rs b/crates/hir/src/db.rs similarity index 100% rename from crates/ra_hir/src/db.rs rename to crates/hir/src/db.rs diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs similarity index 100% rename from crates/ra_hir/src/diagnostics.rs rename to crates/hir/src/diagnostics.rs diff --git a/crates/ra_hir/src/from_id.rs b/crates/hir/src/from_id.rs similarity index 100% rename from crates/ra_hir/src/from_id.rs rename to crates/hir/src/from_id.rs diff --git a/crates/ra_hir/src/has_source.rs b/crates/hir/src/has_source.rs similarity index 100% rename from crates/ra_hir/src/has_source.rs rename to crates/hir/src/has_source.rs diff --git a/crates/ra_hir/src/lib.rs b/crates/hir/src/lib.rs similarity index 92% rename from crates/ra_hir/src/lib.rs rename to crates/hir/src/lib.rs index 34b02c5365f9..24a0f6b4b184 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -9,11 +9,11 @@ //! It is written in "OO" style. Each type is self contained (as in, it knows it's //! parents and full context). It should be "clean code". //! -//! `ra_hir_*` crates are the implementation of the compiler logic. +//! `hir_*` crates are the implementation of the compiler logic. //! They are written in "ECS" style, with relatively little abstractions. //! Many types are not self-contained, and explicitly use local indexes, arenas, etc. //! -//! `ra_hir` is what insulates the "we don't know how to actually write an incremental compiler" +//! `hir` is what insulates the "we don't know how to actually write an incremental compiler" //! from the ide with completions, hovers, etc. It is a (soft, internal) boundary: //! https://www.tedinski.com/2018/02/06/system-boundaries.html. diff --git a/crates/ra_hir/src/semantics.rs b/crates/hir/src/semantics.rs similarity index 100% rename from crates/ra_hir/src/semantics.rs rename to crates/hir/src/semantics.rs diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs similarity index 100% rename from crates/ra_hir/src/semantics/source_to_def.rs rename to crates/hir/src/semantics/source_to_def.rs diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs similarity index 100% rename from crates/ra_hir/src/source_analyzer.rs rename to crates/hir/src/source_analyzer.rs diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index ebac09be6261..cacc063da2b3 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -20,5 +20,5 @@ text_edit = { path = "../text_edit" } profile = { path = "../profile" } base_db = { path = "../base_db" } ra_ide_db = { path = "../ra_ide_db" } -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } test_utils = { path = "../test_utils" } diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 1af51f3ae8f7..a701cdf1d502 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml @@ -33,7 +33,7 @@ ra_ssr = { path = "../ra_ssr" } # ra_ide should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } [dev-dependencies] expect = { path = "../expect" } diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 789fbdaf232e..0d14c823aef2 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -3,7 +3,7 @@ //! Strings, suitable for displaying to the human. //! //! What powers this API are the `RootDatabase` struct, which defines a `salsa` -//! database, and the `ra_hir` crate, where majority of the analysis happens. +//! database, and the `hir` crate, where majority of the analysis happens. //! However, IDE specific bits of the analysis (most notably completion) happen //! in this crate. diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml index 0cda7090d3f7..eda257a3a8b3 100644 --- a/crates/ra_ide_db/Cargo.toml +++ b/crates/ra_ide_db/Cargo.toml @@ -29,4 +29,4 @@ test_utils = { path = "../test_utils" } # ra_ide should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } diff --git a/crates/ra_ssr/Cargo.toml b/crates/ra_ssr/Cargo.toml index f290939cfbdd..bed4bbdf19cf 100644 --- a/crates/ra_ssr/Cargo.toml +++ b/crates/ra_ssr/Cargo.toml @@ -15,7 +15,7 @@ text_edit = { path = "../text_edit" } syntax = { path = "../syntax" } base_db = { path = "../base_db" } ra_ide_db = { path = "../ra_ide_db" } -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } rustc-hash = "1.1.0" test_utils = { path = "../test_utils" } diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index e17fe47daeb1..c0257e9c8970 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -49,7 +49,7 @@ toolchain = { path = "../toolchain" } base_db = { path = "../base_db" } ra_ide_db = { path = "../ra_ide_db" } ra_ssr = { path = "../ra_ssr" } -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } hir_def = { path = "../hir_def" } hir_ty = { path = "../hir_ty" } proc_macro_srv = { path = "../proc_macro_srv" } diff --git a/docs/dev/README.md b/docs/dev/README.md index 4aab6e2b86a8..04bebbfca5c9 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md @@ -148,14 +148,14 @@ Internal representations are lowered to LSP in the `rust-analyzer` crate (the on ## IDE/Compiler split -There's a semi-hard split between "compiler" and "IDE", at the `ra_hir` crate. +There's a semi-hard split between "compiler" and "IDE", at the `hir` crate. Compiler derives new facts about source code. It explicitly acknowledges that not all info is available (i.e. you can't look at types during name resolution). IDE assumes that all information is available at all times. -IDE should use only types from `ra_hir`, and should not depend on the underling compiler types. -`ra_hir` is a facade. +IDE should use only types from `hir`, and should not depend on the underling compiler types. +`hir` is a facade. ## IDE API diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md index 746d41f83ced..0ffe61026ac0 100644 --- a/docs/dev/architecture.md +++ b/docs/dev/architecture.md @@ -102,7 +102,7 @@ defines most of the "input" queries: facts supplied by the client of the analyzer. Reading the docs of the `base_db::input` module should be useful: everything else is strictly derived from those inputs. -### `crates/ra_hir*` crates +### `crates/hir*` crates HIR provides high-level "object oriented" access to Rust code. @@ -113,10 +113,10 @@ is responsible for guessing a HIR for a particular source position. Underneath, HIR works on top of salsa, using a `HirDatabase` trait. -`ra_hir_xxx` crates have a strong ECS flavor, in that they work with raw ids and +`hir_xxx` crates have a strong ECS flavor, in that they work with raw ids and directly query the database. -The top-level `ra_hir` façade crate wraps ids into a more OO-flavored API. +The top-level `hir` façade crate wraps ids into a more OO-flavored API. ### `crates/ra_ide` diff --git a/docs/dev/guide.md b/docs/dev/guide.md index d14143226b1c..29d84bf3f6a4 100644 --- a/docs/dev/guide.md +++ b/docs/dev/guide.md @@ -275,7 +275,7 @@ several times, with different sets of `cfg`s enabled. The IDE-specific task of mapping source code position into a semantic model is inherently imprecise for this reason, and is handled by the [`source_binder`]. -[`source_binder`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/source_binder.rs +[`source_binder`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/source_binder.rs The semantic interface is declared in the [`code_model_api`] module. Each entity is identified by an integer ID and has a bunch of methods which take a salsa database @@ -283,8 +283,8 @@ as an argument and returns other entities (which are also IDs). Internally, thes methods invoke various queries on the database to build the model on demand. Here's [the list of queries]. -[`code_model_api`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/code_model_api.rs -[the list of queries]: https://github.com/rust-analyzer/rust-analyzer/blob/7e84440e25e19529e4ff8a66e521d1b06349c6ec/crates/ra_hir/src/db.rs#L20-L106 +[`code_model_api`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/code_model_api.rs +[the list of queries]: https://github.com/rust-analyzer/rust-analyzer/blob/7e84440e25e19529e4ff8a66e521d1b06349c6ec/crates/hir/src/db.rs#L20-L106 The first step of building the model is parsing the source code. @@ -341,7 +341,7 @@ The algorithm for building a tree of modules is to start with a crate root declarations and recursively process child modules. This is handled by the [`module_tree_query`], with two slight variations. -[`module_tree_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L116-L123 +[`module_tree_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/module_tree.rs#L116-L123 First, rust-analyzer builds a module tree for all crates in a source root simultaneously. The main reason for this is historical (`module_tree` predates @@ -364,7 +364,7 @@ the same, we don't have to re-execute [`module_tree_query`]. In fact, we only need to re-execute it when we add/remove new files or when we change mod declarations. -[`submodules_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L41 +[`submodules_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/module_tree.rs#L41 We store the resulting modules in a `Vec`-based indexed arena. The indices in the arena becomes module IDs. And this brings us to the next topic: @@ -393,7 +393,7 @@ database we use includes a couple of [interners]. How to "garbage collect" unused locations is an open question. [`LocationInterner`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/base_db/src/loc2id.rs#L65-L71 -[interners]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/db.rs#L22-L23 +[interners]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/db.rs#L22-L23 For example, we use `LocationInterner` to assign IDs to definitions of functions, structs, enums, etc. The location, [`DefLoc`] contains two bits of information: @@ -407,7 +407,7 @@ using offsets, text ranges or syntax trees as keys and values for queries. What we do instead is we store "index" of the item among all of the items of a file (so, a positional based ID, but localized to a single file). -[`DefLoc`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/ids.rs#L127-L139 +[`DefLoc`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/ids.rs#L127-L139 One thing we've glossed over for the time being is support for macros. We have only proof of concept handling of macros at the moment, but they are extremely @@ -440,7 +440,7 @@ terms of `HirFileId`! This does not recur infinitely though: any chain of `HirFileId`s bottoms out in `HirFileId::FileId`, that is, some source file actually written by the user. -[`HirFileId`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/ids.rs#L18-L125 +[`HirFileId`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/ids.rs#L18-L125 Now that we understand how to identify a definition, in a source or in a macro-generated file, we can discuss name resolution a bit. @@ -454,14 +454,14 @@ each module into a position-independent representation which does not change if we modify bodies of the items. After that we [loop] resolving all imports until we've reached a fixed point. -[lower]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L113-L117 -[loop]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres.rs#L186-L196 +[lower]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L113-L117 +[loop]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres.rs#L186-L196 And, given all our preparation with IDs and a position-independent representation, it is satisfying to [test] that typing inside function body does not invalidate name resolution results. -[test]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/tests.rs#L376 +[test]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/tests.rs#L376 An interesting fact about name resolution is that it "erases" all of the intermediate paths from the imports: in the end, we know which items are defined @@ -496,10 +496,10 @@ there's an intermediate [projection query] which returns only the first position-independent part of the lowering. The result of this query is stable. Naturally, name resolution [uses] this stable projection query. -[imports]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L52-L59 -[`SourceMap`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L52-L59 -[projection query]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L97-L103 -[uses]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/query_definitions.rs#L49 +[imports]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L52-L59 +[`SourceMap`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L52-L59 +[projection query]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L97-L103 +[uses]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/query_definitions.rs#L49 ## Type inference @@ -521,10 +521,10 @@ construct a mapping from `ExprId`s to types. [@flodiebold]: https://github.com/flodiebold [#327]: https://github.com/rust-analyzer/rust-analyzer/pull/327 -[lower the AST]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/expr.rs -[positional ID]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/expr.rs#L13-L15 -[a source map]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/expr.rs#L41-L44 -[type inference]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/ty.rs#L1208-L1223 +[lower the AST]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/expr.rs +[positional ID]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/expr.rs#L13-L15 +[a source map]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/expr.rs#L41-L44 +[type inference]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/ty.rs#L1208-L1223 ## Tying it all together: completion diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 5a5bd4a3ee34..97a11a01eeb1 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -192,7 +192,7 @@ impl TidyDocs { } let poorly_documented = [ - "ra_hir", + "hir", "hir_expand", "ra_ide", "mbe", From bb5c189b7dae1ea63ccd5d7a0c2e097d7c676f77 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:39:16 +0200 Subject: [PATCH 3/4] Rename ra_ide_db -> ide_db --- Cargo.lock | 46 +++++++++---------- crates/{ra_ide_db => ide_db}/Cargo.toml | 10 ++-- crates/{ra_ide_db => ide_db}/src/change.rs | 0 crates/{ra_ide_db => ide_db}/src/defs.rs | 0 .../src/imports_locator.rs | 0 crates/{ra_ide_db => ide_db}/src/lib.rs | 0 .../{ra_ide_db => ide_db}/src/line_index.rs | 0 crates/{ra_ide_db => ide_db}/src/search.rs | 0 .../src/source_change.rs | 0 .../{ra_ide_db => ide_db}/src/symbol_index.rs | 0 .../{ra_ide_db => ide_db}/src/wasm_shims.rs | 0 crates/ra_assists/Cargo.toml | 2 +- crates/ra_assists/src/assist_context.rs | 2 +- .../ra_assists/src/handlers/add_turbo_fish.rs | 2 +- crates/ra_assists/src/handlers/auto_import.rs | 2 +- .../src/handlers/expand_glob_import.rs | 2 +- .../extract_struct_from_enum_variant.rs | 2 +- .../src/handlers/fill_match_arms.rs | 2 +- .../handlers/generate_from_impl_for_enum.rs | 2 +- .../src/handlers/inline_local_variable.rs | 2 +- .../ra_assists/src/handlers/reorder_fields.rs | 2 +- crates/ra_assists/src/lib.rs | 2 +- crates/ra_assists/src/tests.rs | 2 +- crates/ra_assists/src/utils.rs | 2 +- crates/ra_ide/Cargo.toml | 2 +- crates/ra_ide/src/call_hierarchy.rs | 2 +- crates/ra_ide/src/call_info.rs | 2 +- crates/ra_ide/src/completion.rs | 2 +- .../src/completion/completion_context.rs | 2 +- crates/ra_ide/src/diagnostics.rs | 2 +- .../src/diagnostics/diagnostics_with_fix.rs | 2 +- .../ra_ide/src/display/navigation_target.rs | 2 +- crates/ra_ide/src/expand_macro.rs | 2 +- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/goto_definition.rs | 2 +- crates/ra_ide/src/goto_implementation.rs | 2 +- crates/ra_ide/src/goto_type_definition.rs | 2 +- crates/ra_ide/src/hover.rs | 4 +- crates/ra_ide/src/inlay_hints.rs | 2 +- crates/ra_ide/src/lib.rs | 6 +-- crates/ra_ide/src/parent_module.rs | 2 +- crates/ra_ide/src/references.rs | 4 +- crates/ra_ide/src/references/rename.rs | 2 +- crates/ra_ide/src/runnables.rs | 2 +- crates/ra_ide/src/ssr.rs | 2 +- crates/ra_ide/src/status.rs | 4 +- crates/ra_ide/src/syntax_highlighting.rs | 2 +- crates/ra_ide/src/syntax_tree.rs | 2 +- crates/ra_ide/src/typing.rs | 2 +- crates/ra_ide/src/typing/on_enter.rs | 2 +- crates/ra_ssr/Cargo.toml | 2 +- crates/ra_ssr/src/lib.rs | 10 ++-- crates/ra_ssr/src/matching.rs | 8 ++-- crates/ra_ssr/src/nester.rs | 10 ++-- crates/ra_ssr/src/resolving.rs | 2 +- crates/ra_ssr/src/search.rs | 4 +- crates/ra_ssr/src/tests.rs | 8 ++-- crates/rust-analyzer/Cargo.toml | 2 +- crates/rust-analyzer/src/cli/ssr.rs | 2 +- 59 files changed, 93 insertions(+), 99 deletions(-) rename crates/{ra_ide_db => ide_db}/Cargo.toml (94%) rename crates/{ra_ide_db => ide_db}/src/change.rs (100%) rename crates/{ra_ide_db => ide_db}/src/defs.rs (100%) rename crates/{ra_ide_db => ide_db}/src/imports_locator.rs (100%) rename crates/{ra_ide_db => ide_db}/src/lib.rs (100%) rename crates/{ra_ide_db => ide_db}/src/line_index.rs (100%) rename crates/{ra_ide_db => ide_db}/src/search.rs (100%) rename crates/{ra_ide_db => ide_db}/src/source_change.rs (100%) rename crates/{ra_ide_db => ide_db}/src/symbol_index.rs (100%) rename crates/{ra_ide_db => ide_db}/src/wasm_shims.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index ae71ea9fdbde..8704e43860ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -562,6 +562,25 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ide_db" +version = "0.0.0" +dependencies = [ + "base_db", + "either", + "fst", + "hir", + "log", + "once_cell", + "profile", + "rayon", + "rustc-hash", + "stdx", + "syntax", + "test_utils", + "text_edit", +] + [[package]] name = "idna" version = "0.2.0" @@ -1090,9 +1109,9 @@ dependencies = [ "base_db", "either", "hir", + "ide_db", "itertools", "profile", - "ra_ide_db", "rustc-hash", "stdx", "syntax", @@ -1109,13 +1128,13 @@ dependencies = [ "either", "expect", "hir", + "ide_db", "indexmap", "itertools", "log", "oorandom", "profile", "ra_assists", - "ra_ide_db", "ra_ssr", "rustc-hash", "stdx", @@ -1124,25 +1143,6 @@ dependencies = [ "text_edit", ] -[[package]] -name = "ra_ide_db" -version = "0.1.0" -dependencies = [ - "base_db", - "either", - "fst", - "hir", - "log", - "once_cell", - "profile", - "rayon", - "rustc-hash", - "stdx", - "syntax", - "test_utils", - "text_edit", -] - [[package]] name = "ra_ssr" version = "0.1.0" @@ -1150,7 +1150,7 @@ dependencies = [ "base_db", "expect", "hir", - "ra_ide_db", + "ide_db", "rustc-hash", "syntax", "test_utils", @@ -1239,6 +1239,7 @@ dependencies = [ "hir", "hir_def", "hir_ty", + "ide_db", "itertools", "jod-thread", "log", @@ -1253,7 +1254,6 @@ dependencies = [ "profile", "project_model", "ra_ide", - "ra_ide_db", "ra_ssr", "rayon", "rustc-hash", diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ide_db/Cargo.toml similarity index 94% rename from crates/ra_ide_db/Cargo.toml rename to crates/ide_db/Cargo.toml index eda257a3a8b3..885212162f3b 100644 --- a/crates/ra_ide_db/Cargo.toml +++ b/crates/ide_db/Cargo.toml @@ -1,9 +1,9 @@ [package] -edition = "2018" -name = "ra_ide_db" -version = "0.1.0" -authors = ["rust-analyzer developers"] +name = "ide_db" +version = "0.0.0" license = "MIT OR Apache-2.0" +authors = ["rust-analyzer developers"] +edition = "2018" [lib] doctest = false @@ -20,13 +20,11 @@ once_cell = "1.3.1" either = "1.5.3" stdx = { path = "../stdx" } - syntax = { path = "../syntax" } text_edit = { path = "../text_edit" } base_db = { path = "../base_db" } profile = { path = "../profile" } test_utils = { path = "../test_utils" } - # ra_ide should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. hir = { path = "../hir" } diff --git a/crates/ra_ide_db/src/change.rs b/crates/ide_db/src/change.rs similarity index 100% rename from crates/ra_ide_db/src/change.rs rename to crates/ide_db/src/change.rs diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ide_db/src/defs.rs similarity index 100% rename from crates/ra_ide_db/src/defs.rs rename to crates/ide_db/src/defs.rs diff --git a/crates/ra_ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs similarity index 100% rename from crates/ra_ide_db/src/imports_locator.rs rename to crates/ide_db/src/imports_locator.rs diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ide_db/src/lib.rs similarity index 100% rename from crates/ra_ide_db/src/lib.rs rename to crates/ide_db/src/lib.rs diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ide_db/src/line_index.rs similarity index 100% rename from crates/ra_ide_db/src/line_index.rs rename to crates/ide_db/src/line_index.rs diff --git a/crates/ra_ide_db/src/search.rs b/crates/ide_db/src/search.rs similarity index 100% rename from crates/ra_ide_db/src/search.rs rename to crates/ide_db/src/search.rs diff --git a/crates/ra_ide_db/src/source_change.rs b/crates/ide_db/src/source_change.rs similarity index 100% rename from crates/ra_ide_db/src/source_change.rs rename to crates/ide_db/src/source_change.rs diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs similarity index 100% rename from crates/ra_ide_db/src/symbol_index.rs rename to crates/ide_db/src/symbol_index.rs diff --git a/crates/ra_ide_db/src/wasm_shims.rs b/crates/ide_db/src/wasm_shims.rs similarity index 100% rename from crates/ra_ide_db/src/wasm_shims.rs rename to crates/ide_db/src/wasm_shims.rs diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index cacc063da2b3..19e7591f71c7 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -19,6 +19,6 @@ syntax = { path = "../syntax" } text_edit = { path = "../text_edit" } profile = { path = "../profile" } base_db = { path = "../base_db" } -ra_ide_db = { path = "../ra_ide_db" } +ide_db = { path = "../ide_db" } hir = { path = "../hir" } test_utils = { path = "../test_utils" } diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs index 2fdce037fb8b..79574b9ac8ad 100644 --- a/crates/ra_assists/src/assist_context.rs +++ b/crates/ra_assists/src/assist_context.rs @@ -5,7 +5,7 @@ use std::mem; use algo::find_covering_element; use base_db::{FileId, FileRange}; use hir::Semantics; -use ra_ide_db::{ +use ide_db::{ source_change::{SourceChange, SourceFileEdit}, RootDatabase, }; diff --git a/crates/ra_assists/src/handlers/add_turbo_fish.rs b/crates/ra_assists/src/handlers/add_turbo_fish.rs index 8c7ffae3dde1..f4f997d8e19c 100644 --- a/crates/ra_assists/src/handlers/add_turbo_fish.rs +++ b/crates/ra_assists/src/handlers/add_turbo_fish.rs @@ -1,4 +1,4 @@ -use ra_ide_db::defs::{classify_name_ref, Definition, NameRefClass}; +use ide_db::defs::{classify_name_ref, Definition, NameRefClass}; use syntax::{ast, AstNode, SyntaxKind, T}; use test_utils::mark; diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index e19b197d9e0d..cce789972e54 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -5,7 +5,7 @@ use hir::{ AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait, Type, }; -use ra_ide_db::{imports_locator, RootDatabase}; +use ide_db::{imports_locator, RootDatabase}; use rustc_hash::FxHashSet; use syntax::{ ast::{self, AstNode}, diff --git a/crates/ra_assists/src/handlers/expand_glob_import.rs b/crates/ra_assists/src/handlers/expand_glob_import.rs index cf34ffaf7f71..f690ec343bca 100644 --- a/crates/ra_assists/src/handlers/expand_glob_import.rs +++ b/crates/ra_assists/src/handlers/expand_glob_import.rs @@ -1,5 +1,5 @@ use hir::{AssocItem, MacroDef, ModuleDef, Name, PathResolution, ScopeDef, SemanticsScope}; -use ra_ide_db::{ +use ide_db::{ defs::{classify_name_ref, Definition, NameRefClass}, RootDatabase, }; 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 52fbc540eb08..4bcdae7ba0e4 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,6 +1,6 @@ use base_db::FileId; use hir::{EnumVariant, Module, ModuleDef, Name}; -use ra_ide_db::{defs::Definition, search::Reference, RootDatabase}; +use ide_db::{defs::Definition, search::Reference, RootDatabase}; use rustc_hash::FxHashSet; use syntax::{ algo::find_node_at_offset, diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 8f6660637275..3d9bdb2bf79d 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -1,8 +1,8 @@ use std::iter; use hir::{Adt, HasSource, ModuleDef, Semantics}; +use ide_db::RootDatabase; use itertools::Itertools; -use ra_ide_db::RootDatabase; use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat}; use test_utils::mark; diff --git a/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs index 302b6b67d49d..7f04b95725a8 100644 --- a/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs @@ -1,4 +1,4 @@ -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::ast::{self, AstNode, NameOwner}; use test_utils::mark; diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index 5315923206d9..2b52b333b885 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs @@ -1,4 +1,4 @@ -use ra_ide_db::defs::Definition; +use ide_db::defs::Definition; use syntax::{ ast::{self, AstNode, AstToken}, TextRange, diff --git a/crates/ra_assists/src/handlers/reorder_fields.rs b/crates/ra_assists/src/handlers/reorder_fields.rs index 013720dfcbe9..527f457a7938 100644 --- a/crates/ra_assists/src/handlers/reorder_fields.rs +++ b/crates/ra_assists/src/handlers/reorder_fields.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use rustc_hash::FxHashMap; use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 5d062b88b8bd..f0cf35caf461 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -19,7 +19,7 @@ pub mod ast_transform; use base_db::FileRange; use hir::Semantics; -use ra_ide_db::{source_change::SourceChange, RootDatabase}; +use ide_db::{source_change::SourceChange, RootDatabase}; use syntax::TextRange; pub(crate) use crate::assist_context::{AssistContext, Assists}; diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 75d973688222..ba1fb543b879 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -2,7 +2,7 @@ mod generated; use base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; use hir::Semantics; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::TextRange; use test_utils::{assert_eq_text, extract_offset, extract_range}; diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index a20453dd8747..84ccacafe37f 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs @@ -4,8 +4,8 @@ pub(crate) mod insert_use; use std::{iter, ops}; use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type}; +use ide_db::RootDatabase; use itertools::Itertools; -use ra_ide_db::RootDatabase; use rustc_hash::FxHashSet; use syntax::{ ast::{self, make, NameOwner}, diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index a701cdf1d502..e25aad6cfb08 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml @@ -24,7 +24,7 @@ stdx = { path = "../stdx" } syntax = { path = "../syntax" } text_edit = { path = "../text_edit" } base_db = { path = "../base_db" } -ra_ide_db = { path = "../ra_ide_db" } +ide_db = { path = "../ide_db" } cfg = { path = "../cfg" } profile = { path = "../profile" } test_utils = { path = "../test_utils" } diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index 3578b8d3ce1c..58e26b94ca7c 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs @@ -3,7 +3,7 @@ use indexmap::IndexMap; use hir::Semantics; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ast, match_ast, AstNode, TextRange}; use crate::{ diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 703cbc6b433a..86abd2d8cec2 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -1,7 +1,7 @@ //! FIXME: write short doc here use either::Either; use hir::{Docs, HirDisplay, Semantics, Type}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use stdx::format_to; use syntax::{ ast::{self, ArgListOwner}, diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs index 68ac05e4ca94..7fb4d687e1c1 100644 --- a/crates/ra_ide/src/completion.rs +++ b/crates/ra_ide/src/completion.rs @@ -19,7 +19,7 @@ mod complete_postfix; mod complete_macro_in_item_position; mod complete_trait_impl; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use crate::{ completion::{ diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 0e0a201d091c..047ecd9d7717 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -2,7 +2,7 @@ use base_db::SourceDatabase; use hir::{Semantics, SemanticsScope, Type}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ algo::{find_covering_element, find_node_at_offset}, ast, match_ast, AstNode, NodeOrToken, diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 4e59e3a48058..a3ec98178a10 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -8,8 +8,8 @@ use std::cell::RefCell; use base_db::SourceDatabase; use hir::{diagnostics::DiagnosticSinkBuilder, Semantics}; +use ide_db::RootDatabase; use itertools::Itertools; -use ra_ide_db::RootDatabase; use syntax::{ ast::{self, AstNode}, SyntaxNode, TextRange, T, diff --git a/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs index 7e126d7a6a54..85b46c9958a1 100644 --- a/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs +++ b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs @@ -8,7 +8,7 @@ use hir::{ diagnostics::{Diagnostic, MissingFields, MissingOkInTailExpr, NoSuchField, UnresolvedModule}, HasSource, HirDisplay, Semantics, VariantDef, }; -use ra_ide_db::{ +use ide_db::{ source_change::{FileSystemEdit, SourceFileEdit}, RootDatabase, }; diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 09ec3f65e69d..e77106177267 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -3,7 +3,7 @@ use base_db::{FileId, SourceDatabase}; use either::Either; use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource}; -use ra_ide_db::{defs::Definition, RootDatabase}; +use ide_db::{defs::Definition, RootDatabase}; use syntax::{ ast::{self, DocCommentsOwner, NameOwner}, match_ast, AstNode, SmolStr, diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs index c25e068d60f7..31455709d7d8 100644 --- a/crates/ra_ide/src/expand_macro.rs +++ b/crates/ra_ide/src/expand_macro.rs @@ -1,5 +1,5 @@ use hir::Semantics; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ algo::{find_node_at_offset, SyntaxRewriter}, ast, AstNode, NodeOrToken, SyntaxKind, diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index f30df2bff475..34563a0267f6 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -1,7 +1,7 @@ use std::iter::successors; use hir::Semantics; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ algo::{self, find_covering_element, skip_trivia_token}, ast::{self, AstNode, AstToken}, diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index b93d116bf868..15e9b7fad825 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -1,5 +1,5 @@ use hir::Semantics; -use ra_ide_db::{ +use ide_db::{ defs::{classify_name, classify_name_ref}, symbol_index, RootDatabase, }; diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index 6dc2ccfd05fc..f503f4ec5fe4 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -1,5 +1,5 @@ use hir::{Crate, ImplDef, Semantics}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{algo::find_node_at_offset, ast, AstNode}; use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo}; diff --git a/crates/ra_ide/src/goto_type_definition.rs b/crates/ra_ide/src/goto_type_definition.rs index 8017ca58cba9..4a151b150640 100644 --- a/crates/ra_ide/src/goto_type_definition.rs +++ b/crates/ra_ide/src/goto_type_definition.rs @@ -1,4 +1,4 @@ -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; use crate::{display::ToNav, FilePosition, NavigationTarget, RangeInfo}; diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index a74087f87a71..331aa4db0c73 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -3,11 +3,11 @@ use hir::{ Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, Module, ModuleDef, ModuleSource, Semantics, }; -use itertools::Itertools; -use ra_ide_db::{ +use ide_db::{ defs::{classify_name, classify_name_ref, Definition}, RootDatabase, }; +use itertools::Itertools; use stdx::format_to; use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; use test_utils::mark; diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 81fe274adf22..002adf9159f8 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -1,5 +1,5 @@ use hir::{Adt, Callable, HirDisplay, Semantics, Type}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use stdx::to_lower_snake_case; use syntax::{ ast::{self, ArgListOwner, AstNode}, diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 0d14c823aef2..66a234fff78d 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -52,7 +52,7 @@ use base_db::{ CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, }; use cfg::CfgOptions; -use ra_ide_db::{ +use ide_db::{ symbol_index::{self, FileSymbol}, LineIndexDatabase, }; @@ -86,8 +86,7 @@ pub use base_db::{ SourceRootId, }; pub use hir::{Documentation, Semantics}; -pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist}; -pub use ra_ide_db::{ +pub use ide_db::{ change::AnalysisChange, line_index::{LineCol, LineIndex}, search::SearchScope, @@ -95,6 +94,7 @@ pub use ra_ide_db::{ symbol_index::Query, RootDatabase, }; +pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist}; pub use ra_ssr::SsrError; pub use text_edit::{Indel, TextEdit}; diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index 8439e1d5d331..59ed2967cf2a 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs @@ -1,6 +1,6 @@ use base_db::{CrateId, FileId, FilePosition}; use hir::Semantics; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ algo::find_node_at_offset, ast::{self, AstNode}, diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index e89dca869ca7..0a76ec6b4306 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -12,7 +12,7 @@ mod rename; use hir::Semantics; -use ra_ide_db::{ +use ide_db::{ defs::{classify_name, classify_name_ref, Definition}, search::SearchScope, RootDatabase, @@ -27,7 +27,7 @@ use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeI pub(crate) use self::rename::rename; -pub use ra_ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; +pub use ide_db::search::{Reference, ReferenceAccess, ReferenceKind}; #[derive(Debug, Clone)] pub struct ReferenceSearchResult { diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 5697b9d879d8..d73dc9cd00b0 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -2,7 +2,7 @@ use base_db::SourceDatabaseExt; use hir::{Module, ModuleDef, ModuleSource, Semantics}; -use ra_ide_db::{ +use ide_db::{ defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, RootDatabase, }; diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index fb40762cfb20..c3e07c8dec73 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -2,8 +2,8 @@ use std::fmt; use cfg::CfgExpr; use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; +use ide_db::RootDatabase; use itertools::Itertools; -use ra_ide_db::RootDatabase; use syntax::{ ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner}, match_ast, SyntaxNode, diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 97b82b70e5b4..a8a7041923b6 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -1,5 +1,5 @@ use base_db::{FilePosition, FileRange}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use crate::SourceFileEdit; use ra_ssr::{MatchFinder, SsrError, SsrRule}; diff --git a/crates/ra_ide/src/status.rs b/crates/ra_ide/src/status.rs index 869c74accc20..c23708181807 100644 --- a/crates/ra_ide/src/status.rs +++ b/crates/ra_ide/src/status.rs @@ -5,11 +5,11 @@ use base_db::{ FileTextQuery, SourceRootId, }; use hir::MacroFile; -use profile::{memory_usage, Bytes}; -use ra_ide_db::{ +use ide_db::{ symbol_index::{LibrarySymbolsQuery, SymbolIndex}, RootDatabase, }; +use profile::{memory_usage, Bytes}; use rustc_hash::FxHashMap; use syntax::{ast, Parse, SyntaxNode}; diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 4b41ceb1dc4d..5d7c7e8d02a2 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -5,7 +5,7 @@ mod injection; mod tests; use hir::{Name, Semantics, VariantDef}; -use ra_ide_db::{ +use ide_db::{ defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, RootDatabase, }; diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs index 17daf06b66c9..f8004495960c 100644 --- a/crates/ra_ide/src/syntax_tree.rs +++ b/crates/ra_ide/src/syntax_tree.rs @@ -1,5 +1,5 @@ use base_db::{FileId, SourceDatabase}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ algo, AstNode, NodeOrToken, SourceFile, SyntaxKind::{RAW_STRING, STRING}, diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 75f2a6b60573..899ce5f26527 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -16,7 +16,7 @@ mod on_enter; use base_db::{FilePosition, SourceDatabase}; -use ra_ide_db::{source_change::SourceFileEdit, RootDatabase}; +use ide_db::{source_change::SourceFileEdit, RootDatabase}; use syntax::{ algo::find_node_at_offset, ast::{self, edit::IndentLevel, AstToken}, diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index 1939306590f0..f7d46146c509 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs @@ -2,7 +2,7 @@ //! comments, but should handle indent some time in the future as well. use base_db::{FilePosition, SourceDatabase}; -use ra_ide_db::RootDatabase; +use ide_db::RootDatabase; use syntax::{ ast::{self, AstToken}, AstNode, SmolStr, SourceFile, diff --git a/crates/ra_ssr/Cargo.toml b/crates/ra_ssr/Cargo.toml index bed4bbdf19cf..4d22a8a982c6 100644 --- a/crates/ra_ssr/Cargo.toml +++ b/crates/ra_ssr/Cargo.toml @@ -14,7 +14,7 @@ doctest = false text_edit = { path = "../text_edit" } syntax = { path = "../syntax" } base_db = { path = "../base_db" } -ra_ide_db = { path = "../ra_ide_db" } +ide_db = { path = "../ide_db" } hir = { path = "../hir" } rustc-hash = "1.1.0" test_utils = { path = "../test_utils" } diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs index 6725582e49b2..b4e35107ed7c 100644 --- a/crates/ra_ssr/src/lib.rs +++ b/crates/ra_ssr/src/lib.rs @@ -20,7 +20,7 @@ pub use crate::matching::Match; use crate::matching::MatchFailureReason; use base_db::{FileId, FilePosition, FileRange}; use hir::Semantics; -use ra_ide_db::source_change::SourceFileEdit; +use ide_db::source_change::SourceFileEdit; use resolving::ResolvedRule; use rustc_hash::FxHashMap; use syntax::{ast, AstNode, SyntaxNode, TextRange}; @@ -49,7 +49,7 @@ pub struct SsrMatches { /// Searches a crate for pattern matches and possibly replaces them with something else. pub struct MatchFinder<'db> { /// Our source of information about the user's code. - sema: Semantics<'db, ra_ide_db::RootDatabase>, + sema: Semantics<'db, ide_db::RootDatabase>, rules: Vec, resolution_scope: resolving::ResolutionScope<'db>, restrict_ranges: Vec, @@ -59,7 +59,7 @@ impl<'db> MatchFinder<'db> { /// Constructs a new instance where names will be looked up as if they appeared at /// `lookup_context`. pub fn in_context( - db: &'db ra_ide_db::RootDatabase, + db: &'db ide_db::RootDatabase, lookup_context: FilePosition, mut restrict_ranges: Vec, ) -> MatchFinder<'db> { @@ -70,9 +70,9 @@ impl<'db> MatchFinder<'db> { } /// Constructs an instance using the start of the first file in `db` as the lookup context. - pub fn at_first_file(db: &'db ra_ide_db::RootDatabase) -> Result, SsrError> { + pub fn at_first_file(db: &'db ide_db::RootDatabase) -> Result, SsrError> { use base_db::SourceDatabaseExt; - use ra_ide_db::symbol_index::SymbolsDatabase; + use ide_db::symbol_index::SymbolsDatabase; if let Some(first_file_id) = db .local_roots() .iter() diff --git a/crates/ra_ssr/src/matching.rs b/crates/ra_ssr/src/matching.rs index e81a87c4714b..ffc7202ae560 100644 --- a/crates/ra_ssr/src/matching.rs +++ b/crates/ra_ssr/src/matching.rs @@ -92,7 +92,7 @@ pub(crate) fn get_match( rule: &ResolvedRule, code: &SyntaxNode, restrict_range: &Option, - sema: &Semantics, + sema: &Semantics, ) -> Result { record_match_fails_reasons_scope(debug_active, || { Matcher::try_match(rule, code, restrict_range, sema) @@ -101,7 +101,7 @@ pub(crate) fn get_match( /// Checks if our search pattern matches a particular node of the AST. struct Matcher<'db, 'sema> { - sema: &'sema Semantics<'db, ra_ide_db::RootDatabase>, + sema: &'sema Semantics<'db, ide_db::RootDatabase>, /// If any placeholders come from anywhere outside of this range, then the match will be /// rejected. restrict_range: Option, @@ -123,7 +123,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { rule: &ResolvedRule, code: &SyntaxNode, restrict_range: &Option, - sema: &'sema Semantics<'db, ra_ide_db::RootDatabase>, + sema: &'sema Semantics<'db, ide_db::RootDatabase>, ) -> Result { let match_state = Matcher { sema, restrict_range: restrict_range.clone(), rule }; // First pass at matching, where we check that node types and idents match. @@ -606,7 +606,7 @@ impl Match { fn render_template_paths( &mut self, template: &ResolvedPattern, - sema: &Semantics, + sema: &Semantics, ) -> Result<(), MatchFailed> { let module = sema .scope(&self.matched_node) diff --git a/crates/ra_ssr/src/nester.rs b/crates/ra_ssr/src/nester.rs index 8be570d3cf9a..6ac355dfc22b 100644 --- a/crates/ra_ssr/src/nester.rs +++ b/crates/ra_ssr/src/nester.rs @@ -13,7 +13,7 @@ use syntax::SyntaxNode; pub(crate) fn nest_and_remove_collisions( mut matches: Vec, - sema: &hir::Semantics, + sema: &hir::Semantics, ) -> SsrMatches { // We sort the matches by depth then by rule index. Sorting by depth means that by the time we // see a match, any parent matches or conflicting matches will have already been seen. Sorting @@ -36,7 +36,7 @@ impl MatchCollector { /// Attempts to add `m` to matches. If it conflicts with an existing match, it is discarded. If /// it is entirely within the a placeholder of an existing match, then it is added as a child /// match of the existing match. - fn add_match(&mut self, m: Match, sema: &hir::Semantics) { + fn add_match(&mut self, m: Match, sema: &hir::Semantics) { let matched_node = m.matched_node.clone(); if let Some(existing) = self.matches_by_node.get_mut(&matched_node) { try_add_sub_match(m, existing, sema); @@ -53,11 +53,7 @@ impl MatchCollector { } /// Attempts to add `m` as a sub-match of `existing`. -fn try_add_sub_match( - m: Match, - existing: &mut Match, - sema: &hir::Semantics, -) { +fn try_add_sub_match(m: Match, existing: &mut Match, sema: &hir::Semantics) { for p in existing.placeholder_values.values_mut() { // Note, no need to check if p.range.file is equal to m.range.file, since we // already know we're within `existing`. diff --git a/crates/ra_ssr/src/resolving.rs b/crates/ra_ssr/src/resolving.rs index dac09bae803a..020fd7994138 100644 --- a/crates/ra_ssr/src/resolving.rs +++ b/crates/ra_ssr/src/resolving.rs @@ -187,7 +187,7 @@ impl Resolver<'_, '_> { impl<'db> ResolutionScope<'db> { pub(crate) fn new( - sema: &hir::Semantics<'db, ra_ide_db::RootDatabase>, + sema: &hir::Semantics<'db, ide_db::RootDatabase>, resolve_context: FilePosition, ) -> ResolutionScope<'db> { use syntax::ast::AstNode; diff --git a/crates/ra_ssr/src/search.rs b/crates/ra_ssr/src/search.rs index 434953fb48b9..8509cfa4dea0 100644 --- a/crates/ra_ssr/src/search.rs +++ b/crates/ra_ssr/src/search.rs @@ -6,7 +6,7 @@ use crate::{ Match, MatchFinder, }; use base_db::{FileId, FileRange}; -use ra_ide_db::{ +use ide_db::{ defs::Definition, search::{Reference, SearchScope}, }; @@ -146,7 +146,7 @@ impl<'db> MatchFinder<'db> { if self.restrict_ranges.is_empty() { // Unrestricted search. use base_db::SourceDatabaseExt; - use ra_ide_db::symbol_index::SymbolsDatabase; + use ide_db::symbol_index::SymbolsDatabase; for &root in self.sema.db.local_roots().iter() { let sr = self.sema.db.source_root(root); for file_id in sr.iter() { diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs index 54c3da9db356..0d0a00090642 100644 --- a/crates/ra_ssr/src/tests.rs +++ b/crates/ra_ssr/src/tests.rs @@ -61,13 +61,13 @@ fn parser_undefined_placeholder_in_replacement() { /// `code` may optionally contain a cursor marker `<|>`. If it doesn't, then the position will be /// the start of the file. If there's a second cursor marker, then we'll return a single range. -pub(crate) fn single_file(code: &str) -> (ra_ide_db::RootDatabase, FilePosition, Vec) { +pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Vec) { use base_db::fixture::WithFixture; - use ra_ide_db::symbol_index::SymbolsDatabase; + use ide_db::symbol_index::SymbolsDatabase; let (mut db, file_id, range_or_offset) = if code.contains(test_utils::CURSOR_MARKER) { - ra_ide_db::RootDatabase::with_range_or_offset(code) + ide_db::RootDatabase::with_range_or_offset(code) } else { - let (db, file_id) = ra_ide_db::RootDatabase::with_single_file(code); + let (db, file_id) = ide_db::RootDatabase::with_single_file(code); (db, file_id, RangeOrOffset::Offset(0.into())) }; let selections; diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index c0257e9c8970..da8c09c09a74 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -47,7 +47,7 @@ toolchain = { path = "../toolchain" } # This should only be used in CLI base_db = { path = "../base_db" } -ra_ide_db = { path = "../ra_ide_db" } +ide_db = { path = "../ide_db" } ra_ssr = { path = "../ra_ssr" } hir = { path = "../hir" } hir_def = { path = "../hir_def" } diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs index 08788fb41547..1357a93e1693 100644 --- a/crates/rust-analyzer/src/cli/ssr.rs +++ b/crates/rust-analyzer/src/cli/ssr.rs @@ -27,7 +27,7 @@ pub fn apply_ssr_rules(rules: Vec) -> Result<()> { /// for much else. pub fn search_for_patterns(patterns: Vec, debug_snippet: Option) -> Result<()> { use base_db::SourceDatabaseExt; - use ra_ide_db::symbol_index::SymbolsDatabase; + use ide_db::symbol_index::SymbolsDatabase; let (host, _vfs) = load_cargo(&std::env::current_dir()?, true, true)?; let db = host.raw_database(); let mut match_finder = MatchFinder::at_first_file(db)?; From ae3abd6e575940eb1221acf26c09e96352f052fa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:45:10 +0200 Subject: [PATCH 4/4] Rename ra_ssr -> ssr --- Cargo.lock | 32 +++++------ crates/ra_ide/Cargo.toml | 2 +- crates/ra_ide/src/lib.rs | 18 ++++--- crates/ra_ide/src/ssr.rs | 72 ------------------------- crates/rust-analyzer/Cargo.toml | 2 +- crates/rust-analyzer/src/bin/args.rs | 2 +- crates/rust-analyzer/src/cli.rs | 12 +++-- crates/rust-analyzer/src/cli/ssr.rs | 2 +- crates/{ra_ssr => ssr}/Cargo.toml | 11 ++-- crates/{ra_ssr => ssr}/src/errors.rs | 0 crates/{ra_ssr => ssr}/src/lib.rs | 52 ++++++++++++++++++ crates/{ra_ssr => ssr}/src/matching.rs | 0 crates/{ra_ssr => ssr}/src/nester.rs | 0 crates/{ra_ssr => ssr}/src/parsing.rs | 0 crates/{ra_ssr => ssr}/src/replacing.rs | 0 crates/{ra_ssr => ssr}/src/resolving.rs | 0 crates/{ra_ssr => ssr}/src/search.rs | 0 crates/{ra_ssr => ssr}/src/tests.rs | 0 18 files changed, 95 insertions(+), 110 deletions(-) delete mode 100644 crates/ra_ide/src/ssr.rs rename crates/{ra_ssr => ssr}/Cargo.toml (97%) rename crates/{ra_ssr => ssr}/src/errors.rs (100%) rename crates/{ra_ssr => ssr}/src/lib.rs (82%) rename crates/{ra_ssr => ssr}/src/matching.rs (100%) rename crates/{ra_ssr => ssr}/src/nester.rs (100%) rename crates/{ra_ssr => ssr}/src/parsing.rs (100%) rename crates/{ra_ssr => ssr}/src/replacing.rs (100%) rename crates/{ra_ssr => ssr}/src/resolving.rs (100%) rename crates/{ra_ssr => ssr}/src/search.rs (100%) rename crates/{ra_ssr => ssr}/src/tests.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 8704e43860ae..4d8b748392d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1135,28 +1135,14 @@ dependencies = [ "oorandom", "profile", "ra_assists", - "ra_ssr", "rustc-hash", + "ssr", "stdx", "syntax", "test_utils", "text_edit", ] -[[package]] -name = "ra_ssr" -version = "0.1.0" -dependencies = [ - "base_db", - "expect", - "hir", - "ide_db", - "rustc-hash", - "syntax", - "test_utils", - "text_edit", -] - [[package]] name = "rayon" version = "1.3.1" @@ -1254,11 +1240,11 @@ dependencies = [ "profile", "project_model", "ra_ide", - "ra_ssr", "rayon", "rustc-hash", "serde", "serde_json", + "ssr", "stdx", "syntax", "test_utils", @@ -1456,6 +1442,20 @@ dependencies = [ "serde", ] +[[package]] +name = "ssr" +version = "0.1.0" +dependencies = [ + "base_db", + "expect", + "hir", + "ide_db", + "rustc-hash", + "syntax", + "test_utils", + "text_edit", +] + [[package]] name = "stdx" version = "0.1.0" diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index e25aad6cfb08..8519e9ccaec7 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml @@ -29,7 +29,7 @@ cfg = { path = "../cfg" } profile = { path = "../profile" } test_utils = { path = "../test_utils" } ra_assists = { path = "../ra_assists" } -ra_ssr = { path = "../ra_ssr" } +ssr = { path = "../ssr" } # ra_ide should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 66a234fff78d..bbc9e4b8af27 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -39,7 +39,6 @@ mod matching_brace; mod parent_module; mod references; mod runnables; -mod ssr; mod status; mod syntax_highlighting; mod syntax_tree; @@ -95,7 +94,7 @@ pub use ide_db::{ RootDatabase, }; pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist}; -pub use ra_ssr::SsrError; +pub use ssr::SsrError; pub use text_edit::{Indel, TextEdit}; pub type Cancelable = Result; @@ -515,20 +514,23 @@ impl Analysis { &self, query: &str, parse_only: bool, - position: FilePosition, + resolve_context: FilePosition, selections: Vec, ) -> Cancelable> { self.with_db(|db| { - let edits = ssr::parse_search_replace(query, parse_only, db, position, selections)?; + let rule: ssr::SsrRule = query.parse()?; + let mut match_finder = ssr::MatchFinder::in_context(db, resolve_context, selections); + match_finder.add_rule(rule)?; + let edits = if parse_only { Vec::new() } else { match_finder.edits() }; Ok(SourceChange::from(edits)) }) } /// Performs an operation on that may be Canceled. - fn with_db T + std::panic::UnwindSafe, T>( - &self, - f: F, - ) -> Cancelable { + fn with_db(&self, f: F) -> Cancelable + where + F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, + { self.db.catch_canceled(f) } } diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs deleted file mode 100644 index a8a7041923b6..000000000000 --- a/crates/ra_ide/src/ssr.rs +++ /dev/null @@ -1,72 +0,0 @@ -use base_db::{FilePosition, FileRange}; -use ide_db::RootDatabase; - -use crate::SourceFileEdit; -use ra_ssr::{MatchFinder, SsrError, SsrRule}; - -// Feature: Structural Search and Replace -// -// Search and replace with named wildcards that will match any expression, type, path, pattern or item. -// The syntax for a structural search replace command is ` ==>> `. -// A `$` placeholder in the search pattern will match any AST node and `$` will reference it in the replacement. -// Within a macro call, a placeholder will match up until whatever token follows the placeholder. -// -// All paths in both the search pattern and the replacement template must resolve in the context -// in which this command is invoked. Paths in the search pattern will then match the code if they -// resolve to the same item, even if they're written differently. For example if we invoke the -// command in the module `foo` with a pattern of `Bar`, then code in the parent module that refers -// to `foo::Bar` will match. -// -// Paths in the replacement template will be rendered appropriately for the context in which the -// replacement occurs. For example if our replacement template is `foo::Bar` and we match some -// code in the `foo` module, we'll insert just `Bar`. -// -// Inherent method calls should generally be written in UFCS form. e.g. `foo::Bar::baz($s, $a)` will -// match `$s.baz($a)`, provided the method call `baz` resolves to the method `foo::Bar::baz`. -// -// The scope of the search / replace will be restricted to the current selection if any, otherwise -// it will apply to the whole workspace. -// -// Placeholders may be given constraints by writing them as `${::...}`. -// -// Supported constraints: -// -// |=== -// | Constraint | Restricts placeholder -// -// | kind(literal) | Is a literal (e.g. `42` or `"forty two"`) -// | not(a) | Negates the constraint `a` -// |=== -// -// Available via the command `rust-analyzer.ssr`. -// -// ```rust -// // Using structural search replace command [foo($a, $b) ==>> ($a).foo($b)] -// -// // BEFORE -// String::from(foo(y + 5, z)) -// -// // AFTER -// String::from((y + 5).foo(z)) -// ``` -// -// |=== -// | Editor | Action Name -// -// | VS Code | **Rust Analyzer: Structural Search Replace** -// |=== -pub fn parse_search_replace( - rule: &str, - parse_only: bool, - db: &RootDatabase, - resolve_context: FilePosition, - selections: Vec, -) -> Result, SsrError> { - let rule: SsrRule = rule.parse()?; - let mut match_finder = MatchFinder::in_context(db, resolve_context, selections); - match_finder.add_rule(rule)?; - if parse_only { - return Ok(Vec::new()); - } - Ok(match_finder.edits()) -} diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index da8c09c09a74..749cf648c6f7 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -48,7 +48,7 @@ toolchain = { path = "../toolchain" } # This should only be used in CLI base_db = { path = "../base_db" } ide_db = { path = "../ide_db" } -ra_ssr = { path = "../ra_ssr" } +ssr = { path = "../ssr" } hir = { path = "../hir" } hir_def = { path = "../hir_def" } hir_ty = { path = "../hir_ty" } diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index d3081e88bd94..0bc92431a9a0 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs @@ -7,8 +7,8 @@ use std::{env, fmt::Write, path::PathBuf}; use anyhow::{bail, Result}; use pico_args::Arguments; -use ra_ssr::{SsrPattern, SsrRule}; use rust_analyzer::cli::{AnalysisStatsCmd, BenchCmd, BenchWhat, Position, Verbosity}; +use ssr::{SsrPattern, SsrRule}; use vfs::AbsPathBuf; pub(crate) struct Args { diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index 420abaccb93c..b237a94d113a 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs @@ -13,11 +13,13 @@ use anyhow::Result; use ra_ide::Analysis; use syntax::{AstNode, SourceFile}; -pub use analysis_bench::{BenchCmd, BenchWhat, Position}; -pub use analysis_stats::AnalysisStatsCmd; -pub use diagnostics::diagnostics; -pub use load_cargo::load_cargo; -pub use ssr::{apply_ssr_rules, search_for_patterns}; +pub use self::{ + analysis_bench::{BenchCmd, BenchWhat, Position}, + analysis_stats::AnalysisStatsCmd, + diagnostics::diagnostics, + load_cargo::load_cargo, + ssr::{apply_ssr_rules, search_for_patterns}, +}; #[derive(Clone, Copy)] pub enum Verbosity { diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs index 1357a93e1693..c11e10943719 100644 --- a/crates/rust-analyzer/src/cli/ssr.rs +++ b/crates/rust-analyzer/src/cli/ssr.rs @@ -1,7 +1,7 @@ //! Applies structured search replace rules from the command line. use crate::cli::{load_cargo::load_cargo, Result}; -use ra_ssr::{MatchFinder, SsrPattern, SsrRule}; +use ssr::{MatchFinder, SsrPattern, SsrRule}; pub fn apply_ssr_rules(rules: Vec) -> Result<()> { use base_db::SourceDatabaseExt; diff --git a/crates/ra_ssr/Cargo.toml b/crates/ssr/Cargo.toml similarity index 97% rename from crates/ra_ssr/Cargo.toml rename to crates/ssr/Cargo.toml index 4d22a8a982c6..cd05eeecc89d 100644 --- a/crates/ra_ssr/Cargo.toml +++ b/crates/ssr/Cargo.toml @@ -1,22 +1,23 @@ [package] -edition = "2018" -name = "ra_ssr" +name = "ssr" version = "0.1.0" -authors = ["rust-analyzer developers"] -license = "MIT OR Apache-2.0" description = "Structural search and replace of Rust code" +license = "MIT OR Apache-2.0" repository = "https://github.com/rust-analyzer/rust-analyzer" +authors = ["rust-analyzer developers"] +edition = "2018" [lib] doctest = false [dependencies] +rustc-hash = "1.1.0" + text_edit = { path = "../text_edit" } syntax = { path = "../syntax" } base_db = { path = "../base_db" } ide_db = { path = "../ide_db" } hir = { path = "../hir" } -rustc-hash = "1.1.0" test_utils = { path = "../test_utils" } [dev-dependencies] diff --git a/crates/ra_ssr/src/errors.rs b/crates/ssr/src/errors.rs similarity index 100% rename from crates/ra_ssr/src/errors.rs rename to crates/ssr/src/errors.rs diff --git a/crates/ra_ssr/src/lib.rs b/crates/ssr/src/lib.rs similarity index 82% rename from crates/ra_ssr/src/lib.rs rename to crates/ssr/src/lib.rs index b4e35107ed7c..292bd5b9a73a 100644 --- a/crates/ra_ssr/src/lib.rs +++ b/crates/ssr/src/lib.rs @@ -3,6 +3,58 @@ //! Allows searching the AST for code that matches one or more patterns and then replacing that code //! based on a template. +// Feature: Structural Search and Replace +// +// Search and replace with named wildcards that will match any expression, type, path, pattern or item. +// The syntax for a structural search replace command is ` ==>> `. +// A `$` placeholder in the search pattern will match any AST node and `$` will reference it in the replacement. +// Within a macro call, a placeholder will match up until whatever token follows the placeholder. +// +// All paths in both the search pattern and the replacement template must resolve in the context +// in which this command is invoked. Paths in the search pattern will then match the code if they +// resolve to the same item, even if they're written differently. For example if we invoke the +// command in the module `foo` with a pattern of `Bar`, then code in the parent module that refers +// to `foo::Bar` will match. +// +// Paths in the replacement template will be rendered appropriately for the context in which the +// replacement occurs. For example if our replacement template is `foo::Bar` and we match some +// code in the `foo` module, we'll insert just `Bar`. +// +// Inherent method calls should generally be written in UFCS form. e.g. `foo::Bar::baz($s, $a)` will +// match `$s.baz($a)`, provided the method call `baz` resolves to the method `foo::Bar::baz`. +// +// The scope of the search / replace will be restricted to the current selection if any, otherwise +// it will apply to the whole workspace. +// +// Placeholders may be given constraints by writing them as `${::...}`. +// +// Supported constraints: +// +// |=== +// | Constraint | Restricts placeholder +// +// | kind(literal) | Is a literal (e.g. `42` or `"forty two"`) +// | not(a) | Negates the constraint `a` +// |=== +// +// Available via the command `rust-analyzer.ssr`. +// +// ```rust +// // Using structural search replace command [foo($a, $b) ==>> ($a).foo($b)] +// +// // BEFORE +// String::from(foo(y + 5, z)) +// +// // AFTER +// String::from((y + 5).foo(z)) +// ``` +// +// |=== +// | Editor | Action Name +// +// | VS Code | **Rust Analyzer: Structural Search Replace** +// |=== + mod matching; mod nester; mod parsing; diff --git a/crates/ra_ssr/src/matching.rs b/crates/ssr/src/matching.rs similarity index 100% rename from crates/ra_ssr/src/matching.rs rename to crates/ssr/src/matching.rs diff --git a/crates/ra_ssr/src/nester.rs b/crates/ssr/src/nester.rs similarity index 100% rename from crates/ra_ssr/src/nester.rs rename to crates/ssr/src/nester.rs diff --git a/crates/ra_ssr/src/parsing.rs b/crates/ssr/src/parsing.rs similarity index 100% rename from crates/ra_ssr/src/parsing.rs rename to crates/ssr/src/parsing.rs diff --git a/crates/ra_ssr/src/replacing.rs b/crates/ssr/src/replacing.rs similarity index 100% rename from crates/ra_ssr/src/replacing.rs rename to crates/ssr/src/replacing.rs diff --git a/crates/ra_ssr/src/resolving.rs b/crates/ssr/src/resolving.rs similarity index 100% rename from crates/ra_ssr/src/resolving.rs rename to crates/ssr/src/resolving.rs diff --git a/crates/ra_ssr/src/search.rs b/crates/ssr/src/search.rs similarity index 100% rename from crates/ra_ssr/src/search.rs rename to crates/ssr/src/search.rs diff --git a/crates/ra_ssr/src/tests.rs b/crates/ssr/src/tests.rs similarity index 100% rename from crates/ra_ssr/src/tests.rs rename to crates/ssr/src/tests.rs