Skip to content

Commit fb1d98d

Browse files
committed
progress
1 parent 6bc0ca4 commit fb1d98d

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

crates/pgt_workspace/src/workspace/server/annotation.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ pub struct AnnotationStore {
1414
db: DashMap<StatementId, Arc<StatementAnnotations>>,
1515
}
1616

17+
const WHITESPACE_TOKENS: [SyntaxKind; 6] = [
18+
SyntaxKind::SPACE,
19+
SyntaxKind::TAB,
20+
SyntaxKind::VERTICAL_TAB,
21+
SyntaxKind::FORM_FEED,
22+
SyntaxKind::LINE_ENDING,
23+
SyntaxKind::EOF,
24+
];
25+
1726
impl AnnotationStore {
1827
pub fn new() -> AnnotationStore {
1928
AnnotationStore { db: DashMap::new() }
@@ -31,24 +40,12 @@ impl AnnotationStore {
3140

3241
let lexed = pgt_lexer::lex(content);
3342

34-
let mut ends_with_semicolon = false;
35-
36-
// Iterate through tokens in reverse to find the last non-whitespace token
37-
for idx in (0..lexed.len()).rev() {
38-
let kind = lexed.kind(idx);
39-
if !matches!(
40-
kind,
41-
SyntaxKind::SPACE
42-
| SyntaxKind::TAB
43-
| SyntaxKind::VERTICAL_TAB
44-
| SyntaxKind::FORM_FEED
45-
| SyntaxKind::LINE_ENDING
46-
| SyntaxKind::EOF
47-
) {
48-
ends_with_semicolon = kind == SyntaxKind::SEMICOLON;
49-
break;
50-
}
51-
}
43+
let ends_with_semicolon = (0..lexed.len())
44+
// Iterate through tokens in reverse to find the last non-whitespace token
45+
.filter(|t| !WHITESPACE_TOKENS.contains(&lexed.kind(*t)))
46+
.next_back()
47+
.map(|t| lexed.kind(t) == SyntaxKind::SEMICOLON)
48+
.unwrap_or(false);
5249

5350
let annotations = Arc::new(StatementAnnotations {
5451
ends_with_semicolon,

0 commit comments

Comments
 (0)