Skip to content

Commit

Permalink
refactor: simplify doc_comment_extractor, reduce load (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Mar 23, 2024
1 parent 78dafd7 commit b21db15
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions analyzer/psi/doc_comment_extractor.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module psi
import strings

pub fn extract_doc_comment(el PsiElement) string {
el_start_line := el.node.start_point().row
mut comment := el.prev_sibling() or { return '' }
if comment !is Comment {
comment = comment.prev_sibling() or { return '' }
Expand All @@ -11,23 +12,18 @@ pub fn extract_doc_comment(el PsiElement) string {
mut comments := []PsiElement{}

for comment is Comment {
func_start_line := el.node.start_point().row
comment_start_line := comment.node.start_point().row

if comment_start_line + 1 + u32(comments.len) != func_start_line {
if comment_start_line + 1 + u32(comments.len) != el_start_line {
break
}

if prev := comment.prev_sibling() {
if prev.node.start_point().row == comment_start_line {
break
}
comments << comment
comment = prev
} else {
comments << comment
line := comment.prev_sibling() or { break }
if line.node.start_point().row == comment_start_line {
break
}
comments << comment
comment = line
}

comments.reverse_in_place()
Expand Down

0 comments on commit b21db15

Please sign in to comment.