@@ -301,21 +301,113 @@ test "switch case capture - union tag" {
301301 );
302302}
303303
304+ test "alias with same name - cursor on declaration" {
305+ try testReferences (&.{
306+ \\const S = struct {
307+ \\ fn <loc>foo<cursor></loc>() void {}
308+ \\};
309+ \\comptime {
310+ \\ const <loc>foo</loc> = S.<loc>foo</loc>;
311+ \\ <loc>foo</loc>();
312+ \\}
313+ }, .{ .format = .asymmetric , .request_kind = .references });
314+ try testReferences (&.{
315+ \\const S = struct {
316+ \\ fn <loc>foo<cursor></loc>() void {}
317+ \\};
318+ \\comptime {
319+ \\ const <loc>foo</loc> = S.<loc>foo</loc>;
320+ \\ <loc>foo</loc>();
321+ \\}
322+ }, .{ .format = .asymmetric , .request_kind = .rename });
323+ }
324+
325+ test "alias with same name - cursor on alias" {
326+ try testReferences (&.{
327+ \\const S = struct {
328+ \\ fn <loc>foo</loc>() void {}
329+ \\};
330+ \\comptime {
331+ \\ const <loc>foo</loc> = S.<loc>foo</loc>;
332+ \\ <loc>foo<cursor></loc>();
333+ \\}
334+ \\comptime {
335+ \\ const <loc>foo</loc> = S.<loc>foo</loc>;
336+ \\ <loc>foo</loc>();
337+ \\}
338+ }, .{ .format = .asymmetric , .request_kind = .references });
339+ try testReferences (&.{
340+ \\const S = struct {
341+ \\ fn foo() void {}
342+ \\};
343+ \\comptime {
344+ \\ const <loc>foo</loc> = S.foo;
345+ \\ <loc>foo<cursor></loc>();
346+ \\}
347+ \\comptime {
348+ \\ const foo = S.foo;
349+ \\ foo();
350+ \\}
351+ }, .{ .format = .asymmetric , .request_kind = .rename });
352+ }
353+
354+ test "alias with different name - cursor on declaration" {
355+ // No references on renamed symbols is mainly an optimization rather than intended behaviour.
356+ try testReferences (&.{
357+ \\const S = struct {
358+ \\ fn <loc>foo<cursor></loc>() void {}
359+ \\};
360+ \\comptime {
361+ \\ const bar = S.<loc>foo</loc>;
362+ \\ bar();
363+ \\}
364+ }, .{ .format = .asymmetric , .request_kind = .references });
365+ try testReferences (&.{
366+ \\const S = struct {
367+ \\ fn <loc>foo<cursor></loc>() void {}
368+ \\};
369+ \\comptime {
370+ \\ const bar = S.<loc>foo</loc>;
371+ \\ bar();
372+ \\}
373+ }, .{ .format = .asymmetric , .request_kind = .rename });
374+ }
375+
376+ test "alias with different name - cursor on alias" {
377+ // No references on renamed symbols is mainly an optimization rather than intended behaviour.
378+ try testReferences (&.{
379+ \\const S = struct {
380+ \\ fn <loc>foo</loc>() void {}
381+ \\};
382+ \\comptime {
383+ \\ const bar = S.<loc>foo</loc>;
384+ \\ bar<cursor>();
385+ \\}
386+ }, .{ .format = .asymmetric , .request_kind = .references });
387+ try testReferences (&.{
388+ \\const S = struct {
389+ \\ fn foo() void {}
390+ \\};
391+ \\comptime {
392+ \\ const <loc>bar</loc> = S.foo;
393+ \\ <loc>bar<cursor></loc>();
394+ \\}
395+ }, .{ .format = .asymmetric , .request_kind = .rename });
396+ }
397+
304398test "cross-file reference" {
305399 try testReferences (&.{
306400 // Untitled-0.zig
307- \\pub const <0 > = struct {};
401+ \\pub const <loc>Foo<cursor></loc > = struct {};
308402 ,
309403 // Untitled-1.zig
310404 \\const file = @import("Untitled-0.zig");
311- \\const <0> = file.<0>;
312- \\const renamed = file.<0>;
405+ \\const <loc>Foo</loc> = file.<loc>Foo</loc>;
313406 \\comptime {
314- \\ _ = <0>;
315- \\ _ = renamed;
407+ \\ _ = <loc>Foo</loc>;
316408 \\}
317409 ,
318- }, .{ .format = .symmetric });
410+ }, .{ .format = .asymmetric });
319411}
320412
321413test "cross-file - transitive import" {
@@ -336,18 +428,32 @@ test "cross-file - transitive import" {
336428test "cross-file - alias" {
337429 try testReferences (&.{
338430 // Untitled-0.zig
339- \\pub const <0 > = struct {
340- \\ fn foo(_: <0 >) void {}
341- \\ var bar: <0 > = undefined;
431+ \\pub const <loc>Foo<cursor></loc > = struct {
432+ \\ fn foo(_: <loc>Foo</loc >) void {}
433+ \\ var bar: <loc>Foo</loc > = undefined;
342434 \\};
343435 ,
344436 // Untitled-1.zig
345- \\const <0> = @import("Untitled-0.zig").<0 >;
437+ \\const <loc>Foo</loc> = @import("Untitled-0.zig").<loc>Foo</loc >;
346438 \\comptime {
347- \\ _ = <0 >;
439+ \\ _ = <loc>Foo</loc >;
348440 \\}
349441 ,
350- }, .{ .format = .symmetric });
442+ }, .{ .format = .asymmetric });
443+ try testReferences (&.{
444+ // Untitled-0.zig
445+ \\pub const <loc>Foo<cursor></loc> = struct {};
446+ ,
447+ // Untitled-1.zig
448+ \\const file = @import("Untitled-0.zig");
449+ \\const <loc>Foo</loc> = file.<loc>Foo</loc>;
450+ \\const renamed = file.<loc>Foo</loc>;
451+ \\comptime {
452+ \\ _ = <loc>Foo</loc>;
453+ \\ _ = renamed;
454+ \\}
455+ ,
456+ }, .{ .format = .asymmetric });
351457}
352458
353459test "matching control flow - unlabeled loop" {
0 commit comments