Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/features/references.zig
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,41 @@ const Builder = struct {
const candidate, _ = try builder.analyser.getSymbolEnumLiteral(handle, tree.tokenStart(name_token), name) orelse return;
break :candidate .{ candidate, name_token };
},
.asm_simple,
.@"asm",
=> {
// An asm output operand without `->` is a bare identifier token
// with no corresponding AST node, so it is invisible to the
// child iteration above.
const full_asm = ast.fullAsm(tree, node).?;
for (full_asm.outputs) |output_node| {
const name_token = tree.nodeMainToken(output_node) + 4;
if (tree.tokenTag(name_token) != .identifier) continue; // `(-> T)` operand
const name = offsets.identifierTokenToNameSlice(tree, name_token);
const is_escaped_identifier = tree.source[tree.tokenStart(name_token)] == '@';

if (!is_escaped_identifier) {
if (std.mem.eql(u8, name, "_")) continue;
if (std.zig.isPrimitive(name)) continue;
}

if (!std.mem.eql(u8, name, target_symbol_name)) continue;

var candidate = try builder.analyser.lookupSymbolGlobal(
handle,
name,
tree.tokenStart(name_token),
) orelse continue;

if (builder.resolve_aliases) {
candidate = try builder.analyser.resolveVarDeclAlias(candidate) orelse candidate;
}
if (builder.target_symbol.eql(candidate)) {
try builder.add(handle, name_token);
}
}
return;
},
.global_var_decl,
.local_var_decl,
.aligned_var_decl,
Expand Down
43 changes: 43 additions & 0 deletions tests/lsp_features/references.zig
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,49 @@ test "asm" {
\\ );
\\}
);
try testSymbolReferences(
\\fn foo() void {
\\ var <0>: u32 = 0;
\\ asm volatile ("bogus"
\\ : [ret] "={rax}" (<0>),
\\ );
\\}
);
try testSymbolReferences(
\\fn foo() void {
\\ var <0>: u32 = 0;
\\ asm volatile ("bogus"
\\ : [a] "={rax}" (<0>),
\\ [b] "={rdx}" (<0>),
\\ );
\\}
);
try testSymbolReferences(
\\fn foo() void {
\\ var <0>: u32 = 0;
\\ asm volatile ("bogus"
\\ : [ret] "={rax}" (-> u32),
\\ [out] "={rdx}" (<0>),
\\ );
\\}
);
try testSymbolReferences(
\\var <0>: u32 = 0;
\\fn foo() void {
\\ var <1>: u32 = 0;
\\ asm volatile ("bogus"
\\ : [ret] "={rax}" (<1>),
\\ );
\\}
);
try testSimpleReferences(
\\const <loc>@"i32"<cursor></loc> = undefined;
\\fn foo() void {
\\ asm volatile ("bogus"
\\ : [ret] "={rax}" (i32),
\\ );
\\}
);
}

test "function header" {
Expand Down