Skip to content

Commit

Permalink
文の前後に現れるコメントをサポート (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonadern authored Jan 31, 2025
1 parent 92b01d5 commit f797f5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
7 changes: 7 additions & 0 deletions crates/uroborosql-fmt/src/cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ impl Comment {
}
}

pub(crate) fn pg_new(node: postgresql_cst_parser::tree_sitter::Node) -> Comment {
Comment {
text: node.text().to_string(),
loc: node.range().into(),
}
}

pub(crate) fn loc(&self) -> Location {
self.loc.clone()
}
Expand Down
22 changes: 11 additions & 11 deletions crates/uroborosql-fmt/src/new_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ impl Visitor {
source.push(stmt);
above_semi = true;
}
// SyntaxKind::C_COMMENT| SyntaxKind::SQL_COMMENT => {
// let comment = Comment::pg_new(cursor.node());
// if !source.is_empty() && above_semi {
// let last_stmt = source.last_mut().unwrap();
// // すでにstatementがある場合、末尾に追加
// last_stmt.add_comment_to_child(comment)?;
// } else {
// // まだstatementがない場合、バッファに詰めておく
// comment_buf.push(comment);
// }
// }
SyntaxKind::C_COMMENT| SyntaxKind::SQL_COMMENT => {
let comment = Comment::pg_new(cursor.node());
if !source.is_empty() && above_semi {
let last_stmt = source.last_mut().unwrap();
// すでにstatementがある場合、末尾に追加
last_stmt.add_comment_to_child(comment)?;
} else {
// まだstatementがない場合、バッファに詰めておく
comment_buf.push(comment);
}
}
Semicolon => {
above_semi = false;
if let Some(last) = source.last_mut() {
Expand Down

0 comments on commit f797f5d

Please sign in to comment.