Skip to content

Commit e5d5ad9

Browse files
committed
fix: duplicate doc symbol for trait fns
1 parent 858d019 commit e5d5ad9

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

src/ast/ctx.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,18 +764,25 @@ impl<'a, 'ctx> Ctx<'a> {
764764
pub fn add_doc_symbols(&mut self, pltype: Arc<RefCell<PLType>>) {
765765
match &*RefCell::borrow(&pltype) {
766766
PLType::Fn(fnvalue) => {
767-
if !fnvalue.fntype.method {
767+
if self.get_file() != fnvalue.get_path() {
768+
return;
769+
}
770+
if !fnvalue.fntype.method && !fnvalue.in_trait {
768771
self.plmod
769772
.doc_symbols
770773
.borrow_mut()
771774
.push(fnvalue.get_doc_symbol())
772775
}
773776
}
774-
PLType::Struct(st) => self
775-
.plmod
776-
.doc_symbols
777-
.borrow_mut()
778-
.push(st.get_doc_symbol()),
777+
PLType::Struct(st) => {
778+
if self.get_file() != st.get_path() {
779+
return;
780+
}
781+
self.plmod
782+
.doc_symbols
783+
.borrow_mut()
784+
.push(st.get_doc_symbol())
785+
}
779786
_ => {}
780787
}
781788
}

src/ast/node/function.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ pub struct FuncDefNode {
341341
pub trait_bounds: Option<Vec<Box<TraitBoundNode>>>,
342342
pub impl_trait: Option<(Box<TypeNodeEnum>, (TokenType, Range), bool)>, // bool是是否impl有generic
343343
pub is_method: bool,
344+
pub in_trait_def: bool,
344345
pub target_range: Range,
345346
}
346347

@@ -420,6 +421,7 @@ impl TypeNode for FuncDefNode {
420421
generic_infer: Arc::new(RefCell::new(IndexMap::default())),
421422
node: Some(Box::new(self.clone())),
422423
body_range: self.range,
424+
in_trait: self.in_trait_def,
423425
};
424426
if self.generics.is_none() {
425427
builder.get_or_insert_fn_handle(&fnvalue, child);

src/ast/pltype.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ pub struct FNValue {
658658
pub node: Option<Box<FuncDefNode>>,
659659
pub fntype: FnType,
660660
pub body_range: Range,
661+
pub in_trait: bool,
661662
}
662663
impl TryFrom<PLType> for FNValue {
663664
type Error = ();

src/nomparser/function.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub fn function_def(input: Span) -> IResult<Span, Box<TopLevel>> {
120120
impl_trait: None,
121121
is_method: false,
122122
target_range: Default::default(),
123+
in_trait_def: false,
123124
};
124125
Ok::<_, ()>(Box::new(TopLevel::FuncType(node)))
125126
},

src/nomparser/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ pub fn trait_def(input: Span) -> IResult<Span, Box<TraitDefNode>> {
170170
methods: defs
171171
.into_iter()
172172
.map(|x| match *x {
173-
TopLevel::FuncType(f) => f,
173+
TopLevel::FuncType(mut f) => {
174+
f.in_trait_def = true;
175+
f
176+
}
174177
_ => unreachable!(),
175178
})
176179
.collect(),

0 commit comments

Comments
 (0)