mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-25 21:37:39 +00:00
Auto merge of #17282 - jkelleyrtp:jk/filter-by-underscorte, r=Veykril
Feat: hide double underscored symbols from symbol search Fixes #17272 by changing the default behavior of query to skip results that start with `__` (two underscores). Not sure if this has any far reaching implications - a review would help to understand if this is the right place to do the filtering, and if it's fine to do it by default on the query. If you type `__` as your search, then we'll show the matching double unders, just in case you actually need the symbol.
This commit is contained in:
commit
6bae8e333b
2 changed files with 29 additions and 1 deletions
|
|
@ -192,7 +192,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
|
||||
|
|
@ -356,6 +357,7 @@ impl Query {
|
|||
mut stream: fst::map::Union<'_>,
|
||||
mut cb: impl FnMut(&'sym FileSymbol),
|
||||
) {
|
||||
let ignore_underscore_prefixed = !self.query.starts_with("__");
|
||||
while let Some((_, indexed_values)) = stream.next() {
|
||||
for &IndexedValue { index, value } in indexed_values {
|
||||
let symbol_index = &indices[index];
|
||||
|
|
@ -374,6 +376,10 @@ impl Query {
|
|||
if non_type_for_type_only_query || !self.matches_assoc_mode(symbol.is_assoc) {
|
||||
continue;
|
||||
}
|
||||
// Hide symbols that start with `__` unless the query starts with `__`
|
||||
if ignore_underscore_prefixed && symbol.name.starts_with("__") {
|
||||
continue;
|
||||
}
|
||||
if self.mode.check(&self.query, self.case_sensitive, &symbol.name) {
|
||||
cb(symbol);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -926,4 +926,26 @@ 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);
|
||||
let navs = analysis.symbol_search(Query::new("_foo".to_owned()), !0).unwrap();
|
||||
assert_eq!(navs.len(), 0);
|
||||
|
||||
// Unless we explicitly search for a `__` prefix
|
||||
let query = Query::new("__foo".to_owned());
|
||||
let navs = analysis.symbol_search(query, !0).unwrap();
|
||||
assert_eq!(navs.len(), 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue