Merge branch 'master' into add-disable-diagnostics

This commit is contained in:
Igor Aleksanov 2020-08-14 07:34:07 +03:00
commit c26c911ec1
1140 changed files with 2355 additions and 2386 deletions

2
.gitattributes vendored
View File

@ -1,5 +1,5 @@
* text=auto eol=lf
crates/ra_syntax/test_data/** -text eof=LF
crates/syntax/test_data/** -text eof=LF
# Older git versions try to fix line endings on images, this prevents it.
*.png binary
*.jpg binary

View File

@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest] #, macos-latest]
steps:
- name: Checkout repository
@ -115,7 +115,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}

743
Cargo.lock generated
View File

@ -15,15 +15,6 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
[[package]]
name = "aho-corasick"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86"
dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
@ -45,12 +36,33 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
[[package]]
name = "arena"
version = "0.0.0"
[[package]]
name = "arrayvec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]]
name = "assists"
version = "0.0.0"
dependencies = [
"base_db",
"either",
"hir",
"ide_db",
"itertools",
"profile",
"rustc-hash",
"stdx",
"syntax",
"test_utils",
"text_edit",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -88,6 +100,21 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "base_db"
version = "0.0.0"
dependencies = [
"cfg",
"profile",
"rustc-hash",
"salsa",
"stdx",
"syntax",
"test_utils",
"tt",
"vfs",
]
[[package]]
name = "bitflags"
version = "1.2.1"
@ -117,6 +144,16 @@ version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
[[package]]
name = "cfg"
version = "0.0.0"
dependencies = [
"mbe",
"rustc-hash",
"syntax",
"tt",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
@ -285,9 +322,9 @@ checksum = "9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1"
[[package]]
name = "either"
version = "1.5.3"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"
[[package]]
name = "ena"
@ -309,7 +346,7 @@ dependencies = [
[[package]]
name = "expect"
version = "0.1.0"
version = "0.0.0"
dependencies = [
"difference",
"once_cell",
@ -348,14 +385,14 @@ dependencies = [
[[package]]
name = "flycheck"
version = "0.1.0"
version = "0.0.0"
dependencies = [
"cargo_metadata",
"crossbeam-channel",
"jod-thread",
"log",
"ra_toolchain",
"serde_json",
"toolchain",
]
[[package]]
@ -443,6 +480,96 @@ 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"
dependencies = [
"anymap",
"arena",
"base_db",
"cfg",
"drop_bomb",
"either",
"expect",
"fst",
"hir_expand",
"indexmap",
"itertools",
"log",
"mbe",
"once_cell",
"profile",
"rustc-hash",
"smallvec",
"stdx",
"syntax",
"test_utils",
"tt",
]
[[package]]
name = "hir_expand"
version = "0.0.0"
dependencies = [
"arena",
"base_db",
"either",
"log",
"mbe",
"parser",
"profile",
"rustc-hash",
"syntax",
"test_utils",
"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"
@ -452,6 +579,49 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "ide"
version = "0.0.0"
dependencies = [
"assists",
"base_db",
"cfg",
"either",
"expect",
"hir",
"ide_db",
"indexmap",
"itertools",
"log",
"oorandom",
"profile",
"rustc-hash",
"ssr",
"stdx",
"syntax",
"test_utils",
"text_edit",
]
[[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"
@ -547,9 +717,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.2.1"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
@ -641,10 +811,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
name = "mbe"
version = "0.0.0"
dependencies = [
"log",
"parser",
"rustc-hash",
"smallvec",
"syntax",
"test_utils",
"tt",
]
[[package]]
name = "memmap"
@ -830,9 +1007,16 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "parser"
version = "0.0.0"
dependencies = [
"drop_bomb",
]
[[package]]
name = "paths"
version = "0.1.0"
version = "0.0.0"
[[package]]
name = "percent-encoding"
@ -890,6 +1074,66 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "proc_macro_api"
version = "0.0.0"
dependencies = [
"crossbeam-channel",
"jod-thread",
"log",
"serde",
"serde_json",
"tt",
]
[[package]]
name = "proc_macro_srv"
version = "0.0.0"
dependencies = [
"cargo_metadata",
"difference",
"goblin",
"libloading",
"mbe",
"memmap",
"proc_macro_api",
"serde_derive",
"test_utils",
"toolchain",
"tt",
]
[[package]]
name = "profile"
version = "0.0.0"
dependencies = [
"arena",
"backtrace",
"cfg-if",
"libc",
"once_cell",
"perf-event",
]
[[package]]
name = "project_model"
version = "0.0.0"
dependencies = [
"anyhow",
"arena",
"base_db",
"cargo_metadata",
"cfg",
"log",
"paths",
"proc_macro_api",
"rustc-hash",
"serde",
"serde_json",
"stdx",
"toolchain",
]
[[package]]
name = "quote"
version = "1.0.7"
@ -899,332 +1143,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "ra_arena"
version = "0.1.0"
[[package]]
name = "ra_assists"
version = "0.1.0"
dependencies = [
"either",
"itertools",
"ra_db",
"ra_fmt",
"ra_hir",
"ra_ide_db",
"ra_prof",
"ra_syntax",
"ra_text_edit",
"rustc-hash",
"stdx",
"test_utils",
]
[[package]]
name = "ra_cfg"
version = "0.1.0"
dependencies = [
"ra_mbe",
"ra_syntax",
"ra_tt",
"rustc-hash",
]
[[package]]
name = "ra_db"
version = "0.1.0"
dependencies = [
"ra_cfg",
"ra_prof",
"ra_syntax",
"ra_tt",
"rustc-hash",
"salsa",
"stdx",
"test_utils",
"vfs",
]
[[package]]
name = "ra_fmt"
version = "0.1.0"
dependencies = [
"itertools",
"ra_syntax",
]
[[package]]
name = "ra_hir"
version = "0.1.0"
dependencies = [
"arrayvec",
"either",
"itertools",
"log",
"ra_db",
"ra_hir_def",
"ra_hir_expand",
"ra_hir_ty",
"ra_prof",
"ra_syntax",
"rustc-hash",
"stdx",
]
[[package]]
name = "ra_hir_def"
version = "0.1.0"
dependencies = [
"anymap",
"drop_bomb",
"either",
"expect",
"fst",
"indexmap",
"itertools",
"log",
"once_cell",
"ra_arena",
"ra_cfg",
"ra_db",
"ra_hir_expand",
"ra_mbe",
"ra_prof",
"ra_syntax",
"ra_tt",
"rustc-hash",
"smallvec",
"stdx",
"test_utils",
]
[[package]]
name = "ra_hir_expand"
version = "0.1.0"
dependencies = [
"either",
"log",
"ra_arena",
"ra_db",
"ra_mbe",
"ra_parser",
"ra_prof",
"ra_syntax",
"ra_tt",
"rustc-hash",
"test_utils",
]
[[package]]
name = "ra_hir_ty"
version = "0.1.0"
dependencies = [
"arrayvec",
"chalk-ir",
"chalk-recursive",
"chalk-solve",
"ena",
"expect",
"itertools",
"log",
"ra_arena",
"ra_db",
"ra_hir_def",
"ra_hir_expand",
"ra_prof",
"ra_syntax",
"rustc-hash",
"scoped-tls",
"smallvec",
"stdx",
"test_utils",
"tracing",
"tracing-subscriber",
"tracing-tree",
]
[[package]]
name = "ra_ide"
version = "0.1.0"
dependencies = [
"either",
"expect",
"indexmap",
"itertools",
"log",
"oorandom",
"ra_assists",
"ra_cfg",
"ra_db",
"ra_fmt",
"ra_hir",
"ra_ide_db",
"ra_prof",
"ra_ssr",
"ra_syntax",
"ra_text_edit",
"rustc-hash",
"stdx",
"test_utils",
]
[[package]]
name = "ra_ide_db"
version = "0.1.0"
dependencies = [
"either",
"fst",
"log",
"once_cell",
"ra_db",
"ra_hir",
"ra_prof",
"ra_syntax",
"ra_text_edit",
"rayon",
"rustc-hash",
"stdx",
"test_utils",
]
[[package]]
name = "ra_mbe"
version = "0.1.0"
dependencies = [
"log",
"ra_parser",
"ra_syntax",
"ra_tt",
"rustc-hash",
"smallvec",
"test_utils",
]
[[package]]
name = "ra_parser"
version = "0.1.0"
dependencies = [
"drop_bomb",
]
[[package]]
name = "ra_proc_macro"
version = "0.1.0"
dependencies = [
"crossbeam-channel",
"jod-thread",
"log",
"ra_tt",
"serde",
"serde_json",
]
[[package]]
name = "ra_proc_macro_srv"
version = "0.1.0"
dependencies = [
"cargo_metadata",
"difference",
"goblin",
"libloading",
"memmap",
"ra_mbe",
"ra_proc_macro",
"ra_toolchain",
"ra_tt",
"serde_derive",
"test_utils",
]
[[package]]
name = "ra_prof"
version = "0.1.0"
dependencies = [
"backtrace",
"cfg-if",
"libc",
"once_cell",
"perf-event",
"ra_arena",
]
[[package]]
name = "ra_project_model"
version = "0.1.0"
dependencies = [
"anyhow",
"cargo_metadata",
"log",
"paths",
"ra_arena",
"ra_cfg",
"ra_db",
"ra_proc_macro",
"ra_toolchain",
"rustc-hash",
"serde",
"serde_json",
"stdx",
]
[[package]]
name = "ra_ssr"
version = "0.1.0"
dependencies = [
"expect",
"ra_db",
"ra_hir",
"ra_ide_db",
"ra_syntax",
"ra_text_edit",
"rustc-hash",
"test_utils",
]
[[package]]
name = "ra_syntax"
version = "0.1.0"
dependencies = [
"arrayvec",
"expect",
"itertools",
"once_cell",
"ra_parser",
"ra_text_edit",
"rayon",
"rowan",
"rustc-ap-rustc_lexer",
"rustc-hash",
"serde",
"smol_str",
"stdx",
"test_utils",
"walkdir",
]
[[package]]
name = "ra_text_edit"
version = "0.1.0"
dependencies = [
"text-size",
]
[[package]]
name = "ra_toolchain"
version = "0.1.0"
dependencies = [
"home",
]
[[package]]
name = "ra_tt"
version = "0.1.0"
dependencies = [
"smol_str",
"stdx",
]
[[package]]
name = "rayon"
version = "1.3.1"
@ -1262,10 +1180,7 @@ version = "1.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
@ -1298,45 +1213,45 @@ dependencies = [
[[package]]
name = "rust-analyzer"
version = "0.1.0"
version = "0.0.0"
dependencies = [
"anyhow",
"base_db",
"cfg",
"crossbeam-channel",
"env_logger",
"expect",
"flycheck",
"hir",
"hir_def",
"hir_ty",
"ide",
"ide_db",
"itertools",
"jod-thread",
"log",
"lsp-server",
"lsp-types",
"mbe",
"mimalloc",
"oorandom",
"parking_lot",
"pico-args",
"ra_cfg",
"ra_db",
"ra_hir",
"ra_hir_def",
"ra_hir_ty",
"ra_ide",
"ra_ide_db",
"ra_mbe",
"ra_proc_macro_srv",
"ra_prof",
"ra_project_model",
"ra_ssr",
"ra_syntax",
"ra_text_edit",
"ra_toolchain",
"ra_tt",
"proc_macro_srv",
"profile",
"project_model",
"rayon",
"rustc-hash",
"serde",
"serde_json",
"ssr",
"stdx",
"syntax",
"test_utils",
"text_edit",
"threadpool",
"toolchain",
"tt",
"vfs",
"vfs-notify",
"winapi 0.3.9",
@ -1457,18 +1372,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.114"
version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.114"
version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48"
dependencies = [
"proc-macro2",
"quote",
@ -1514,9 +1429,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.4.1"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
[[package]]
name = "smol_str"
@ -1527,9 +1442,23 @@ dependencies = [
"serde",
]
[[package]]
name = "ssr"
version = "0.0.0"
dependencies = [
"base_db",
"expect",
"hir",
"ide_db",
"rustc-hash",
"syntax",
"test_utils",
"text_edit",
]
[[package]]
name = "stdx"
version = "0.1.0"
version = "0.0.0"
[[package]]
name = "syn"
@ -1554,6 +1483,27 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "syntax"
version = "0.0.0"
dependencies = [
"arrayvec",
"expect",
"itertools",
"once_cell",
"parser",
"rayon",
"rowan",
"rustc-ap-rustc_lexer",
"rustc-hash",
"serde",
"smol_str",
"stdx",
"test_utils",
"text_edit",
"walkdir",
]
[[package]]
name = "termcolor"
version = "1.1.0"
@ -1565,7 +1515,7 @@ dependencies = [
[[package]]
name = "test_utils"
version = "0.1.0"
version = "0.0.0"
dependencies = [
"difference",
"rustc-hash",
@ -1580,6 +1530,13 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f03e7efdedc3bc78cb2337f1e2785c39e45f5ef762d9e4ebb137fff7380a6d8a"
[[package]]
name = "text_edit"
version = "0.0.0"
dependencies = [
"text-size",
]
[[package]]
name = "thin-dst"
version = "1.1.0"
@ -1620,11 +1577,18 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed"
[[package]]
name = "toolchain"
version = "0.0.0"
dependencies = [
"home",
]
[[package]]
name = "tracing"
version = "0.1.18"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0aae59226cf195d8e74d4b34beae1859257efb4e5fed3f147d2dc2c7d372178"
checksum = "6d79ca061b032d6ce30c660fded31189ca0b9922bf483cd70759f13a2d86786c"
dependencies = [
"cfg-if",
"tracing-attributes",
@ -1633,9 +1597,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.9"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b"
checksum = "1fe233f4227389ab7df5b32649239da7ebe0b281824b4e84b342d04d3fd8c25e"
dependencies = [
"proc-macro2",
"quote",
@ -1644,9 +1608,9 @@ dependencies = [
[[package]]
name = "tracing-core"
version = "0.1.13"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d593f98af59ebc017c0648f0117525db358745a8894a8d684e185ba3f45954f9"
checksum = "db63662723c316b43ca36d833707cc93dff82a02ba3d7e354f342682cc8b3545"
dependencies = [
"lazy_static",
]
@ -1674,9 +1638,9 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
version = "0.2.10"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7b33f8b2ef2ab0c3778c12646d9c42a24f7772bee4cdafc72199644a9f58fdc"
checksum = "abd165311cc4d7a555ad11cc77a37756df836182db0d81aac908c8184c584f40"
dependencies = [
"ansi_term",
"chrono",
@ -1687,6 +1651,7 @@ dependencies = [
"serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
"tracing-serde",
@ -1706,6 +1671,14 @@ dependencies = [
"tracing-subscriber",
]
[[package]]
name = "tt"
version = "0.0.0"
dependencies = [
"smol_str",
"stdx",
]
[[package]]
name = "ungrammar"
version = "1.1.1"
@ -1756,7 +1729,7 @@ dependencies = [
[[package]]
name = "vfs"
version = "0.1.0"
version = "0.0.0"
dependencies = [
"fst",
"paths",
@ -1765,7 +1738,7 @@ dependencies = [
[[package]]
name = "vfs-notify"
version = "0.1.0"
version = "0.0.0"
dependencies = [
"crossbeam-channel",
"jod-thread",

View File

@ -39,7 +39,7 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frls-2.2E0
* Website: https://rust-analyzer.github.io/
* Metrics: https://rust-analyzer.github.io/metrics/
* API docs: https://rust-analyzer.github.io/rust-analyzer/ra_ide/
* API docs: https://rust-analyzer.github.io/rust-analyzer/ide/
## License

View File

@ -1,9 +1,8 @@
status = [
"Rust (ubuntu-latest)",
"Rust (windows-latest)",
"Rust (macos-latest)",
# "Rust (macos-latest)",
"TypeScript (ubuntu-latest)",
"TypeScript (windows-latest)",
"TypeScript (macos-latest)",
]
delete_merged_branches = true

View File

@ -1,9 +1,9 @@
[package]
edition = "2018"
name = "ra_arena"
version = "0.1.0"
authors = ["rust-analyzer developers"]
name = "arena"
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false

23
crates/assists/Cargo.toml Normal file
View File

@ -0,0 +1,23 @@
[package]
name = "assists"
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false
[dependencies]
rustc-hash = "1.1.0"
itertools = "0.9.0"
either = "1.5.3"
stdx = { path = "../stdx" }
syntax = { path = "../syntax" }
text_edit = { path = "../text_edit" }
profile = { path = "../profile" }
base_db = { path = "../base_db" }
ide_db = { path = "../ide_db" }
hir = { path = "../hir" }
test_utils = { path = "../test_utils" }

View File

@ -3,19 +3,18 @@
use std::mem;
use algo::find_covering_element;
use base_db::{FileId, FileRange};
use hir::Semantics;
use ra_db::{FileId, FileRange};
use ra_fmt::{leading_indent, reindent};
use ra_ide_db::{
use ide_db::{
source_change::{SourceChange, SourceFileEdit},
RootDatabase,
};
use ra_syntax::{
use syntax::{
algo::{self, find_node_at_offset, SyntaxRewriter},
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize,
AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxToken, TextRange, TextSize,
TokenAtOffset,
};
use ra_text_edit::TextEditBuilder;
use text_edit::{TextEdit, TextEditBuilder};
use crate::{
assist_config::{AssistConfig, SnippetCap},
@ -214,7 +213,7 @@ pub(crate) struct AssistBuilder {
impl AssistBuilder {
pub(crate) fn new(file_id: FileId) -> AssistBuilder {
AssistBuilder {
edit: TextEditBuilder::default(),
edit: TextEdit::builder(),
file_id,
is_snippet: false,
change: SourceChange::default(),
@ -269,20 +268,6 @@ impl AssistBuilder {
pub(crate) fn replace_ast<N: AstNode>(&mut self, old: N, new: N) {
algo::diff(old.syntax(), new.syntax()).into_text_edit(&mut self.edit)
}
/// Replaces specified `node` of text with a given string, reindenting the
/// string to maintain `node`'s existing indent.
// FIXME: remove in favor of ra_syntax::edit::IndentLevel::increase_indent
pub(crate) fn replace_node_and_indent(
&mut self,
node: &SyntaxNode,
replace_with: impl Into<String>,
) {
let mut replace_with = replace_with.into();
if let Some(indent) = leading_indent(node) {
replace_with = reindent(&replace_with, &indent)
}
self.replace(node.text_range(), replace_with)
}
pub(crate) fn rewrite(&mut self, rewriter: SyntaxRewriter) {
let node = rewriter.rewrite_root().unwrap();
let new = rewriter.rewrite(&node);

View File

@ -2,13 +2,13 @@
use rustc_hash::FxHashMap;
use hir::{HirDisplay, PathResolution, SemanticsScope};
use ra_syntax::{
use syntax::{
algo::SyntaxRewriter,
ast::{self, AstNode},
};
pub trait AstTransform<'a> {
fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode>;
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode>;
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a>;
fn or<T: AstTransform<'a> + 'a>(self, other: T) -> Box<dyn AstTransform<'a> + 'a>
@ -22,7 +22,7 @@ pub trait AstTransform<'a> {
struct NullTransformer;
impl<'a> AstTransform<'a> for NullTransformer {
fn get_substitution(&self, _node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> {
fn get_substitution(&self, _node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
None
}
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
@ -101,10 +101,7 @@ impl<'a> SubstituteTypeParams<'a> {
Some(result)
}
}
fn get_substitution_inner(
&self,
node: &ra_syntax::SyntaxNode,
) -> Option<ra_syntax::SyntaxNode> {
fn get_substitution_inner(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
let type_ref = ast::Type::cast(node.clone())?;
let path = match &type_ref {
ast::Type::PathType(path_type) => path_type.path()?,
@ -122,7 +119,7 @@ impl<'a> SubstituteTypeParams<'a> {
}
impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> {
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
}
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
@ -141,10 +138,7 @@ impl<'a> QualifyPaths<'a> {
Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
}
fn get_substitution_inner(
&self,
node: &ra_syntax::SyntaxNode,
) -> Option<ra_syntax::SyntaxNode> {
fn get_substitution_inner(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
// FIXME handle value ns?
let from = self.target_scope.module()?;
let p = ast::Path::cast(node.clone())?;
@ -183,7 +177,7 @@ impl<'a> QualifyPaths<'a> {
pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
SyntaxRewriter::from_fn(|element| match element {
ra_syntax::SyntaxElement::Node(n) => {
syntax::SyntaxElement::Node(n) => {
let replacement = transformer.get_substitution(&n)?;
Some(replacement.into())
}
@ -193,7 +187,7 @@ pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
}
impl<'a> AstTransform<'a> for QualifyPaths<'a> {
fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> {
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
}
fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {

View File

@ -1,5 +1,5 @@
use itertools::Itertools;
use ra_syntax::{
use syntax::{
ast::{self, AstNode},
Direction, SmolStr,
SyntaxKind::{IDENT, WHITESPACE},

View File

@ -1,5 +1,5 @@
use hir::HirDisplay;
use ra_syntax::{
use syntax::{
ast::{self, AstNode, LetStmt, NameOwner},
TextRange,
};

View File

@ -1,5 +1,5 @@
use hir::HasSource;
use ra_syntax::{
use syntax::{
ast::{
self,
edit::{self, AstNodeEdit, IndentLevel},
@ -110,7 +110,7 @@ fn add_missing_impl_members_inner(
assist_id: &'static str,
label: &'static str,
) -> Option<()> {
let _p = ra_prof::profile("add_missing_impl_members_inner");
let _p = profile::span("add_missing_impl_members_inner");
let impl_def = ctx.find_node_at_offset::<ast::Impl>()?;
let impl_item_list = impl_def.assoc_item_list()?;

View File

@ -1,5 +1,5 @@
use ra_ide_db::defs::{classify_name_ref, Definition, NameRefClass};
use ra_syntax::{ast, AstNode, SyntaxKind, T};
use ide_db::defs::{classify_name_ref, Definition, NameRefClass};
use syntax::{ast, AstNode, SyntaxKind, T};
use test_utils::mark;
use crate::{

View File

@ -1,4 +1,4 @@
use ra_syntax::ast::{self, AstNode};
use syntax::ast::{self, AstNode};
use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKind, Assists};

View File

@ -5,13 +5,12 @@ use hir::{
AsAssocItem, AssocItemContainer, ModPath, Module, ModuleDef, PathResolution, Semantics, Trait,
Type,
};
use ra_ide_db::{imports_locator, RootDatabase};
use ra_prof::profile;
use ra_syntax::{
use ide_db::{imports_locator, RootDatabase};
use rustc_hash::FxHashSet;
use syntax::{
ast::{self, AstNode},
SyntaxNode,
};
use rustc_hash::FxHashSet;
use crate::{
utils::insert_use_statement, AssistContext, AssistId, AssistKind, Assists, GroupLabel,
@ -130,7 +129,7 @@ impl AutoImportAssets {
}
fn search_for_imports(&self, ctx: &AssistContext) -> BTreeSet<ModPath> {
let _p = profile("auto_import::search_for_imports");
let _p = profile::span("auto_import::search_for_imports");
let db = ctx.db();
let current_crate = self.module_with_name_to_import.krate();
imports_locator::find_imports(&ctx.sema, current_crate, &self.get_search_query())

View File

@ -1,10 +1,12 @@
use ra_syntax::{
ast::{self, BlockExpr, Expr, LoopBodyOwner},
use std::iter;
use syntax::{
ast::{self, make, BlockExpr, Expr, LoopBodyOwner},
AstNode, SyntaxNode,
};
use test_utils::mark;
use crate::{AssistContext, AssistId, AssistKind, Assists};
use test_utils::mark;
// Assist: change_return_type_to_result
//
@ -44,7 +46,13 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex
tail_return_expr_collector.collect_tail_exprs(block_expr);
for ret_expr_arg in tail_return_expr_collector.exprs_to_wrap {
builder.replace_node_and_indent(&ret_expr_arg, format!("Ok({})", ret_expr_arg));
let ok_wrapped = make::expr_call(
make::expr_path(make::path_unqualified(make::path_segment(make::name_ref(
"Ok",
)))),
make::arg_list(iter::once(ret_expr_arg.clone())),
);
builder.replace_ast(ret_expr_arg, ok_wrapped);
}
match ctx.config.snippet_cap {
@ -60,7 +68,7 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex
}
struct TailReturnCollector {
exprs_to_wrap: Vec<SyntaxNode>,
exprs_to_wrap: Vec<ast::Expr>,
}
impl TailReturnCollector {
@ -86,7 +94,8 @@ impl TailReturnCollector {
if let Some(last_exprs) = get_tail_expr_from_block(&expr) {
for last_expr in last_exprs {
let last_expr = match last_expr {
NodeType::Node(expr) | NodeType::Leaf(expr) => expr,
NodeType::Node(expr) => expr,
NodeType::Leaf(expr) => expr.syntax().clone(),
};
if let Some(last_expr) = Expr::cast(last_expr.clone()) {
@ -113,12 +122,12 @@ impl TailReturnCollector {
}
Expr::ReturnExpr(ret_expr) => {
if let Some(ret_expr_arg) = &ret_expr.expr() {
self.exprs_to_wrap.push(ret_expr_arg.syntax().clone());
self.exprs_to_wrap.push(ret_expr_arg.clone());
}
}
Expr::BreakExpr(break_expr) if collect_break => {
if let Some(break_expr_arg) = &break_expr.expr() {
self.exprs_to_wrap.push(break_expr_arg.syntax().clone());
self.exprs_to_wrap.push(break_expr_arg.clone());
}
}
Expr::IfExpr(if_expr) => {
@ -166,14 +175,11 @@ impl TailReturnCollector {
NodeType::Leaf(expr) => {
self.exprs_to_wrap.push(expr.clone());
}
NodeType::Node(expr) => match &Expr::cast(expr.clone()) {
Some(last_expr) => {
self.fetch_tail_exprs(last_expr);
NodeType::Node(expr) => {
if let Some(last_expr) = Expr::cast(expr.clone()) {
self.fetch_tail_exprs(&last_expr);
}
None => {
self.exprs_to_wrap.push(expr.clone());
}
},
}
}
}
}
@ -182,7 +188,7 @@ impl TailReturnCollector {
#[derive(Debug)]
enum NodeType {
Leaf(SyntaxNode),
Leaf(ast::Expr),
Node(SyntaxNode),
}
@ -233,25 +239,26 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
Some(arms)
}
Expr::BreakExpr(expr) => expr.expr().map(|e| vec![NodeType::Leaf(e.syntax().clone())]),
Expr::BreakExpr(expr) => expr.expr().map(|e| vec![NodeType::Leaf(e)]),
Expr::ReturnExpr(ret_expr) => Some(vec![NodeType::Node(ret_expr.syntax().clone())]),
Expr::CallExpr(call_expr) => Some(vec![NodeType::Leaf(call_expr.syntax().clone())]),
Expr::Literal(lit_expr) => Some(vec![NodeType::Leaf(lit_expr.syntax().clone())]),
Expr::TupleExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::ArrayExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::RecordExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::AwaitExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::CastExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::RefExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::PrefixExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::RangeExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::BinExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::MacroCall(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::BoxExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::CallExpr(_)
| Expr::Literal(_)
| Expr::TupleExpr(_)
| Expr::ArrayExpr(_)
| Expr::ParenExpr(_)
| Expr::PathExpr(_)
| Expr::RecordExpr(_)
| Expr::IndexExpr(_)
| Expr::MethodCallExpr(_)
| Expr::AwaitExpr(_)
| Expr::CastExpr(_)
| Expr::RefExpr(_)
| Expr::PrefixExpr(_)
| Expr::RangeExpr(_)
| Expr::BinExpr(_)
| Expr::MacroCall(_)
| Expr::BoxExpr(_) => Some(vec![NodeType::Leaf(expr.clone())]),
_ => None,
}
}

View File

@ -1,4 +1,4 @@
use ra_syntax::{
use syntax::{
ast::{self, NameOwner, VisibilityOwner},
AstNode,
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, VISIBILITY},

View File

@ -1,6 +1,6 @@
use std::{iter::once, ops::RangeInclusive};
use ra_syntax::{
use syntax::{
algo::replace_children,
ast::{
self,

View File

@ -1,9 +1,9 @@
use hir::{AssocItem, MacroDef, ModuleDef, Name, PathResolution, ScopeDef, SemanticsScope};
use ra_ide_db::{
use ide_db::{
defs::{classify_name_ref, Definition, NameRefClass},
RootDatabase,
};
use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxNode, SyntaxToken, T};
use syntax::{algo, ast, match_ast, AstNode, SyntaxNode, SyntaxToken, T};
use crate::{
assist_context::{AssistBuilder, AssistContext, Assists},

View File

@ -1,13 +1,12 @@
use base_db::FileId;
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 ra_syntax::{
algo::find_node_at_offset,
ast::{self, ArgListOwner, AstNode, NameOwner, VisibilityOwner},
SourceFile, SyntaxNode, TextRange, TextSize,
};
use ide_db::{defs::Definition, search::Reference, RootDatabase};
use rustc_hash::FxHashSet;
use syntax::{
algo::find_node_at_offset,
ast::{self, edit::IndentLevel, ArgListOwner, AstNode, NameOwner, VisibilityOwner},
SourceFile, TextRange, TextSize,
};
use crate::{
assist_context::AssistBuilder, utils::insert_use_statement, AssistContext, AssistId,
@ -72,7 +71,7 @@ pub(crate) fn extract_struct_from_enum_variant(
}
extract_struct_def(
builder,
enum_ast.syntax(),
&enum_ast,
&variant_name,
&field_list.to_string(),
start_offset,
@ -112,9 +111,10 @@ fn insert_import(
Some(())
}
// FIXME: this should use strongly-typed `make`, rather than string manipulation.
fn extract_struct_def(
builder: &mut AssistBuilder,
enum_ast: &SyntaxNode,
enum_: &ast::Enum,
variant_name: &str,
variant_list: &str,
start_offset: TextSize,
@ -126,11 +126,7 @@ fn extract_struct_def(
} else {
"".to_string()
};
let indent = if let Some(indent) = leading_indent(enum_ast) {
indent.to_string()
} else {
"".to_string()
};
let indent = IndentLevel::from_node(enum_.syntax());
let struct_def = format!(
r#"{}struct {}{};

View File

@ -1,11 +1,11 @@
use ra_syntax::{
use stdx::format_to;
use syntax::{
ast::{self, AstNode},
SyntaxKind::{
BLOCK_EXPR, BREAK_EXPR, CLOSURE_EXPR, COMMENT, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
},
SyntaxNode,
};
use stdx::format_to;
use test_utils::mark;
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,9 +1,9 @@
use std::iter;
use hir::{Adt, HasSource, ModuleDef, Semantics};
use ide_db::RootDatabase;
use itertools::Itertools;
use ra_ide_db::RootDatabase;
use ra_syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat};
use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat};
use test_utils::mark;
use crate::{

View File

@ -1,6 +1,6 @@
use base_db::FileId;
use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution};
use ra_db::FileId;
use ra_syntax::{ast, AstNode, TextRange, TextSize};
use syntax::{ast, AstNode, TextRange, TextSize};
use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
use ast::VisibilityOwner;

View File

@ -1,4 +1,4 @@
use ra_syntax::ast::{AstNode, BinExpr, BinOp};
use syntax::ast::{AstNode, BinExpr, BinOp};
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,4 +1,4 @@
use ra_syntax::{algo::non_trivia_sibling, Direction, T};
use syntax::{algo::non_trivia_sibling, Direction, T};
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,4 +1,4 @@
use ra_syntax::{
use syntax::{
algo::non_trivia_sibling,
ast::{self, AstNode},
Direction, T,

View File

@ -1,4 +1,4 @@
use ra_syntax::{
use syntax::{
ast::{self, AstNode, AttrsOwner},
SyntaxKind::{COMMENT, WHITESPACE},
TextSize,

View File

@ -1,5 +1,5 @@
use ra_ide_db::RootDatabase;
use ra_syntax::ast::{self, AstNode, NameOwner};
use ide_db::RootDatabase;
use syntax::ast::{self, AstNode, NameOwner};
use test_utils::mark;
use crate::{utils::FamousDefs, AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,6 +1,7 @@
use base_db::FileId;
use hir::HirDisplay;
use ra_db::FileId;
use ra_syntax::{
use rustc_hash::{FxHashMap, FxHashSet};
use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},
@ -8,7 +9,6 @@ use ra_syntax::{
},
SyntaxKind, SyntaxNode, TextSize,
};
use rustc_hash::{FxHashMap, FxHashSet};
use crate::{
assist_config::SnippetCap,

View File

@ -1,6 +1,6 @@
use itertools::Itertools;
use ra_syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner};
use stdx::format_to;
use syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner};
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,10 +1,10 @@
use hir::Adt;
use itertools::Itertools;
use ra_syntax::{
use stdx::format_to;
use syntax::{
ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner},
T,
};
use stdx::format_to;
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,5 +1,5 @@
use ra_ide_db::defs::Definition;
use ra_syntax::{
use ide_db::defs::Definition;
use syntax::{
ast::{self, AstNode, AstToken},
TextRange,
};

View File

@ -1,8 +1,8 @@
use ra_syntax::{
use rustc_hash::FxHashSet;
use syntax::{
ast::{self, GenericParamsOwner, NameOwner},
AstNode, SyntaxKind, TextRange, TextSize,
};
use rustc_hash::FxHashSet;
use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,4 +1,4 @@
use ra_syntax::{
use syntax::{
ast::{self, AstNode},
T,
};

View File

@ -1,6 +1,6 @@
use std::iter::successors;
use ra_syntax::{
use syntax::{
algo::{neighbor, skip_trivia_token, SyntaxRewriter},
ast::{self, edit::AstNodeEdit, make},
AstNode, Direction, InsertPosition, SyntaxElement, T,
@ -164,6 +164,33 @@ use std::fmt::{Display, Debug};
);
}
#[test]
fn merge_self1() {
check_assist(
merge_imports,
r"
use std::fmt<|>;
use std::fmt::Display;
",
r"
use std::fmt::{self, Display};
",
);
}
#[test]
fn merge_self2() {
check_assist(
merge_imports,
r"
use std::{fmt, <|>fmt::Display};
",
r"
use std::{fmt::{Display, self}};
",
);
}
#[test]
fn test_merge_nested() {
check_assist(

View File

@ -1,6 +1,6 @@
use std::iter::successors;
use ra_syntax::{
use syntax::{
algo::neighbor,
ast::{self, AstNode},
Direction,

View File

@ -1,4 +1,4 @@
use ra_syntax::{
use syntax::{
ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner, TypeBoundsOwner},
match_ast,
SyntaxKind::*,

View File

@ -1,5 +1,5 @@
use ra_syntax::{
ast::{AstNode, IfExpr, MatchArm},
use syntax::{
ast::{edit::AstNodeEdit, make, AstNode, IfExpr, MatchArm},
SyntaxKind::WHITESPACE,
};
@ -25,7 +25,9 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// fn handle(action: Action) {
// match action {
// Action::Move { distance } => if distance > 10 { foo() },
// Action::Move { distance } => if distance > 10 {
// foo()
// },
// _ => (),
// }
// }
@ -35,9 +37,13 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
let guard = match_arm.guard()?;
let space_before_guard = guard.syntax().prev_sibling_or_token();
let guard_conditions = guard.expr()?;
let guard_condition = guard.expr()?;
let arm_expr = match_arm.expr()?;
let buf = format!("if {} {{ {} }}", guard_conditions.syntax().text(), arm_expr.syntax().text());
let if_expr = make::expr_if(
make::condition(guard_condition, None),
make::block_expr(None, Some(arm_expr.clone())),
)
.indent(arm_expr.indent_level());
let target = guard.syntax().text_range();
acc.add(
@ -53,7 +59,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
};
edit.delete(guard.syntax().text_range());
edit.replace_node_and_indent(arm_expr.syntax(), buf);
edit.replace_ast(arm_expr, if_expr);
},
)
}
@ -134,16 +140,14 @@ mod tests {
check_assist_target(
move_guard_to_arm_body,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' <|>if chars.clone().next() == Some('\n') => false,
_ => true
}
}
"#,
r#"if chars.clone().next() == Some('\n')"#,
fn main() {
match 92 {
x <|>if x > 10 => false,
_ => true
}
}
"#,
r#"if x > 10"#,
);
}
@ -152,25 +156,23 @@ mod tests {
check_assist(
move_guard_to_arm_body,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' <|>if chars.clone().next() == Some('\n') => false,
_ => true
}
}
"#,
fn main() {
match 92 {
x <|>if x > 10 => false,
_ => true
}
}
"#,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' => if chars.clone().next() == Some('\n') { false },
_ => true
}
}
"#,
fn main() {
match 92 {
x => if x > 10 {
false
},
_ => true
}
}
"#,
);
}
@ -179,21 +181,23 @@ mod tests {
check_assist(
move_guard_to_arm_body,
r#"
fn f() {
match x {
<|>y @ 4 | y @ 5 if y > 5 => true,
_ => false
}
}
"#,
fn main() {
match 92 {
<|>x @ 4 | x @ 5 if x > 5 => true,
_ => false
}
}
"#,
r#"
fn f() {
match x {
y @ 4 | y @ 5 => if y > 5 { true },
_ => false
}
}
"#,
fn main() {
match 92 {
x @ 4 | x @ 5 => if x > 5 {
true
},
_ => false
}
}
"#,
);
}
@ -202,25 +206,21 @@ mod tests {
check_assist(
move_arm_cond_to_match_guard,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' => if chars.clone().next() == Some('\n') { <|>false },
_ => true
}
}
"#,
fn main() {
match 92 {
x => if x > 10 { <|>false },
_ => true
}
}
"#,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' if chars.clone().next() == Some('\n') => false,
_ => true
}
}
"#,
fn main() {
match 92 {
x if x > 10 => false,
_ => true
}
}
"#,
);
}
@ -229,15 +229,13 @@ mod tests {
check_assist_not_applicable(
move_arm_cond_to_match_guard,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' => if let Some(_) = chars.clone().next() { <|>false },
_ => true
}
}
"#,
fn main() {
match 92 {
x => if let 62 = x { <|>false },
_ => true
}
}
"#,
);
}
@ -246,25 +244,21 @@ mod tests {
check_assist(
move_arm_cond_to_match_guard,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' => if chars.clone().next().is_some() { <|> },
_ => true
}
}
"#,
fn main() {
match 92 {
x => if x > 10 { <|> },
_ => true
}
}
"#,
r#"
fn f() {
let t = 'a';
let chars = "abcd";
match t {
'\r' if chars.clone().next().is_some() => { },
_ => true
}
}
"#,
fn main() {
match 92 {
x if x > 10 => { },
_ => true
}
}
"#,
);
}
@ -273,31 +267,27 @@ mod tests {
check_assist(
move_arm_cond_to_match_guard,
r#"
fn f() {
let mut t = 'a';
let chars = "abcd";
match t {
'\r' => if chars.clone().next().is_some() {
t = 'e';<|>
false
},
_ => true
}
}
"#,
fn main() {
match 92 {
x => if x > 10 {
92;<|>
false
},
_ => true
}
}
"#,
r#"
fn f() {
let mut t = 'a';
let chars = "abcd";
match t {
'\r' if chars.clone().next().is_some() => {
t = 'e';
false
},
_ => true
}
}
"#,
fn main() {
match 92 {
x if x > 10 => {
92;
false
},
_ => true
}
}
"#,
);
}
}

View File

@ -1,6 +1,6 @@
use std::borrow::Cow;
use ra_syntax::{
use syntax::{
ast::{self, HasQuotes, HasStringValue},
AstToken,
SyntaxKind::{RAW_STRING, STRING},

View File

@ -1,4 +1,4 @@
use ra_syntax::{
use syntax::{
ast::{self, AstNode},
TextRange, TextSize, T,
};

View File

@ -1,4 +1,4 @@
use ra_syntax::{SyntaxKind, TextRange, T};
use syntax::{SyntaxKind, TextRange, T};
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -2,8 +2,8 @@ use itertools::Itertools;
use rustc_hash::FxHashMap;
use hir::{Adt, ModuleDef, PathResolution, Semantics, Struct};
use ra_ide_db::RootDatabase;
use ra_syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode};
use ide_db::RootDatabase;
use syntax::{algo, ast, match_ast, AstNode, SyntaxKind, SyntaxKind::*, SyntaxNode};
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,5 +1,4 @@
use ra_fmt::unwrap_trivial_block;
use ra_syntax::{
use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},
@ -8,7 +7,10 @@ use ra_syntax::{
AstNode,
};
use crate::{utils::TryEnum, AssistContext, AssistId, AssistKind, Assists};
use crate::{
utils::{unwrap_trivial_block, TryEnum},
AssistContext, AssistId, AssistKind, Assists,
};
// Assist: replace_if_let_with_match
//

View File

@ -1,6 +1,6 @@
use std::iter::once;
use ra_syntax::{
use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},

View File

@ -1,5 +1,5 @@
use hir;
use ra_syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SmolStr, SyntaxNode};
use syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SmolStr, SyntaxNode};
use crate::{
utils::{find_insert_use_container, insert_use_statement},

View File

@ -1,6 +1,6 @@
use std::iter;
use ra_syntax::{
use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},

View File

@ -1,6 +1,6 @@
use std::iter::successors;
use ra_syntax::{ast, AstNode, T};
use syntax::{ast, AstNode, T};
use crate::{AssistContext, AssistId, AssistKind, Assists};

View File

@ -1,5 +1,4 @@
use ra_fmt::unwrap_trivial_block;
use ra_syntax::{
use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},
@ -7,7 +6,7 @@ use ra_syntax::{
AstNode, TextRange, T,
};
use crate::{AssistContext, AssistId, AssistKind, Assists};
use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, Assists};
// Assist: unwrap_block
//

View File

@ -1,4 +1,4 @@
//! `ra_assists` crate provides a bunch of code assists, also known as code
//! `assists` crate provides a bunch of code assists, also known as code
//! actions (in LSP) or intentions (in IntelliJ).
//!
//! An assist is a micro-refactoring, which is automatically activated in
@ -17,10 +17,10 @@ mod tests;
pub mod utils;
pub mod ast_transform;
use base_db::FileRange;
use hir::Semantics;
use ra_db::FileRange;
use ra_ide_db::{source_change::SourceChange, RootDatabase};
use ra_syntax::TextRange;
use ide_db::{source_change::SourceChange, RootDatabase};
use syntax::TextRange;
pub(crate) use crate::assist_context::{AssistContext, Assists};

View File

@ -1,9 +1,9 @@
mod generated;
use base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
use hir::Semantics;
use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
use ra_ide_db::RootDatabase;
use ra_syntax::TextRange;
use ide_db::RootDatabase;
use syntax::TextRange;
use test_utils::{assert_eq_text, extract_offset, extract_range};
use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists};

View File

@ -690,7 +690,9 @@ enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } => if distance > 10 { foo() },
Action::Move { distance } => if distance > 10 {
foo()
},
_ => (),
}
}

View File

@ -4,19 +4,57 @@ pub(crate) mod insert_use;
use std::{iter, ops};
use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type};
use ra_ide_db::RootDatabase;
use ra_syntax::{
use ide_db::RootDatabase;
use itertools::Itertools;
use rustc_hash::FxHashSet;
use syntax::{
ast::{self, make, NameOwner},
AstNode,
SyntaxKind::*,
SyntaxNode, TextSize, T,
};
use rustc_hash::FxHashSet;
use crate::assist_config::SnippetCap;
pub(crate) use insert_use::{find_insert_use_container, insert_use_statement};
pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
extract_trivial_expression(&block)
.filter(|expr| !expr.syntax().text().contains_char('\n'))
.unwrap_or_else(|| block.into())
}
pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
let has_anything_else = |thing: &SyntaxNode| -> bool {
let mut non_trivial_children =
block.syntax().children_with_tokens().filter(|it| match it.kind() {
WHITESPACE | T!['{'] | T!['}'] => false,
_ => it.as_node() != Some(thing),
});
non_trivial_children.next().is_some()
};
if let Some(expr) = block.expr() {
if has_anything_else(expr.syntax()) {
return None;
}
return Some(expr);
}
// Unwrap `{ continue; }`
let (stmt,) = block.statements().next_tuple()?;
if let ast::Stmt::ExprStmt(expr_stmt) = stmt {
if has_anything_else(expr_stmt.syntax()) {
return None;
}
let expr = expr_stmt.expr()?;
match expr.syntax().kind() {
CONTINUE_EXPR | BREAK_EXPR | RETURN_EXPR => return Some(expr),
_ => (),
}
}
None
}
#[derive(Clone, Copy, Debug)]
pub(crate) enum Cursor<'a> {
Replace(&'a SyntaxNode),

View File

@ -2,17 +2,19 @@
// 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 ra_syntax::{
use syntax::{
ast::{self, NameOwner, VisibilityOwner},
AstNode, Direction, SmolStr,
AstNode, AstToken, Direction, SmolStr,
SyntaxKind::{PATH, PATH_SEGMENT},
SyntaxNode, T,
SyntaxNode, SyntaxToken, T,
};
use ra_text_edit::TextEditBuilder;
use text_edit::TextEditBuilder;
use crate::assist_context::AssistContext;
use either::Either;
/// Determines the containing syntax node in which to insert a `use` statement affecting `position`.
pub(crate) fn find_insert_use_container(
@ -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())
}
}

View File

@ -1,9 +1,9 @@
[package]
edition = "2018"
name = "ra_db"
version = "0.1.0"
authors = ["rust-analyzer developers"]
name = "base_db"
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false
@ -12,10 +12,10 @@ doctest = false
salsa = "0.15.2"
rustc-hash = "1.1.0"
ra_syntax = { path = "../ra_syntax" }
ra_cfg = { path = "../ra_cfg" }
ra_prof = { path = "../ra_prof" }
ra_tt = { path = "../ra_tt" }
syntax = { path = "../syntax" }
cfg = { path = "../cfg" }
profile = { path = "../profile" }
tt = { path = "../tt" }
test_utils = { path = "../test_utils" }
vfs = { path = "../vfs" }
stdx = { path = "../stdx" }

View File

@ -59,7 +59,7 @@
//! ```
use std::{str::FromStr, sync::Arc};
use ra_cfg::CfgOptions;
use cfg::CfgOptions;
use rustc_hash::FxHashMap;
use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER};
use vfs::{file_set::FileSet, VfsPath};

View File

@ -8,10 +8,10 @@
use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc};
use ra_cfg::CfgOptions;
use ra_syntax::SmolStr;
use ra_tt::TokenExpander;
use cfg::CfgOptions;
use rustc_hash::{FxHashMap, FxHashSet};
use syntax::SmolStr;
use tt::TokenExpander;
use vfs::file_set::FileSet;
pub use vfs::FileId;
@ -156,7 +156,7 @@ impl CrateGraph {
display_name: Option<String>,
cfg_options: CfgOptions,
env: Env,
proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>,
proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
) -> CrateId {
let proc_macro =
proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect();

View File

@ -1,13 +1,12 @@
//! ra_db defines basic database traits. The concrete DB is defined by ra_ide.
//! base_db defines basic database traits. The concrete DB is defined by ide.
mod cancellation;
mod input;
pub mod fixture;
use std::{panic, sync::Arc};
use ra_prof::profile;
use ra_syntax::{ast, Parse, SourceFile, TextRange, TextSize};
use rustc_hash::FxHashSet;
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
pub use crate::{
cancellation::Canceled,
@ -113,7 +112,7 @@ pub trait SourceDatabase: CheckCanceled + FileLoader + std::fmt::Debug {
}
fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
let _p = profile("parse_query").detail(|| format!("{:?}", file_id));
let _p = profile::span("parse_query").detail(|| format!("{:?}", file_id));
let text = db.file_text(file_id);
SourceFile::parse(&*text)
}

View File

@ -1,9 +1,9 @@
[package]
edition = "2018"
name = "ra_cfg"
version = "0.1.0"
authors = ["rust-analyzer developers"]
name = "cfg"
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false
@ -11,8 +11,8 @@ doctest = false
[dependencies]
rustc-hash = "1.1.0"
ra_syntax = { path = "../ra_syntax" }
tt = { path = "../ra_tt", package = "ra_tt" }
tt = { path = "../tt" }
[dev-dependencies]
mbe = { path = "../ra_mbe", package = "ra_mbe" }
mbe = { path = "../mbe" }
syntax = { path = "../syntax" }

View File

@ -4,7 +4,7 @@
use std::slice::Iter as SliceIter;
use ra_syntax::SmolStr;
use tt::SmolStr;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CfgExpr {
@ -86,17 +86,15 @@ fn next_cfg_expr(it: &mut SliceIter<tt::TokenTree>) -> Option<CfgExpr> {
mod tests {
use super::*;
use mbe::{ast_to_token_tree, TokenMap};
use ra_syntax::ast::{self, AstNode};
fn get_token_tree_generated(input: &str) -> (tt::Subtree, TokenMap) {
let source_file = ast::SourceFile::parse(input).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
ast_to_token_tree(&tt).unwrap()
}
use mbe::ast_to_token_tree;
use syntax::ast::{self, AstNode};
fn assert_parse_result(input: &str, expected: CfgExpr) {
let (tt, _) = get_token_tree_generated(input);
let (tt, _) = {
let source_file = ast::SourceFile::parse(input).ok().unwrap();
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
ast_to_token_tree(&tt).unwrap()
};
let cfg = CfgExpr::parse(&tt);
assert_eq!(cfg, expected);
}

View File

@ -1,9 +1,9 @@
//! ra_cfg defines conditional compiling options, `cfg` attibute parser and evaluator
//! cfg defines conditional compiling options, `cfg` attibute parser and evaluator
mod cfg_expr;
use ra_syntax::SmolStr;
use rustc_hash::FxHashSet;
use tt::SmolStr;
pub use cfg_expr::CfgExpr;

View File

@ -1,9 +1,9 @@
[package]
name = "expect"
version = "0.1.0"
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
license = "MIT OR Apache-2.0"
[lib]
doctest = false
@ -11,4 +11,5 @@ doctest = false
[dependencies]
once_cell = "1"
difference = "2"
stdx = { path = "../stdx" }

View File

@ -1,9 +1,9 @@
[package]
edition = "2018"
name = "flycheck"
version = "0.1.0"
authors = ["rust-analyzer developers"]
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false
@ -14,4 +14,5 @@ log = "0.4.8"
cargo_metadata = "0.11.1"
serde_json = "1.0.48"
jod-thread = "0.1.1"
ra_toolchain = { path = "../ra_toolchain" }
toolchain = { path = "../toolchain" }

View File

@ -193,7 +193,7 @@ impl FlycheckActor {
extra_args,
features,
} => {
let mut cmd = Command::new(ra_toolchain::cargo());
let mut cmd = Command::new(toolchain::cargo());
cmd.arg(command);
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
.arg(self.workspace_root.join("Cargo.toml"));

24
crates/hir/Cargo.toml Normal file
View File

@ -0,0 +1,24 @@
[package]
name = "hir"
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false
[dependencies]
log = "0.4.8"
rustc-hash = "1.1.0"
either = "1.5.3"
arrayvec = "0.5.1"
itertools = "0.9.0"
stdx = { path = "../stdx" }
syntax = { path = "../syntax" }
base_db = { path = "../base_db" }
profile = { path = "../profile" }
hir_expand = { path = "../hir_expand" }
hir_def = { path = "../hir_def" }
hir_ty = { path = "../hir_ty" }

View File

@ -2,6 +2,7 @@
use std::{iter, sync::Arc};
use arrayvec::ArrayVec;
use base_db::{CrateId, Edition, FileId};
use either::Either;
use hir_def::{
adt::ReprKind,
@ -30,14 +31,12 @@ use hir_ty::{
method_resolution, ApplicationTy, CallableDefId, Canonical, FnSig, GenericPredicate,
InEnvironment, Substs, TraitEnvironment, Ty, TyDefId, TypeCtor,
};
use ra_db::{CrateId, Edition, FileId};
use ra_prof::profile;
use ra_syntax::{
use rustc_hash::FxHashSet;
use stdx::impl_from;
use syntax::{
ast::{self, AttrsOwner, NameOwner},
AstNode,
};
use rustc_hash::FxHashSet;
use stdx::impl_from;
use crate::{
db::{DefDatabase, HirDatabase},
@ -304,7 +303,7 @@ impl Module {
}
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
let _p = profile("Module::diagnostics");
let _p = profile::span("Module::diagnostics");
let crate_def_map = db.crate_def_map(self.id.krate);
crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink);
for decl in self.declarations(db) {
@ -816,7 +815,7 @@ pub struct MacroDef {
impl MacroDef {
/// FIXME: right now, this just returns the root module of the crate that
/// defines this macro. The reasons for this is that macros are expanded
/// early, in `ra_hir_expand`, where modules simply do not exist yet.
/// early, in `hir_expand`, where modules simply do not exist yet.
pub fn module(self, db: &dyn HirDatabase) -> Option<Module> {
let krate = self.id.krate?;
let module_id = db.crate_def_map(krate).root;
@ -884,6 +883,13 @@ where
}
impl AssocItem {
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
match self {
AssocItem::Function(it) => Some(it.name(db)),
AssocItem::Const(it) => it.name(db),
AssocItem::TypeAlias(it) => Some(it.name(db)),
}
}
pub fn module(self, db: &dyn HirDatabase) -> Module {
match self {
AssocItem::Function(f) => f.module(db),

View File

@ -29,7 +29,7 @@ macro_rules! from_id {
}
from_id![
(ra_db::CrateId, crate::Crate),
(base_db::CrateId, crate::Crate),
(hir_def::ModuleId, crate::Module),
(hir_def::StructId, crate::Struct),
(hir_def::UnionId, crate::Union),

View File

@ -6,7 +6,7 @@ use hir_def::{
src::{HasChildSource, HasSource as _},
Lookup, VariantId,
};
use ra_syntax::ast;
use syntax::ast;
use crate::{
db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, ImplDef, MacroDef,

View File

@ -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.
@ -52,8 +52,12 @@ pub use hir_def::{
type_ref::{Mutability, TypeRef},
};
pub use hir_expand::{
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc,
MacroDefId, /* FIXME */
name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, /* FIXME */ MacroDefId,
MacroFile, Origin,
};
pub use hir_ty::display::HirDisplay;
// These are negative re-exports: pub using these names is forbidden, they
// should remain private to hir internals.
#[allow(unused)]
use hir_expand::hygiene::Hygiene;

View File

@ -4,6 +4,7 @@ mod source_to_def;
use std::{cell::RefCell, fmt, iter::successors};
use base_db::{FileId, FileRange};
use hir_def::{
resolver::{self, HasResolver, Resolver},
AsMacroCall, FunctionId, TraitId, VariantId,
@ -11,13 +12,11 @@ use hir_def::{
use hir_expand::{hygiene::Hygiene, name::AsName, ExpansionInfo};
use hir_ty::associated_type_shorthand_candidates;
use itertools::Itertools;
use ra_db::{FileId, FileRange};
use ra_prof::profile;
use ra_syntax::{
use rustc_hash::{FxHashMap, FxHashSet};
use syntax::{
algo::{find_node_at_offset, skip_trivia_token},
ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize,
};
use rustc_hash::{FxHashMap, FxHashSet};
use crate::{
db::HirDatabase,
@ -334,7 +333,7 @@ impl<'db> SemanticsImpl<'db> {
}
fn descend_into_macros(&self, token: SyntaxToken) -> SyntaxToken {
let _p = profile("descend_into_macros");
let _p = profile::span("descend_into_macros");
let parent = token.parent();
let parent = self.find_file(parent);
let sa = self.analyze2(parent.as_ref(), None);
@ -503,18 +502,19 @@ impl<'db> SemanticsImpl<'db> {
fn scope(&self, node: &SyntaxNode) -> SemanticsScope<'db> {
let node = self.find_file(node.clone());
let resolver = self.analyze2(node.as_ref(), None).resolver;
SemanticsScope { db: self.db, resolver }
SemanticsScope { db: self.db, file_id: node.file_id, resolver }
}
fn scope_at_offset(&self, node: &SyntaxNode, offset: TextSize) -> SemanticsScope<'db> {
let node = self.find_file(node.clone());
let resolver = self.analyze2(node.as_ref(), Some(offset)).resolver;
SemanticsScope { db: self.db, resolver }
SemanticsScope { db: self.db, file_id: node.file_id, resolver }
}
fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db> {
let file_id = self.db.lookup_intern_trait(def.id).id.file_id;
let resolver = def.id.resolver(self.db.upcast());
SemanticsScope { db: self.db, resolver }
SemanticsScope { db: self.db, file_id, resolver }
}
fn analyze(&self, node: &SyntaxNode) -> SourceAnalyzer {
@ -523,7 +523,7 @@ impl<'db> SemanticsImpl<'db> {
}
fn analyze2(&self, src: InFile<&SyntaxNode>, offset: Option<TextSize>) -> SourceAnalyzer {
let _p = profile("Semantics::analyze2");
let _p = profile::span("Semantics::analyze2");
let container = match self.with_ctx(|ctx| ctx.find_container(src)) {
Some(it) => it,
@ -710,6 +710,7 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
#[derive(Debug)]
pub struct SemanticsScope<'a> {
pub db: &'a dyn HirDatabase,
file_id: HirFileId,
resolver: Resolver,
}
@ -753,6 +754,14 @@ impl<'a> SemanticsScope<'a> {
})
}
/// Resolve a path as-if it was written at the given scope. This is
/// necessary a heuristic, as it doesn't take hygiene into account.
pub fn resolve_hypothetical(&self, path: &ast::Path) -> Option<PathResolution> {
let hygiene = Hygiene::new(self.db.upcast(), self.file_id);
let path = Path::from_src(path.clone(), &hygiene)?;
self.resolve_hir_path(&path)
}
pub fn resolve_hir_path(&self, path: &Path) -> Option<PathResolution> {
resolve_hir_path(self.db, &self.resolver, path)
}

View File

@ -1,5 +1,6 @@
//! Maps *syntax* of various definitions to their semantic ids.
use base_db::FileId;
use hir_def::{
child_by_source::ChildBySource,
dyn_map::DynMap,
@ -9,14 +10,12 @@ use hir_def::{
ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
};
use hir_expand::{name::AsName, AstId, MacroDefKind};
use ra_db::FileId;
use ra_prof::profile;
use ra_syntax::{
use rustc_hash::FxHashMap;
use stdx::impl_from;
use syntax::{
ast::{self, NameOwner},
match_ast, AstNode, SyntaxNode,
};
use rustc_hash::FxHashMap;
use stdx::impl_from;
use crate::{db::HirDatabase, InFile, MacroDefId};
@ -29,7 +28,7 @@ pub(super) struct SourceToDefCtx<'a, 'b> {
impl SourceToDefCtx<'_, '_> {
pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> {
let _p = profile("SourceBinder::to_module_def");
let _p = profile::span("SourceBinder::to_module_def");
let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| {
let crate_def_map = self.db.crate_def_map(crate_id);
let local_id = crate_def_map.modules_for_file(file).next()?;
@ -39,7 +38,7 @@ impl SourceToDefCtx<'_, '_> {
}
pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
let _p = profile("module_to_def");
let _p = profile::span("module_to_def");
let parent_declaration = src
.as_ref()
.map(|it| it.syntax())

View File

@ -21,7 +21,7 @@ use hir_ty::{
diagnostics::{record_literal_missing_fields, record_pattern_missing_fields},
InferenceResult, Substs, Ty,
};
use ra_syntax::{
use syntax::{
ast::{self, AstNode},
SyntaxNode, TextRange, TextSize,
};
@ -31,7 +31,7 @@ use crate::{
MacroDef, ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias,
TypeParam,
};
use ra_db::CrateId;
use base_db::CrateId;
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
/// original source files. It should not be used inside the HIR itself.

View File

@ -1,9 +1,9 @@
[package]
edition = "2018"
name = "ra_hir_def"
version = "0.1.0"
authors = ["rust-analyzer developers"]
name = "hir_def"
version = "0.0.0"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false
@ -21,16 +21,15 @@ indexmap = "1.4.0"
smallvec = "1.4.0"
stdx = { path = "../stdx" }
ra_arena = { path = "../ra_arena" }
ra_db = { path = "../ra_db" }
ra_syntax = { path = "../ra_syntax" }
ra_prof = { path = "../ra_prof" }
hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
arena = { path = "../arena" }
base_db = { path = "../base_db" }
syntax = { path = "../syntax" }
profile = { path = "../profile" }
hir_expand = { path = "../hir_expand" }
test_utils = { path = "../test_utils" }
mbe = { path = "../ra_mbe", package = "ra_mbe" }
ra_cfg = { path = "../ra_cfg" }
tt = { path = "../ra_tt", package = "ra_tt" }
mbe = { path = "../mbe" }
cfg = { path = "../cfg" }
tt = { path = "../tt" }
[dev-dependencies]
expect = { path = "../expect" }

View File

@ -2,13 +2,13 @@
use std::sync::Arc;
use arena::{map::ArenaMap, Arena};
use either::Either;
use hir_expand::{
name::{AsName, Name},
InFile,
};
use ra_arena::{map::ArenaMap, Arena};
use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
use syntax::ast::{self, NameOwner, VisibilityOwner};
use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree};
use crate::{
@ -23,7 +23,7 @@ use crate::{
EnumId, HasModule, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId,
VariantId,
};
use ra_cfg::CfgOptions;
use cfg::CfgOptions;
/// Note that we use `StructData` for unions as well!
#[derive(Debug, Clone, PartialEq, Eq)]

View File

@ -2,11 +2,11 @@
use std::{ops, sync::Arc};
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_expand::{hygiene::Hygiene, AstId, InFile};
use mbe::ast_to_token_tree;
use ra_cfg::{CfgExpr, CfgOptions};
use ra_syntax::{
use syntax::{
ast::{self, AstNode, AttrsOwner},
SmolStr,
};

View File

@ -5,15 +5,14 @@ pub mod scope;
use std::{mem, ops::Index, sync::Arc};
use arena::{map::ArenaMap, Arena};
use base_db::CrateId;
use cfg::CfgOptions;
use drop_bomb::DropBomb;
use either::Either;
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId};
use ra_arena::{map::ArenaMap, Arena};
use ra_cfg::CfgOptions;
use ra_db::CrateId;
use ra_prof::profile;
use ra_syntax::{ast, AstNode, AstPtr};
use rustc_hash::FxHashMap;
use syntax::{ast, AstNode, AstPtr};
use test_utils::mark;
pub(crate) use lower::LowerCtx;
@ -228,7 +227,7 @@ impl Body {
db: &dyn DefDatabase,
def: DefWithBodyId,
) -> (Arc<Body>, Arc<BodySourceMap>) {
let _p = profile("body_with_source_map_query");
let _p = profile::span("body_with_source_map_query");
let mut params = None;
let (file_id, module, body) = match def {
@ -321,7 +320,7 @@ impl BodySourceMap {
#[cfg(test)]
mod tests {
use ra_db::{fixture::WithFixture, SourceDatabase};
use base_db::{fixture::WithFixture, SourceDatabase};
use test_utils::mark;
use crate::ModuleDefId;

View File

@ -3,21 +3,21 @@
use std::{any::type_name, sync::Arc};
use arena::Arena;
use either::Either;
use hir_expand::{
hygiene::Hygiene,
name::{name, AsName, Name},
HirFileId, MacroDefId, MacroDefKind,
};
use ra_arena::Arena;
use ra_syntax::{
use rustc_hash::FxHashMap;
use syntax::{
ast::{
self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner,
SlicePatComponents,
},
AstNode, AstPtr,
};
use rustc_hash::FxHashMap;
use test_utils::mark;
use crate::{

View File

@ -1,8 +1,8 @@
//! Name resolution for expressions.
use std::sync::Arc;
use arena::{Arena, Idx};
use hir_expand::name::Name;
use ra_arena::{Arena, Idx};
use rustc_hash::FxHashMap;
use crate::{
@ -169,9 +169,9 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
#[cfg(test)]
mod tests {
use base_db::{fixture::WithFixture, FileId, SourceDatabase};
use hir_expand::{name::AsName, InFile};
use ra_db::{fixture::WithFixture, FileId, SourceDatabase};
use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
use syntax::{algo::find_node_at_offset, ast, AstNode};
use test_utils::{assert_eq_text, extract_offset, mark};
use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId};

View File

@ -3,8 +3,7 @@
use std::sync::Arc;
use hir_expand::{name::Name, InFile};
use ra_prof::profile;
use ra_syntax::ast;
use syntax::ast;
use crate::{
attr::Attrs,
@ -133,7 +132,7 @@ pub struct ImplData {
impl ImplData {
pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<ImplData> {
let _p = profile("impl_data_query");
let _p = profile::span("impl_data_query");
let impl_loc = id.lookup(db);
let item_tree = db.item_tree(impl_loc.id.file_id);

View File

@ -1,10 +1,9 @@
//! Defines database & queries for name resolution.
use std::sync::Arc;
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
use hir_expand::{db::AstDatabase, HirFileId};
use ra_db::{salsa, CrateId, SourceDatabase, Upcast};
use ra_prof::profile;
use ra_syntax::SmolStr;
use syntax::SmolStr;
use crate::{
adt::{EnumData, StructData},
@ -116,6 +115,6 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
}
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
let _p = profile("crate_def_map:wait");
let _p = profile::span("crate_def_map:wait");
db.crate_def_map_query(krate)
}

View File

@ -3,7 +3,7 @@
use std::any::Any;
use hir_expand::diagnostics::Diagnostic;
use ra_syntax::{ast, AstPtr, SyntaxNodePtr};
use syntax::{ast, AstPtr, SyntaxNodePtr};
use hir_expand::{HirFileId, InFile};

View File

@ -6,7 +6,7 @@
use std::sync::Arc;
use either::Either;
use ra_syntax::ast;
use syntax::ast;
use crate::{
db::DefDatabase,

View File

@ -12,9 +12,9 @@
//!
//! See also a neighboring `body` module.
use arena::{Idx, RawId};
use hir_expand::name::Name;
use ra_arena::{Idx, RawId};
use ra_syntax::ast::RangeOp;
use syntax::ast::RangeOp;
use crate::{
builtin_type::{BuiltinFloat, BuiltinInt},
@ -197,7 +197,7 @@ pub enum ArithOp {
BitAnd,
}
pub use ra_syntax::ast::PrefixOp as UnaryOp;
pub use syntax::ast::PrefixOp as UnaryOp;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Array {
ElementList(Vec<ExprId>),

View File

@ -1,7 +1,6 @@
//! An algorithm to find a path to refer to a certain item.
use hir_expand::name::{known, AsName, Name};
use ra_prof::profile;
use rustc_hash::FxHashSet;
use test_utils::mark;
@ -18,7 +17,7 @@ use crate::{
/// Find a path that can be used to refer to a certain item. This can depend on
/// *from where* you're referring to the item, hence the `from` parameter.
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
let _p = profile("find_path");
let _p = profile::span("find_path");
find_path_inner(db, item, from, MAX_PATH_LEN)
}
@ -215,7 +214,7 @@ fn find_local_import_locations(
item: ItemInNs,
from: ModuleId,
) -> Vec<(ModuleId, Name)> {
let _p = profile("find_local_import_locations");
let _p = profile::span("find_local_import_locations");
// `from` can import anything below `from` with visibility of at least `from`, and anything
// above `from` with any visibility. That means we do not need to descend into private siblings
@ -293,9 +292,9 @@ fn find_local_import_locations(
#[cfg(test)]
mod tests {
use base_db::fixture::WithFixture;
use hir_expand::hygiene::Hygiene;
use ra_db::fixture::WithFixture;
use ra_syntax::ast::AstNode;
use syntax::ast::AstNode;
use test_utils::mark;
use crate::test_db::TestDB;
@ -308,12 +307,9 @@ mod tests {
fn check_found_path(ra_fixture: &str, path: &str) {
let (db, pos) = TestDB::with_position(ra_fixture);
let module = db.module_for_file(pos.file_id);
let parsed_path_file = ra_syntax::SourceFile::parse(&format!("use {};", path));
let ast_path = parsed_path_file
.syntax_node()
.descendants()
.find_map(ra_syntax::ast::Path::cast)
.unwrap();
let parsed_path_file = syntax::SourceFile::parse(&format!("use {};", path));
let ast_path =
parsed_path_file.syntax_node().descendants().find_map(syntax::ast::Path::cast).unwrap();
let mod_path = ModPath::from_src(ast_path, &Hygiene::new_unhygienic()).unwrap();
let crate_def_map = db.crate_def_map(module.krate);
@ -442,12 +438,12 @@ mod tests {
// already in scope.
check_found_path(
r#"
//- /main.rs crate:main deps:ra_syntax
//- /main.rs crate:main deps:syntax
use ra_syntax::ast;
use syntax::ast;
<|>
//- /lib.rs crate:ra_syntax
//- /lib.rs crate:syntax
pub mod ast {
pub enum ModuleItem {
A, B, C,
@ -459,18 +455,18 @@ mod tests {
check_found_path(
r#"
//- /main.rs crate:main deps:ra_syntax
//- /main.rs crate:main deps:syntax
<|>
//- /lib.rs crate:ra_syntax
//- /lib.rs crate:syntax
pub mod ast {
pub enum ModuleItem {
A, B, C,
}
}
"#,
"ra_syntax::ast::ModuleItem",
"syntax::ast::ModuleItem",
);
}

View File

@ -4,15 +4,14 @@
//! in rustc.
use std::sync::Arc;
use arena::{map::ArenaMap, Arena};
use base_db::FileId;
use either::Either;
use hir_expand::{
name::{name, AsName, Name},
InFile,
};
use ra_arena::{map::ArenaMap, Arena};
use ra_db::FileId;
use ra_prof::profile;
use ra_syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner};
use syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner};
use crate::{
body::LowerCtx,
@ -73,7 +72,7 @@ impl GenericParams {
db: &dyn DefDatabase,
def: GenericDefId,
) -> Arc<GenericParams> {
let _p = profile("generic_params_query");
let _p = profile::span("generic_params_query");
let generics = match def {
GenericDefId::FunctionId(id) => {

View File

@ -2,12 +2,12 @@
use std::{cmp::Ordering, fmt, hash::BuildHasherDefault, sync::Arc};
use base_db::CrateId;
use fst::{self, Streamer};
use indexmap::{map::Entry, IndexMap};
use ra_db::CrateId;
use ra_syntax::SmolStr;
use rustc_hash::{FxHashMap, FxHasher};
use smallvec::SmallVec;
use syntax::SmolStr;
use crate::{
db::DefDatabase,
@ -56,7 +56,7 @@ pub struct ImportMap {
impl ImportMap {
pub fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
let _p = ra_prof::profile("import_map_query");
let _p = profile::span("import_map_query");
let def_map = db.crate_def_map(krate);
let mut import_map = Self::default();
@ -254,7 +254,7 @@ pub fn search_dependencies<'a>(
krate: CrateId,
query: Query,
) -> Vec<ItemInNs> {
let _p = ra_prof::profile("search_dependencies").detail(|| format!("{:?}", query));
let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query));
let graph = db.crate_graph();
let import_maps: Vec<_> =
@ -327,8 +327,8 @@ pub fn search_dependencies<'a>(
#[cfg(test)]
mod tests {
use base_db::{fixture::WithFixture, SourceDatabase, Upcast};
use expect::{expect, Expect};
use ra_db::{fixture::WithFixture, SourceDatabase, Upcast};
use crate::{test_db::TestDB, AssocContainerId, Lookup};

View File

@ -3,9 +3,9 @@
use std::collections::hash_map::Entry;
use base_db::CrateId;
use hir_expand::name::Name;
use once_cell::sync::Lazy;
use ra_db::CrateId;
use rustc_hash::{FxHashMap, FxHashSet};
use test_utils::mark;

View File

@ -13,6 +13,7 @@ use std::{
sync::Arc,
};
use arena::{Arena, Idx, RawId};
use ast::{AstNode, AttrsOwner, NameOwner, StructKind};
use either::Either;
use hir_expand::{
@ -21,10 +22,9 @@ use hir_expand::{
name::{name, AsName, Name},
HirFileId, InFile,
};
use ra_arena::{Arena, Idx, RawId};
use ra_syntax::{ast, match_ast};
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use syntax::{ast, match_ast};
use test_utils::mark;
use crate::{
@ -77,7 +77,7 @@ pub struct ItemTree {
impl ItemTree {
pub fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
let _p = ra_prof::profile("item_tree_query").detail(|| format!("{:?}", file_id));
let _p = profile::span("item_tree_query").detail(|| format!("{:?}", file_id));
let syntax = if let Some(node) = db.parse_or_expand(file_id) {
node
} else {

View File

@ -2,13 +2,13 @@
use std::{collections::hash_map::Entry, mem, sync::Arc};
use arena::map::ArenaMap;
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId};
use ra_arena::map::ArenaMap;
use ra_syntax::{
use smallvec::SmallVec;
use syntax::{
ast::{self, ModuleItemOwner},
SyntaxNode,
};
use smallvec::SmallVec;
use crate::{
attr::Attrs,

View File

@ -1,10 +1,10 @@
use base_db::fixture::WithFixture;
use expect::{expect, Expect};
use hir_expand::{db::AstDatabase, HirFileId, InFile};
use ra_db::fixture::WithFixture;
use ra_syntax::{ast, AstNode};
use rustc_hash::FxHashSet;
use std::sync::Arc;
use stdx::format_to;
use syntax::{ast, AstNode};
use crate::{db::DefDatabase, test_db::TestDB};
@ -228,31 +228,31 @@ fn smoke() {
top-level items:
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ExternCrate>(1) }
ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<syntax::ast::generated::nodes::ExternCrate>(1) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(2) }
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(2) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
> TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::TypeAlias>(8) }
> TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<syntax::ast::generated::nodes::TypeAlias>(8) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
> Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Const>(9) }
> Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<syntax::ast::generated::nodes::Const>(9) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }]
> Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(10) }
> Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(10) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }]
> Function { name: Name(Text("dfl_method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Mut)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(11) }
> Function { name: Name(Text("dfl_method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Mut)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(11) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct0"))] }, input: None }]) }]
Struct { name: Name(Text("Struct0")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), fields: Unit, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(3), kind: Unit }
Struct { name: Name(Text("Struct0")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), fields: Unit, ast_id: FileAstId::<syntax::ast::generated::nodes::Struct>(3), kind: Unit }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct1"))] }, input: None }]) }]
Struct { name: Name(Text("Struct1")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(2), fields: Tuple(IdRange::<ra_hir_def::item_tree::Field>(0..1)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(4), kind: Tuple }
Struct { name: Name(Text("Struct1")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(2), fields: Tuple(IdRange::<hir_def::item_tree::Field>(0..1)), ast_id: FileAstId::<syntax::ast::generated::nodes::Struct>(4), kind: Tuple }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct2"))] }, input: None }]) }]
Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(3), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(1..2)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Struct>(5), kind: Record }
Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(3), fields: Record(IdRange::<hir_def::item_tree::Field>(1..2)), ast_id: FileAstId::<syntax::ast::generated::nodes::Struct>(5), kind: Record }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("en"))] }, input: None }]) }]
Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::<ra_hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Enum>(6) }
Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::<hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<syntax::ast::generated::nodes::Enum>(6) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }]
Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Union>(7) }
Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<syntax::ast::generated::nodes::Union>(7) }
"##]],
);
}
@ -274,13 +274,13 @@ fn simple_inner_items() {
inner attrs: Attrs { entries: None }
top-level items:
Impl { generic_params: GenericParamsId(0), target_trait: Some(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("D"))] }, generic_args: [None] })), target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Response"))] }, generic_args: [Some(GenericArgs { args: [Type(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("T"))] }, generic_args: [None] }))], has_self_type: false, bindings: [] })] }), is_negative: false, items: [Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
> Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
Impl { generic_params: GenericParamsId(0), target_trait: Some(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("D"))] }, generic_args: [None] })), target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Response"))] }, generic_args: [Some(GenericArgs { args: [Type(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("T"))] }, generic_args: [None] }))], has_self_type: false, bindings: [] })] }), is_negative: false, items: [Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Impl>(0) }
> Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
inner items:
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(2):
Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
for AST FileAstId::<syntax::ast::generated::nodes::Item>(2):
Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
"#]],
);
@ -303,9 +303,9 @@ fn extern_attrs() {
top-level items:
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }]
Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
"##]],
);
}
@ -327,11 +327,11 @@ fn trait_attrs() {
top-level items:
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }]
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Trait>(0) }
Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(0) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
"##]],
);
}
@ -353,11 +353,11 @@ fn impl_attrs() {
top-level items:
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("impl_attr"))] }, input: None }]) }]
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Ty"))] }, generic_args: [None] }), is_negative: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Ty"))] }, generic_args: [None] }), is_negative: false, items: [Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Impl>(0) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }]
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
> Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }]
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(2) }
> Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(2) }
"##]],
);
}
@ -408,13 +408,13 @@ fn inner_item_attrs() {
inner attrs: Attrs { entries: None }
top-level items:
Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(0) }
Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(0) }
inner items:
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(1):
for AST FileAstId::<syntax::ast::generated::nodes::Item>(1):
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Fn>(1) }
Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(1) }
"##]],
);
@ -432,8 +432,8 @@ fn assoc_item_macros() {
inner attrs: Attrs { entries: None }
top-level items:
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::<MacroCall>(0))], ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Impl>(0) }
> MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::MacroCall>(1) }
Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::<MacroCall>(0))], ast_id: FileAstId::<syntax::ast::generated::nodes::Impl>(0) }
> MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::<syntax::ast::generated::nodes::MacroCall>(1) }
"#]],
);
}

View File

@ -3,8 +3,8 @@
use std::marker::PhantomData;
use hir_expand::{InFile, MacroDefId};
use ra_syntax::{ast, AstNode, AstPtr};
use rustc_hash::FxHashMap;
use syntax::{ast, AstNode, AstPtr};
use crate::{
dyn_map::{DynMap, Policy},

View File

@ -4,9 +4,8 @@
//! features, such as Fn family of traits.
use std::sync::Arc;
use ra_prof::profile;
use ra_syntax::SmolStr;
use rustc_hash::FxHashMap;
use syntax::SmolStr;
use crate::{
db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, ModuleId,
@ -79,7 +78,7 @@ impl LangItems {
/// Salsa query. This will look for lang items in a specific crate.
pub(crate) fn crate_lang_items_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<LangItems> {
let _p = profile("crate_lang_items_query");
let _p = profile::span("crate_lang_items_query");
let mut lang_items = LangItems::default();
@ -98,7 +97,7 @@ impl LangItems {
db: &dyn DefDatabase,
module: ModuleId,
) -> Option<Arc<LangItems>> {
let _p = profile("module_lang_items_query");
let _p = profile::span("module_lang_items_query");
let mut lang_items = LangItems::default();
lang_items.collect_lang_items(db, module);
if lang_items.items.is_empty() {
@ -115,7 +114,7 @@ impl LangItems {
start_crate: CrateId,
item: SmolStr,
) -> Option<LangItemTarget> {
let _p = profile("lang_item_query");
let _p = profile::span("lang_item_query");
let lang_items = db.crate_lang_items(start_crate);
let start_crate_target = lang_items.items.get(&item);
if let Some(target) = start_crate_target {

Some files were not shown because too many files have changed in this diff Show More