Merge pull request #585 from InKryption/master
Improve unused variable report accuracy
This commit is contained in:
commit
07ae21a25c
@ -250,7 +250,7 @@ fn publishDiagnostics(server: *Server, writer: anytype, handle: DocumentStore.Ha
|
||||
while (decl_iterator.next()) |decl| {
|
||||
var identifier_count: usize = 0;
|
||||
|
||||
var name_token_index = switch (decl.value_ptr.*) {
|
||||
const name_token_index = switch (decl.value_ptr.*) {
|
||||
.ast_node => |an| s: {
|
||||
const an_tag = tree.nodes.items(.tag)[an];
|
||||
switch (an_tag) {
|
||||
@ -270,8 +270,27 @@ fn publishDiagnostics(server: *Server, writer: anytype, handle: DocumentStore.Ha
|
||||
const pit_start = tree.firstToken(scope_data);
|
||||
const pit_end = ast.lastToken(tree, scope_data);
|
||||
|
||||
for (tree.tokens.items(.tag)[pit_start..pit_end]) |tag, index| {
|
||||
if (tag == .identifier and std.mem.eql(u8, tree.tokenSlice(pit_start + @intCast(u32, index)), tree.tokenSlice(name_token_index))) identifier_count += 1;
|
||||
const tags = tree.tokens.items(.tag)[pit_start..pit_end];
|
||||
for (tags) |tag, index| {
|
||||
if (tag != .identifier) continue;
|
||||
if (!std.mem.eql(u8, tree.tokenSlice(pit_start + @intCast(u32, index)), tree.tokenSlice(name_token_index))) continue;
|
||||
if (index -| 1 > 0 and tags[index - 1] == .period) continue;
|
||||
if (index +| 2 < tags.len and tags[index + 1] == .colon) switch (tags[index + 2]) {
|
||||
.l_brace,
|
||||
.keyword_inline,
|
||||
.keyword_while,
|
||||
.keyword_for,
|
||||
.keyword_switch,
|
||||
=> continue,
|
||||
else => {},
|
||||
};
|
||||
if (index -| 2 > 0 and tags[index - 1] == .colon) switch (tags[index - 2]) {
|
||||
.keyword_break,
|
||||
.keyword_continue,
|
||||
=> continue,
|
||||
else => {},
|
||||
};
|
||||
identifier_count += 1;
|
||||
}
|
||||
|
||||
if (identifier_count <= 1)
|
||||
|
Loading…
Reference in New Issue
Block a user