Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,28 @@ sum(expression interval) -> interval
sum(expression numeric) -> numeric
```

unnset

```sql
select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']);
-- ^$ hover
```

```sql
-- Expands multiple arrays (possibly of different data types) into a set of rows. If the arrays are not all the same length then the shorter ones are padded with NULLs. This form is only allowed in a query's FROM clause;
unnest(anyarray, anyarray [, ... ] ) -> setof anyelement, anyelement [, ... ]
```

```sql
select * from unnest(ARRAY[1,2]);
-- ^$ hover
```

```sql
-- Expands an array into a set of rows. The array's elements are read out in storage order.
unnest(anyarray) -> setof anyelement
```

#### Column Number

another example:
Expand All @@ -872,6 +894,8 @@ type: string

#### Star

case expr

```sql
select * from (select case
-- ^$ hover
Expand All @@ -886,6 +910,17 @@ select * from (select case
("case": boolean)
```

unnest

```sql
select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']);
-- ^$ hover
```

```
("unnest": integer, "unnest": text)
```

### Semantic Syntax Highlighting

https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
Expand Down
11 changes: 10 additions & 1 deletion crates/squawk_linter/src/rules/prefer_bigint_over_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn int_to_bigint_replacement(int_type: &str) -> &'static str {
fn create_bigint_fix(ty: &ast::Type) -> Option<Fix> {
let type_name = ty.syntax().first_token()?;
let i64 = int_to_bigint_replacement(type_name.text());
let edit = Edit::replace(ty.syntax().text_range(), i64);
let edit = Edit::replace(type_name.text_range(), i64);
Some(Fix::new(
format!("Replace with a 64-bit integer type: `{i64}`"),
vec![edit],
Expand Down Expand Up @@ -105,6 +105,15 @@ mod test {
assert_snapshot!(fix("create table users (id serial primary key, score int not null);"), @"create table users (id bigserial primary key, score bigint not null);");
}

#[test]
fn fix_array_types() {
assert_snapshot!(fix("create table users (ids int[]);"), @"create table users (ids bigint[]);");
assert_snapshot!(fix("create table users (ids integer[]);"), @"create table users (ids bigint[]);");
assert_snapshot!(fix("create table users (ids int4[]);"), @"create table users (ids int8[]);");
assert_snapshot!(fix("create table users (ids serial[]);"), @"create table users (ids bigserial[]);");
assert_snapshot!(fix("create table users (ids serial4[]);"), @"create table users (ids serial8[]);");
}

#[test]
fn err() {
let sql = r#"
Expand Down
10 changes: 9 additions & 1 deletion crates/squawk_linter/src/rules/prefer_bigint_over_smallint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn smallint_to_bigint(smallint_type: &str) -> &'static str {
fn create_bigint_fix(ty: &ast::Type) -> Option<Fix> {
let type_name = ty.syntax().first_token()?;
let i64 = smallint_to_bigint(type_name.text());
let edit = Edit::replace(ty.syntax().text_range(), i64);
let edit = Edit::replace(type_name.text_range(), i64);
Some(Fix::new(
format!("Replace with a 64-bit integer type: `{i64}`"),
vec![edit],
Expand Down Expand Up @@ -101,6 +101,14 @@ mod test {
assert_snapshot!(fix("create table users (id smallserial primary key, score smallint not null);"), @"create table users (id bigserial primary key, score bigint not null);");
}

#[test]
fn fix_array_types() {
assert_snapshot!(fix("create table users (ids smallint[]);"), @"create table users (ids bigint[]);");
assert_snapshot!(fix("create table users (ids int2[]);"), @"create table users (ids int8[]);");
assert_snapshot!(fix("create table users (ids smallserial[]);"), @"create table users (ids bigserial[]);");
assert_snapshot!(fix("create table users (ids serial2[]);"), @"create table users (ids serial8[]);");
}

#[test]
fn err() {
let sql = r#"
Expand Down
2 changes: 1 addition & 1 deletion crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,7 +2436,7 @@ fn expr_bp(p: &mut Parser<'_>, bp: u8, r: &Restrictions) -> Option<CompletedMark
let _ = expr_bp(p, op_bp, r);
lhs = m.complete(
p,
if matches!(op, COLON_COLON | AS_KW) {
if matches!(op, COLON_COLON) {
CAST_EXPR
} else if matches!(op, FAT_ARROW | COLON_EQ) {
NAMED_ARG
Expand Down
12 changes: 12 additions & 0 deletions crates/squawk_syntax/src/ast/generated/nodes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion crates/squawk_syntax/src/postgresql.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ CallExpr =
Expr ArgList

CastExpr =
Expr (ColonColon? | 'as') Type
'cast' '(' Expr 'as' Type ')'
| Expr ColonColon Type
| Expr Type

ArrayExpr =
'array' '[' (Expr (',' Expr)*) ']'
Expand Down
Loading