Skip to content

Commit 751022e

Browse files
committed
Rust: skip private items when extracting library files
1 parent 5df50c0 commit 751022e

File tree

1 file changed

+54
-1
lines changed
  • rust/extractor/src/translate

1 file changed

+54
-1
lines changed

rust/extractor/src/translate/base.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use ra_ap_ide_db::RootDatabase;
1616
use ra_ap_ide_db::line_index::{LineCol, LineIndex};
1717
use ra_ap_parser::SyntaxKind;
1818
use ra_ap_span::TextSize;
19-
use ra_ap_syntax::ast::{Const, Fn, HasName, Param, Static};
19+
use ra_ap_syntax::ast::{Const, Fn, HasName, HasVisibility, Param, Static};
2020
use ra_ap_syntax::{
2121
AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxNode, SyntaxToken, TextRange,
2222
ast,
@@ -687,6 +687,59 @@ impl<'a> Translator<'a> {
687687
{
688688
return true;
689689
}
690+
691+
if ast::AnyHasVisibility::cast(syntax.clone())
692+
.and_then(|x| x.visibility())
693+
.is_none()
694+
{
695+
match syntax.kind() {
696+
SyntaxKind::ENUM
697+
| SyntaxKind::STATIC
698+
| SyntaxKind::STRUCT
699+
| SyntaxKind::TRAIT
700+
| SyntaxKind::TRAIT_ALIAS
701+
| SyntaxKind::UNION => return true,
702+
SyntaxKind::CONST | SyntaxKind::FN | SyntaxKind::TYPE_ALIAS => {
703+
// check for enclosing source file
704+
if syntax.parent().and_then(ast::SourceFile::cast).is_some() {
705+
return true;
706+
}
707+
// check for enclosing module
708+
if syntax
709+
.parent()
710+
.and_then(ast::ItemList::cast)
711+
.and_then(|x| x.syntax().parent())
712+
.and_then(ast::Module::cast)
713+
.is_some()
714+
{
715+
return true;
716+
}
717+
// check for enclosing extern block
718+
if syntax
719+
.parent()
720+
.and_then(ast::ExternItemList::cast)
721+
.is_some()
722+
{
723+
return true;
724+
}
725+
// check for enclosing block expr
726+
if syntax.parent().and_then(ast::BlockExpr::cast).is_some() {
727+
return true;
728+
}
729+
// check for enclosing non-trait impl
730+
if syntax
731+
.parent()
732+
.and_then(ast::AssocItemList::cast)
733+
.and_then(|x| x.syntax().parent())
734+
.and_then(ast::Impl::cast)
735+
.is_some_and(|imp| imp.trait_().is_none())
736+
{
737+
return true;
738+
}
739+
}
740+
_ => {}
741+
}
742+
}
690743
}
691744
false
692745
}

0 commit comments

Comments
 (0)