Skip to content

Commit 37399a2

Browse files
committed
ide: use previous token in more cases of punctuation
1 parent 269412d commit 37399a2

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

crates/squawk_ide/src/goto_definition.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ drop table t$0;
245245
}
246246

247247
#[test]
248-
fn goto_definition_on_dot_prefers_previous_token() {
248+
fn goto_definition_prefers_previous_token() {
249249
assert_snapshot!(goto("
250250
create table t(a int);
251251
select t.$0a from t;
@@ -256,6 +256,50 @@ select t.$0a from t;
256256
3 │ select t.a from t;
257257
╰╴ ─ 1. source
258258
");
259+
260+
assert_snapshot!(goto("
261+
create type ty as (a int, b int);
262+
with t as (select '(1,2)'::ty c)
263+
select (c)$0.a from t;
264+
"), @r"
265+
╭▸
266+
3 │ with t as (select '(1,2)'::ty c)
267+
│ ─ 2. destination
268+
4 │ select (c).a from t;
269+
╰╴ ─ 1. source
270+
");
271+
assert_snapshot!(goto("
272+
create function f() returns int as 'select 1' language sql;
273+
select f($0);
274+
"), @r"
275+
╭▸
276+
2 │ create function f() returns int as 'select 1' language sql;
277+
│ ─ 2. destination
278+
3 │ select f();
279+
╰╴ ─ 1. source
280+
");
281+
282+
assert_snapshot!(goto("
283+
with t as (select array[1,2,3]::int[] c)
284+
select c[$01] from t;
285+
"), @r"
286+
╭▸
287+
2 │ with t as (select array[1,2,3]::int[] c)
288+
│ ─ 2. destination
289+
3 │ select c[1] from t;
290+
╰╴ ─ 1. source
291+
");
292+
293+
assert_snapshot!(goto("
294+
with t as (select array[1,2,3]::int[] c, 1 b)
295+
select c[b]$0 from t;
296+
"), @r"
297+
╭▸
298+
2 │ with t as (select array[1,2,3]::int[] c, 1 b)
299+
│ ─ 2. destination
300+
3 │ select c[b] from t;
301+
╰╴ ─ 1. source
302+
");
259303
}
260304

261305
#[test]

crates/squawk_ide/src/offsets.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@ pub(crate) fn token_from_offset(file: &ast::SourceFile, offset: TextSize) -> Opt
1010
// - the trailing `;` of a line
1111
// - the `,` in a target list, like `select a, b, c`
1212
// - the `.` following a table/schema/column, like `select t.a from t`
13+
// - the `)` following a composite type, like `select (c).f from t`
14+
// - the `[` in `select c[1] from t`
15+
// - the `]` in `select c[a] from t`
16+
// - the `(` in `select foo()`
1317
if matches!(
1418
token.kind(),
15-
SyntaxKind::SEMICOLON | SyntaxKind::COMMA | SyntaxKind::DOT
19+
SyntaxKind::SEMICOLON
20+
| SyntaxKind::COMMA
21+
| SyntaxKind::DOT
22+
| SyntaxKind::R_PAREN
23+
| SyntaxKind::L_BRACK
24+
| SyntaxKind::R_BRACK
25+
| SyntaxKind::L_PAREN
1626
) {
1727
token = token.prev_token()?;
1828
}

0 commit comments

Comments
 (0)