diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index b03ba939a5a5..c81b966c398d 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs @@ -5,6 +5,7 @@ use hir_expand::name::Name; use once_cell::sync::Lazy; use ra_db::CrateId; use rustc_hash::FxHashMap; +use test_utils::mark; use crate::{ db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId, @@ -126,19 +127,27 @@ impl ItemScope { let mut changed = false; let existing = self.visible.entry(name).or_default(); - if existing.types.is_none() && def.types.is_some() { - existing.types = def.types; - changed = true; - } - if existing.values.is_none() && def.values.is_some() { - existing.values = def.values; - changed = true; - } - if existing.macros.is_none() && def.macros.is_some() { - existing.macros = def.macros; - changed = true; + macro_rules! check_changed { + ($changed:ident, $existing:expr, $def:expr) => { + match ($existing, $def) { + (None, Some(_)) => { + $existing = $def; + $changed = true; + } + (Some(e), Some(d)) if e.0 != d.0 => { + mark::hit!(import_shadowed); + $existing = $def; + $changed = true; + } + _ => {} + } + }; } + check_changed!(changed, existing.types, def.types); + check_changed!(changed, existing.values, def.values); + check_changed!(changed, existing.macros, def.macros); + changed } diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs index 2b12c0daad5a..2f440975a970 100644 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ b/crates/ra_hir_def/src/nameres/tests/globs.rs @@ -229,3 +229,50 @@ fn glob_enum_group() { "### ); } + +#[test] +fn glob_shadowed_def() { + mark::check!(import_shadowed); + let map = def_map( + r###" + //- /lib.rs + mod foo; + mod bar; + + use foo::*; + use bar::baz; + + use baz::Bar; + + //- /foo.rs + pub mod baz { + pub struct Foo; + } + + //- /bar.rs + pub mod baz { + pub struct Bar; + } + "###, + ); + assert_snapshot!(map, @r###" + ⋮crate + ⋮Bar: t v + ⋮bar: t + ⋮baz: t + ⋮foo: t + ⋮ + ⋮crate::bar + ⋮baz: t + ⋮ + ⋮crate::bar::baz + ⋮Bar: t v + ⋮ + ⋮crate::foo + ⋮baz: t + ⋮ + ⋮crate::foo::baz + ⋮Foo: t v + "### + ); +} diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 90868760b9b3..2f4c29e06824 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -121,7 +121,7 @@ pub fn analysis_stats( let original_file = src.file_id.original_file(db); let path = vfs.file_path(original_file); let syntax_range = src.value.syntax().text_range(); - format_to!(msg, " ({:?} {:?})", path, syntax_range); + format_to!(msg, " ({} {:?})", path, syntax_range); } if verbosity.is_spammy() { bar.println(msg.to_string()); diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 0a8a86c6214e..940f91d0e5a2 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs @@ -5,7 +5,7 @@ use paths::{AbsPath, AbsPathBuf}; /// Long-term, we want to support files which do not reside in the file-system, /// so we treat VfsPaths as opaque identifiers. -#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] pub struct VfsPath(VfsPathRepr); impl VfsPath { @@ -50,7 +50,7 @@ impl VfsPath { } } -#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] enum VfsPathRepr { PathBuf(AbsPathBuf), VirtualPath(VirtualPath), @@ -71,6 +71,21 @@ impl fmt::Display for VfsPath { } } +impl fmt::Debug for VfsPath { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.0, f) + } +} + +impl fmt::Debug for VfsPathRepr { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match &self { + VfsPathRepr::PathBuf(it) => fmt::Debug::fmt(&it.display(), f), + VfsPathRepr::VirtualPath(VirtualPath(it)) => fmt::Debug::fmt(&it, f), + } + } +} + #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] struct VirtualPath(String); diff --git a/editors/code/rollup.config.js b/editors/code/rollup.config.js index 58360eabbf52..4b4c47f4a374 100644 --- a/editors/code/rollup.config.js +++ b/editors/code/rollup.config.js @@ -11,12 +11,7 @@ export default { resolve({ preferBuiltins: true }), - commonjs({ - namedExports: { - // squelch missing import warnings - 'vscode-languageclient': ['CreateFile', 'RenameFile', 'ErrorCodes', 'WorkDoneProgress', 'WorkDoneProgressBegin', 'WorkDoneProgressReport', 'WorkDoneProgressEnd'] - } - }) + commonjs() ], external: [...nodeBuiltins, 'vscode'], output: {