Rust: skip private items when extracting library files

This commit is contained in:
Arthur Baars
2025-05-26 13:09:10 +02:00
parent 55be5fbf9e
commit 977a197337

View File

@@ -16,7 +16,7 @@ use ra_ap_ide_db::RootDatabase;
use ra_ap_ide_db::line_index::{LineCol, LineIndex}; use ra_ap_ide_db::line_index::{LineCol, LineIndex};
use ra_ap_parser::SyntaxKind; use ra_ap_parser::SyntaxKind;
use ra_ap_span::TextSize; use ra_ap_span::TextSize;
use ra_ap_syntax::ast::{Const, Fn, HasName, Param, Static}; use ra_ap_syntax::ast::{Const, Fn, HasName, HasVisibility, Param, Static};
use ra_ap_syntax::{ use ra_ap_syntax::{
AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxNode, SyntaxToken, TextRange, AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxNode, SyntaxToken, TextRange,
ast, ast,
@@ -687,6 +687,59 @@ impl<'a> Translator<'a> {
{ {
return true; return true;
} }
if ast::AnyHasVisibility::cast(syntax.clone())
.and_then(|x| x.visibility())
.is_none()
{
match syntax.kind() {
SyntaxKind::ENUM
| SyntaxKind::STATIC
| SyntaxKind::STRUCT
| SyntaxKind::TRAIT
| SyntaxKind::TRAIT_ALIAS
| SyntaxKind::UNION => return true,
SyntaxKind::CONST | SyntaxKind::FN | SyntaxKind::TYPE_ALIAS => {
// check for enclosing source file
if syntax.parent().and_then(ast::SourceFile::cast).is_some() {
return true;
}
// check for enclosing module
if syntax
.parent()
.and_then(ast::ItemList::cast)
.and_then(|x| x.syntax().parent())
.and_then(ast::Module::cast)
.is_some()
{
return true;
}
// check for enclosing extern block
if syntax
.parent()
.and_then(ast::ExternItemList::cast)
.is_some()
{
return true;
}
// check for enclosing block expr
if syntax.parent().and_then(ast::BlockExpr::cast).is_some() {
return true;
}
// check for enclosing non-trait impl
if syntax
.parent()
.and_then(ast::AssocItemList::cast)
.and_then(|x| x.syntax().parent())
.and_then(ast::Impl::cast)
.is_some_and(|imp| imp.trait_().is_none())
{
return true;
}
}
_ => {}
}
}
} }
false false
} }