diff --git a/Cargo.lock b/Cargo.lock index 1483bec7f2f..102c7550424 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ dependencies = [ "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -912,7 +912,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "racer" -version = "2.1.4" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -990,7 +990,7 @@ dependencies = [ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1099,7 +1099,7 @@ dependencies = [ "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ordslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "racer 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "racer 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rls-analysis 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1109,7 +1109,7 @@ dependencies = [ "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-workspace-hack 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfmt-nightly 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustfmt-nightly 0.99.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1173,15 +1173,15 @@ dependencies = [ [[package]] name = "rustc-ap-arena" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rustc-ap-rustc_data_structures 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-rustc_cratesio_shim" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1190,7 +1190,7 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_data_structures" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1198,67 +1198,72 @@ dependencies = [ "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-rustc_errors" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-rustc_target" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-serialize" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "rustc-ap-syntax" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_errors 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_errors 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-syntax_pos" -version = "218.0.0" +version = "237.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-arena 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-arena 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1329,7 +1334,7 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "0.99.2" +version = "0.99.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1342,9 +1347,9 @@ dependencies = [ "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1439,7 +1444,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1826,7 +1831,7 @@ dependencies = [ "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" "checksum quote 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ed7d650913520df631972f21e104a4fa2f9c82a14afc65d17b388a2e29731e7c" -"checksum racer 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "dcbc5ababaffee8d8f34910f925287c8f716b1ead48561c4278a152d08264f7c" +"checksum racer 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4bc3847329b20ff5ba56c298938c179ae9911af15c9c10553f683b65164533" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" "checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" @@ -1843,14 +1848,14 @@ dependencies = [ "checksum rls-rustc 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9dba7390427aefa953608429701e3665192ca810ba8ae09301e001b7c7bed0" "checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a" "checksum rls-vfs 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ecbc8541b4c341d6271eae10f869dd9d36db871afe184f5b6f9bffbd6ed0373f" -"checksum rustc-ap-arena 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e905467184ce31ccdbd33ac33b9ba377f8cc7aefb340a733ab7e5efe34cddda" -"checksum rustc-ap-rustc_cratesio_shim 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a1a45817e78d0c1e2800fb933c526747ef2c5ee4b2dc0946e0c2d901329b88" -"checksum rustc-ap-rustc_data_structures 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4e9e5588883318e0e58bb7ea7cde2a66eaca55b25e32908f0982365988657" -"checksum rustc-ap-rustc_errors 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d233c0d9beda42a52d329a5df865c8f20c64773d2ab7aa6b4ae4248bacf3188" -"checksum rustc-ap-rustc_target 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eec0bc13feecf9e88e39439b24b4b3ca54db8caf12fb7172d0c430451c8b377c" -"checksum rustc-ap-serialize 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffcfb1102cd7cbf5f25c008a00f7253427af9dfac8989ede48c19bd47f556893" -"checksum rustc-ap-syntax 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a2ca0ef078a735c81a0d33589e04148dcf41f80ee7ebe30e72904a631b7c669" -"checksum rustc-ap-syntax_pos 218.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1bbd31d1bbc7210983c3bbbcb9ee35bac443c6c899f979b8114e58bb7101c28" +"checksum rustc-ap-arena 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d24c8b3c1437fad023cb9472381216a1d41d82dbb2d2e6c7858bd6f50317719" +"checksum rustc-ap-rustc_cratesio_shim 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c5b02c76cd1ee4e9c97c8228701796d6b7431e8f100dea2d8af1d6c2c2bad56" +"checksum rustc-ap-rustc_data_structures 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4076388154497fb9a007e3badd78e415402a5594111cd6bc7ce1420dd1b1818b" +"checksum rustc-ap-rustc_errors 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c6c11e4789cbc276ceaa87d326c234b1a2d1e0fe6017b88a8a25903200060acb" +"checksum rustc-ap-rustc_target 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25f711bb152b9d7cdd69410cfe6d99aeb1409c959e0fdf3c8ca4d220e568aa52" +"checksum rustc-ap-serialize 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57638db658d4942d3f30a12566836f9a67a636ed8002c8cae1c9231214e39929" +"checksum rustc-ap-syntax 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6dbcf07abf7a9957dce8d34353d55dfb4cd882153181f24349f4690facb58f0" +"checksum rustc-ap-syntax_pos 237.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0915cb5e166cabe588a129dec2d47357077e96fb1f9b57318fbe217eac4ce508" "checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c6d5a683c6ba4ed37959097e88d71c9e8e26659a3cb5be8b389078e7ad45306" @@ -1859,7 +1864,7 @@ dependencies = [ "checksum rustc-workspace-hack 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustfix 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "756567f00f7d89c9f89a5c401b8b1caaa122e27240b9eaadd0bb52ee0b680b1b" -"checksum rustfmt-nightly 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)" = "56f5442163d82d1f2fb52dd8572e2ac40c1498a8b71964865d4fe464e93766d4" +"checksum rustfmt-nightly 0.99.4 (registry+https://github.com/rust-lang/crates.io-index)" = "df2124994af9da1062649cf5ac3738ae8c1bc292153e991b39a98904e342b7a7" "checksum ryu 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "16aa12da69951804cddf5f74d96abcc414a31b064e610dc81e37c1536082f491" "checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637" "checksum schannel 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "dc1fabf2a7b6483a141426e1afd09ad543520a77ac49bd03c286e7696ccfd77f" @@ -1872,7 +1877,7 @@ dependencies = [ "checksum serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "190e9765dcedb56be63b6e0993a006c7e3b071a016a304736e4a315dc01fb142" "checksum serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "44dd2cfde475037451fa99b7e5df77aa3cfd1536575fa8e7a538ab36dcde49ae" "checksum shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9" -"checksum smallvec 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "211a489e65e94b103926d2054ae515a1cdb5d515ea0ef414fee23b7e043ce748" +"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" "checksum socket2 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "962a516af4d3a7c272cb3a1d50a8cc4e5b41802e4ad54cfb7bee8ba61d37d703" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" diff --git a/Cargo.toml b/Cargo.toml index be82ec29b26..e7ff825c13a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ languageserver-types = "0.45" lazy_static = "1" log = "0.4" num_cpus = "1" -racer = { version = "2.1.4", default-features = false } +racer = { version = "2.1.5", default-features = false } rayon = "1" rls-analysis = "0.16" rls-blacklist = "0.1.2" @@ -32,7 +32,7 @@ rls-data = { version = "0.18", features = ["serialize-serde"] } rls-rustc = "0.5.0" rls-span = { version = "0.4", features = ["serialize-serde"] } rls-vfs = "0.4.6" -rustfmt-nightly = "0.99.2" +rustfmt-nightly = "0.99.4" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" diff --git a/src/project_model.rs b/src/project_model.rs index b725ce54685..6c2363c707f 100644 --- a/src/project_model.rs +++ b/src/project_model.rs @@ -1,5 +1,5 @@ -/// This module represents the RLS view of the Cargo project model: -/// a graph of interdependent packages. +//! This module represents the RLS view of the Cargo project model: +//! a graph of interdependent packages. use std::{ collections::HashMap, sync::Arc, @@ -20,6 +20,7 @@ use racer; #[derive(Debug)] pub struct ProjectModel { + manifest_to_id: HashMap, packages: Vec, } @@ -28,8 +29,7 @@ pub struct Package(usize); #[derive(Debug)] struct PackageData { - manifest: PathBuf, - lib: Option, + lib: Option<(PathBuf, String)>, deps: Vec, } @@ -40,12 +40,12 @@ pub struct Dep { } impl ProjectModel { - pub fn load(manifest: &Path, vfs: &Vfs) -> Result { - assert!(manifest.ends_with("Cargo.toml")); + pub fn load(ws_manifest: &Path, vfs: &Vfs) -> Result { + assert!(ws_manifest.ends_with("Cargo.toml")); let mut config = Config::default()?; - // frozen=true, locked=true - config.configure(0, Some(true), &None, true, true, &None, &[])?; - let ws = Workspace::new(&manifest, &config)?; + // frozen = false, locked = false + config.configure(0, Some(true), &None, false, false, &None, &[])?; + let ws = Workspace::new(&ws_manifest, &config)?; // get resolve from lock file let prev = { let lock_path = ws.root().to_owned().join("Cargo.lock"); @@ -55,30 +55,33 @@ impl ProjectModel { let v: EncodableResolve = resolve.try_into()?; Some(v.into_resolve(&ws)?) } - _ => None + _ => None, } }; - // then resolve precisely and add overrides let mut registry = PackageRegistry::new(ws.config())?; let resolve = resolve_with_prev(&mut registry, &ws, prev.as_ref())?; let cargo_packages = { let ids: Vec = resolve.iter().cloned().collect(); registry.get(&ids) }; - let mut pkg_id_to_pkg = HashMap::new(); + let mut manifest_to_id = HashMap::new(); let mut packages = Vec::new(); for (idx, pkg_id) in resolve.iter().enumerate() { let pkg = Package(idx); pkg_id_to_pkg.insert(pkg_id.clone(), pkg); let cargo_pkg = cargo_packages.get(pkg_id)?; + let manifest = cargo_pkg.manifest_path().to_owned(); packages.push(PackageData { - manifest: cargo_pkg.manifest_path().to_owned(), - lib: cargo_pkg.targets().iter() + lib: cargo_pkg + .targets() + .iter() .find(|t| t.is_lib()) - .map(|t| t.src_path().to_owned()), + // racer expect name 'underscored'(crate) name + .map(|t| (t.src_path().to_owned(), t.name().replace('-', "_"))), deps: Vec::new(), - }) + }); + manifest_to_id.insert(manifest, pkg); } for pkg_id in resolve.iter() { for (dep_id, _) in resolve.deps(&pkg_id) { @@ -99,20 +102,23 @@ impl ProjectModel { } } } - Ok(ProjectModel { packages }) + Ok(ProjectModel { + manifest_to_id, + packages, + }) } pub fn package_for_manifest(&self, manifest_path: &Path) -> Option { - self.packages.iter() - .enumerate() - .find(|(_idx, p)| p.manifest == manifest_path) - .map(|(idx, _p)| Package(idx)) + self.manifest_to_id.get(manifest_path).map(|&x| x) } fn get(&self, pkg: Package) -> &PackageData { &self.packages[pkg.0] } + fn get_lib(&self, pkg: Package) -> Option<&(PathBuf, String)> { + self.packages[pkg.0].lib.as_ref() + } } impl Package { @@ -120,7 +126,7 @@ impl Package { &project.get(self).deps } pub fn lib_root(self, project: &ProjectModel) -> Option<&Path> { - project.get(self).lib.as_ref().map(|p| p.as_path()) + project.get(self).lib.as_ref().map(|p| p.0.as_path()) } } @@ -141,6 +147,13 @@ impl racer::ProjectModelProvider for RacerProjectModel { } fn resolve_dependency(&self, manifest: &Path, libname: &str) -> Option { let pkg = self.0.package_for_manifest(manifest)?; + // if current package has a library target, we have to provide its own name + // in examples/tests/benches directory + if let Some(lib) = self.0.get_lib(pkg) { + if lib.1 == libname { + return Some(lib.0.clone()); + } + } let dep = pkg.deps(&self.0) .iter() .find(|dep| dep.crate_name == libname)? diff --git a/tests/tests.rs b/tests/tests.rs index bf834891510..bf95424a60a 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -311,4 +311,69 @@ fn changing_workspace_lib_retains_bin_diagnostics() { rls.shutdown_exit(); }); -} \ No newline at end of file +} + +#[test] +fn cmd_test_complete_self_crate_name() { + timeout(Duration::from_secs(TIME_LIMIT_SECS), ||{ + let p = project("ws_with_test_dir") + .file("Cargo.toml", r#" + [workspace] + members = ["library"] + "#) + .file("library/Cargo.toml", r#" + [package] + name = "library" + version = "0.1.0" + authors = ["Example "] + "#) + .file("library/src/lib.rs", r#" + pub fn function() -> usize { 5 } + "#) + .file("library/tests/test.rs", r#" + extern crate library; + use library::~ + "#) + .build(); + + let root_path = p.root(); + let rls_child = p.rls().spawn().unwrap(); + let mut rls = RlsHandle::new(rls_child); + + rls.request(0, "initialize", Some(json!({ + "rootPath": root_path, + "capabilities": {} + }))).unwrap(); + + rls.expect_messages(&[ + ExpectedMessage::new(Some(0)).expect_contains("capabilities"), + ExpectedMessage::new(None).expect_contains("progress").expect_contains(r#"title":"Building""#), + ExpectedMessage::new(None).expect_contains("progress").expect_contains("library"), + ExpectedMessage::new(None).expect_contains("progress").expect_contains("library"), + ExpectedMessage::new(None).expect_contains("progress").expect_contains(r#"title":"Building""#), + ExpectedMessage::new(None).expect_contains("progress").expect_contains(r#""done":true"#), + ExpectedMessage::new(None).expect_contains("progress").expect_contains(r#"title":"Indexing""#), + ExpectedMessage::new(None).expect_contains("expected identifier, found"), + ExpectedMessage::new(None).expect_contains("progress").expect_contains(r#""done":true"#), + ]); + rls.request(0, "textDocument/completion", Some(json!({ + "context": { + "triggerCharacter": ":", + "triggerKind": 2 + }, + "position": { + "character": 32, + "line": 2 + }, + "textDocument": { + "uri": format!("file://{}/library/tests/test.rs", root_path.as_path().display()), + "version": 1 + } + }))).unwrap(); + rls.expect_messages(&[ + ExpectedMessage::new(Some(0)).expect_contains("result").expect_contains("pub fn function() -> usize"), + ]); + + rls.shutdown_exit(); + }); +}