Feat: hide double underscored symbols from symbol search
This commit is contained in:
parent
ad810a51f0
commit
ada256c09e
2 changed files with 32 additions and 1 deletions
|
|
@ -53,6 +53,7 @@ pub struct Query {
|
|||
case_sensitive: bool,
|
||||
only_types: bool,
|
||||
libs: bool,
|
||||
include_hidden: bool,
|
||||
}
|
||||
|
||||
impl Query {
|
||||
|
|
@ -66,9 +67,14 @@ impl Query {
|
|||
mode: SearchMode::Fuzzy,
|
||||
assoc_mode: AssocSearchMode::Include,
|
||||
case_sensitive: false,
|
||||
include_hidden: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn include_hidden(&mut self) {
|
||||
self.include_hidden = true;
|
||||
}
|
||||
|
||||
pub fn only_types(&mut self) {
|
||||
self.only_types = true;
|
||||
}
|
||||
|
|
@ -192,7 +198,8 @@ impl<DB> std::ops::Deref for Snap<DB> {
|
|||
// Note that filtering does not currently work in VSCode due to the editor never
|
||||
// sending the special symbols to the language server. Instead, you can configure
|
||||
// the filtering via the `rust-analyzer.workspace.symbol.search.scope` and
|
||||
// `rust-analyzer.workspace.symbol.search.kind` settings.
|
||||
// `rust-analyzer.workspace.symbol.search.kind` settings. Symbols prefixed
|
||||
// with `__` are hidden from the search results unless configured otherwise.
|
||||
//
|
||||
// |===
|
||||
// | Editor | Shortcut
|
||||
|
|
@ -374,6 +381,9 @@ impl Query {
|
|||
if non_type_for_type_only_query || !self.matches_assoc_mode(symbol.is_assoc) {
|
||||
continue;
|
||||
}
|
||||
if !self.include_hidden && symbol.name.starts_with("__") {
|
||||
continue;
|
||||
}
|
||||
if self.mode.check(&self.query, self.case_sensitive, &symbol.name) {
|
||||
cb(symbol);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -926,4 +926,25 @@ struct Foo;
|
|||
let navs = analysis.symbol_search(Query::new("foo".to_owned()), !0).unwrap();
|
||||
assert_eq!(navs.len(), 2)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ensure_hidden_symbols_are_not_returned() {
|
||||
let (analysis, _) = fixture::file(
|
||||
r#"
|
||||
fn foo() {}
|
||||
struct Foo;
|
||||
static __FOO_CALLSITE: () = ();
|
||||
"#,
|
||||
);
|
||||
|
||||
// It doesn't show the hidden symbol
|
||||
let navs = analysis.symbol_search(Query::new("foo".to_owned()), !0).unwrap();
|
||||
assert_eq!(navs.len(), 2);
|
||||
|
||||
// Unless we configure a query to show hidden symbols
|
||||
let mut query = Query::new("foo".to_owned());
|
||||
query.include_hidden();
|
||||
let navs = analysis.symbol_search(query, !0).unwrap();
|
||||
assert_eq!(navs.len(), 3);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue