Skip to content

Commit edd401e

Browse files
committed
Rust: skip private items when extracting library files
1 parent 23b4e50 commit edd401e

File tree

1 file changed

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

1 file changed

+56
-1
lines changed

rust/extractor/src/translate/base.rs

Lines changed: 56 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,
@@ -672,6 +672,61 @@ impl<'a> Translator<'a> {
672672
{
673673
return true;
674674
}
675+
676+
if ast::AnyHasVisibility::cast(syntax.clone())
677+
.and_then(|x| x.visibility())
678+
.is_none()
679+
{
680+
match syntax.kind() {
681+
SyntaxKind::ENUM
682+
| SyntaxKind::STATIC
683+
| SyntaxKind::STRUCT
684+
| SyntaxKind::TRAIT
685+
| SyntaxKind::TRAIT_ALIAS
686+
| SyntaxKind::UNION => return true,
687+
SyntaxKind::CONST | SyntaxKind::FN | SyntaxKind::TYPE_ALIAS => {
688+
// check for enclosing source file
689+
if syntax.parent().and_then(ast::SourceFile::cast).is_some() {
690+
return true;
691+
}
692+
// check for enclosing module
693+
if syntax
694+
.parent()
695+
.and_then(ast::ItemList::cast)
696+
.and_then(|x| x.syntax().parent())
697+
.and_then(ast::Module::cast)
698+
.is_some()
699+
{
700+
return true;
701+
}
702+
// check for enclosing extern block
703+
if syntax
704+
.parent()
705+
.and_then(ast::ExternItemList::cast)
706+
.and_then(|x| x.syntax().parent())
707+
.and_then(ast::ExternBlock::cast)
708+
.is_some()
709+
{
710+
return true;
711+
}
712+
// check for enclosing block expr
713+
if syntax.parent().and_then(ast::BlockExpr::cast).is_some() {
714+
return true;
715+
}
716+
// check for enclosing non-trait impl
717+
if syntax
718+
.parent()
719+
.and_then(ast::AssocItemList::cast)
720+
.and_then(|x| x.syntax().parent())
721+
.and_then(ast::Impl::cast)
722+
.is_some_and(|imp| imp.trait_().is_none())
723+
{
724+
return true;
725+
}
726+
}
727+
_ => {}
728+
}
729+
}
675730
}
676731
false
677732
}

0 commit comments

Comments
 (0)