Skip to content

Commit b8a0986

Browse files
fix?(splitter): allow newlines after commas (#380)
1 parent 331f8d1 commit b8a0986

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

crates/pgt_completions/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn should_preselect_first_item(items: &Vec<PossibleCompletionItem>) -> bool {
8686
let second = items_iter.next();
8787

8888
first.is_some_and(|f| match second {
89-
Some(s) => (f.score.get_score() - s.score.get_score()) > 10,
89+
Some(s) => (f.score.get_score() - s.score.get_score()) > 15,
9090
None => true,
91-
})
91+
}) && items.len() >= 10
9292
}

crates/pgt_statement_splitter/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,21 @@ values ('insert', new.id, now());",
333333
"select 3",
334334
]);
335335
}
336+
337+
#[test]
338+
fn commas_and_newlines() {
339+
Tester::from(
340+
"
341+
select
342+
email,
343+
344+
345+
from
346+
auth.users;
347+
",
348+
)
349+
.expect_statements(vec![
350+
"select\n email,\n\n\n from\n auth.users;",
351+
]);
352+
}
336353
}

crates/pgt_statement_splitter/src/parser/common.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,21 @@ pub(crate) fn unknown(p: &mut Parser, exclude: &[SyntaxKind]) {
138138
break;
139139
}
140140
Token {
141-
kind: SyntaxKind::Newline | SyntaxKind::Eof,
141+
kind: SyntaxKind::Eof,
142142
..
143143
} => {
144144
break;
145145
}
146+
Token {
147+
kind: SyntaxKind::Newline,
148+
..
149+
} => {
150+
if p.look_back().is_some_and(|t| t.kind == SyntaxKind::Ascii44) {
151+
p.advance();
152+
} else {
153+
break;
154+
}
155+
}
146156
Token {
147157
kind: SyntaxKind::Case,
148158
..

0 commit comments

Comments
 (0)