Skip to content

Commit

Permalink
fix goto definition on the string literal inside @import
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Jan 15, 2025
1 parent f7888fc commit 3ca6f2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/features/goto.zig
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn gotoDefinitionString(
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

const loc = pos_context.loc().?;
const loc = pos_context.stringLiteralContentLoc(handle.tree.source);
if (loc.start == loc.end) return null;
const import_str = offsets.locToSlice(handle.tree.source, loc);

Expand Down
6 changes: 6 additions & 0 deletions tests/utility/position_context.zig
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,18 @@ test "import/embedfile string literal" {
try testContext(
\\const std = @import(<loc>"st</loc><cursor>");
, .import_string_literal, .{ .lookahead = false });
try testContext(
\\const std = @import(<loc>"s<cursor>t"</loc>);
, .import_string_literal, .{ .lookahead = true });
try testContext(
\\const std = @embedFile(<loc>"file</loc><cursor>.");
, .embedfile_string_literal, .{ .lookahead = false });
try testContext(
\\const std = @embedFile(<loc>"file.</loc><cursor>");
, .embedfile_string_literal, .{ .lookahead = false });
try testContext(
\\const std = @embedFile(<loc>"file.<cursor>"</loc>);
, .embedfile_string_literal, .{ .lookahead = true });

try testContext(
\\const std = @import(<loc>"std"</loc><cursor>);
Expand Down

0 comments on commit 3ca6f2a

Please sign in to comment.