Skip to content

Commit b236854

Browse files
committed
Rust: exclude all function, const, and static bodies
1 parent 08c95ef commit b236854

File tree

1 file changed

+26
-2
lines changed
  • rust/extractor/src/translate

1 file changed

+26
-2
lines changed

Diff for: rust/extractor/src/translate/base.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use ra_ap_ide_db::line_index::{LineCol, LineIndex};
1818
use ra_ap_ide_db::RootDatabase;
1919
use ra_ap_parser::SyntaxKind;
2020
use ra_ap_span::{EditionedFileId, TextSize};
21-
use ra_ap_syntax::ast::HasName;
21+
use ra_ap_syntax::ast::{Const, Fn, HasName, Static};
2222
use ra_ap_syntax::{
2323
ast, AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxNode, SyntaxToken,
2424
TextRange,
@@ -563,7 +563,31 @@ impl<'a> Translator<'a> {
563563
})();
564564
}
565565

566-
pub(crate) fn should_be_excluded(&self, item: &impl ast::HasAttrs) -> bool {
566+
pub(crate) fn should_be_excluded(&self, item: &(impl ast::HasAttrs + ast::AstNode)) -> bool {
567+
let syntax = item.syntax();
568+
if let Some(body) = syntax.parent().and_then(Fn::cast).and_then(|x| x.body()) {
569+
if body.syntax() == item.syntax() {
570+
log::warn!("Skipping Fn body");
571+
return true;
572+
}
573+
}
574+
if let Some(body) = syntax.parent().and_then(Const::cast).and_then(|x| x.body()) {
575+
if body.syntax() == item.syntax() {
576+
log::warn!("Skipping Const body");
577+
return true;
578+
}
579+
}
580+
if let Some(body) = syntax
581+
.parent()
582+
.and_then(Static::cast)
583+
.and_then(|x| x.body())
584+
{
585+
if body.syntax() == item.syntax() {
586+
log::warn!("Skipping Static body");
587+
return true;
588+
}
589+
}
590+
567591
self.semantics.is_some_and(|sema| {
568592
item.attrs().any(|attr| {
569593
attr.as_simple_call().is_some_and(|(name, tokens)| {

0 commit comments

Comments
 (0)