Skip to content

Commit

Permalink
ignore ast-check errors on invalid unused capture
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Dec 11, 2024
1 parent 6c6923d commit 475463a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/features/code_actions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,15 @@ fn handleUnusedCapture(

const source = tree.source;

const identifier_token = offsets.sourceIndexToTokenIndex(tree, loc.start);
if (token_tags[identifier_token] != .identifier) return;

const identifier_name = offsets.locToSlice(source, loc);

// Zig can report incorrect "unused capture" errors
// https://github.com/ziglang/zig/pull/22209
if (std.mem.eql(u8, identifier_name, "_")) return;

try actions.ensureUnusedCapacity(builder.arena, 3);

if (builder.wantKind(.quickfix)) {
Expand Down Expand Up @@ -464,11 +473,6 @@ fn handleUnusedCapture(

if (!builder.wantKind(.@"source.fixAll")) return;

const identifier_token = offsets.sourceIndexToTokenIndex(tree, loc.start);
if (token_tags[identifier_token] != .identifier) return;

const identifier_name = offsets.locToSlice(source, loc);

const capture_end: Ast.TokenIndex = @intCast(std.mem.indexOfScalarPos(Token.Tag, token_tags, identifier_token, .pipe) orelse return);

var lbrace_token = capture_end + 1;
Expand Down
2 changes: 1 addition & 1 deletion tests/lsp_features/code_actions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ test "convert string literal to multiline - invalid" {
}

fn testAutofix(before: []const u8, after: []const u8) !void {
try testDiagnostic(before, after, .{ .filter_kind = .@"source.fixAll", .want_zir = true }); // diagnostics come from our AstGen fork
try testDiagnostic(before, after, .{ .filter_kind = .@"source.fixAll", .want_zir = true }); // diagnostics come from std.zig.AstGen
try testDiagnostic(before, after, .{ .filter_kind = .@"source.fixAll", .want_zir = false }); // diagnostics come from calling zig ast-check
}

Expand Down

0 comments on commit 475463a

Please sign in to comment.