@@ -58,7 +58,8 @@ pub fn goto_definition(file: ast::SourceFile, offset: TextSize) -> SmallVec<[Tex
5858
5959 if let Some ( name_ref) = ast:: NameRef :: cast ( parent. clone ( ) ) {
6060 let binder_output = binder:: bind ( & file) ;
61- if let Some ( ptrs) = resolve:: resolve_name_ref ( & binder_output, & name_ref) {
61+ let root = file. syntax ( ) ;
62+ if let Some ( ptrs) = resolve:: resolve_name_ref ( & binder_output, root, & name_ref) {
6263 return ptrs
6364 . iter ( )
6465 . map ( |ptr| ptr. to_node ( file. syntax ( ) ) . text_range ( ) )
@@ -243,6 +244,34 @@ drop table t$0;
243244 " ) ;
244245 }
245246
247+ #[ test]
248+ fn goto_definition_on_dot_prefers_previous_token ( ) {
249+ assert_snapshot ! ( goto( "
250+ create table t(a int);
251+ select t.$0a from t;
252+ " ) , @r"
253+ ╭▸
254+ 2 │ create table t(a int);
255+ │ ─ 2. destination
256+ 3 │ select t.a from t;
257+ ╰╴ ─ 1. source
258+ " ) ;
259+ }
260+
261+ #[ test]
262+ fn goto_with_table_star ( ) {
263+ assert_snapshot ! ( goto( "
264+ with t as (select 1 a)
265+ select t$0.* from t;
266+ " ) , @r"
267+ ╭▸
268+ 2 │ with t as (select 1 a)
269+ │ ─ 2. destination
270+ 3 │ select t.* from t;
271+ ╰╴ ─ 1. source
272+ " ) ;
273+ }
274+
246275 #[ test]
247276 fn goto_drop_sequence ( ) {
248277 assert_snapshot ! ( goto( "
@@ -2415,6 +2444,32 @@ select a$0 from x;
24152444 " ) ;
24162445 }
24172446
2447+ #[ test]
2448+ fn goto_cte_qualified_column_prefers_cte_over_table ( ) {
2449+ assert_snapshot ! ( goto( "
2450+ create table u(id int, b int);
2451+ with u as (select 1 id, 2 b)
2452+ select u.id$0 from u;
2453+ " ) , @r"
2454+ ╭▸
2455+ 3 │ with u as (select 1 id, 2 b)
2456+ │ ── 2. destination
2457+ 4 │ select u.id from u;
2458+ ╰╴ ─ 1. source
2459+ " ) ;
2460+ }
2461+
2462+ #[ test]
2463+ fn goto_subquery_qualified_column ( ) {
2464+ assert_snapshot ! ( goto( "
2465+ select t.a$0 from (select 1 a) t;
2466+ " ) , @r"
2467+ ╭▸
2468+ 2 │ select t.a from (select 1 a) t;
2469+ ╰╴ ─ 1. source ─ 2. destination
2470+ " ) ;
2471+ }
2472+
24182473 #[ test]
24192474 fn goto_cte_multiple_columns ( ) {
24202475 assert_snapshot ! ( goto( "
@@ -2474,6 +2529,50 @@ select a$0 from y;
24742529 " ) ;
24752530 }
24762531
2532+ #[ test]
2533+ fn goto_cte_qualified_star_join_column ( ) {
2534+ assert_snapshot ! ( goto( "
2535+ create table u(id int, b int);
2536+ create table t(id int, a int);
2537+
2538+ with k as (
2539+ select u.* from t join u on a = b
2540+ )
2541+ select b$0 from k;
2542+ " ) , @r"
2543+ ╭▸
2544+ 2 │ create table u(id int, b int);
2545+ │ ─ 2. destination
2546+ ‡
2547+ 8 │ select b from k;
2548+ ╰╴ ─ 1. source
2549+ " ) ;
2550+ }
2551+
2552+ #[ test]
2553+ fn goto_cte_qualified_star_join_column_with_partial_column_list ( ) {
2554+ assert_snapshot ! ( goto( "
2555+ with
2556+ u as (
2557+ select 1 id, 2 b
2558+ ),
2559+ t as (
2560+ select 1 id, 2 a
2561+ ),
2562+ k(x) as (
2563+ select u.* from t join u on a = b
2564+ )
2565+ select b$0 from k;
2566+ " ) , @r"
2567+ ╭▸
2568+ 4 │ select 1 id, 2 b
2569+ │ ─ 2. destination
2570+ ‡
2571+ 12 │ select b from k;
2572+ ╰╴ ─ 1. source
2573+ " ) ;
2574+ }
2575+
24772576 #[ test]
24782577 fn goto_cte_reference_inside_cte ( ) {
24792578 assert_snapshot ! ( goto( "
@@ -2614,6 +2713,32 @@ select a$0 from (select * from foo.t);
26142713 " ) ;
26152714 }
26162715
2716+ #[ test]
2717+ fn goto_subquery_column_qualified_star_join ( ) {
2718+ assert_snapshot ! ( goto( "
2719+ create table t(a int);
2720+ create table u(b int);
2721+ select b$0 from (select u.* from t join u on a = b);
2722+ " ) , @r"
2723+ ╭▸
2724+ 3 │ create table u(b int);
2725+ │ ─ 2. destination
2726+ 4 │ select b from (select u.* from t join u on a = b);
2727+ ╰╴ ─ 1. source
2728+ " ) ;
2729+ }
2730+
2731+ #[ test]
2732+ fn goto_subquery_column_qualified_star_join_not_found ( ) {
2733+ goto_not_found (
2734+ "
2735+ create table t(a int);
2736+ create table u(b int);
2737+ select a$0 from (select u.* from t join u on a = b);
2738+ " ,
2739+ ) ;
2740+ }
2741+
26172742 #[ test]
26182743 fn goto_insert_table ( ) {
26192744 assert_snapshot ! ( goto( "
0 commit comments