Builtin functions in Zig #8480
Unanswered
rvoogdgeert
asked this question in
Troubleshooting
Replies: 1 comment 1 reply
-
This looks like a bug upstream in ZLS. Can you reproduce this with another editor? ZLS sends us this completion item: {
"detail": "@This() type",
"documentation": {
"kind": "markdown",
"value": "Returns the innermost struct, enum, or union that this function call is inside. This can be useful for an anonymous struct that needs to refer to itself:\n\n```zig\nconst std = @import(\"std\");\nconst expect = std.testing.expect;\ntest \"@This()\" {\n var items = [_]i32{ 1, 2, 3, 4 };\n const list = List(i32){ .items = items[0..] };\n try expect(list.length() == 4);\n}\nfn List(comptime T: type) type {\n return struct {\n const Self = @This();\n items: []T,\n fn length(self: Self) usize {\n return self.items.len;\n }\n };\n}\n```\nWhen `@This()` is used at file scope, it returns a reference to the struct that corresponds to the current file."
},
"filterText": "This",
"insertText": "This()",
"insertTextFormat": 2,
"kind": 3,
"label": "@This",
"sortText": "4_@This",
"textEdit": {
"newText": "This()",
"range": {
"end": {
"character": 24,
"line": 0
},
"start": {
"character": 23,
"line": 0
}
}
}
}, For a document like so: pub fn printName(self: @) void {} with the cursor to the right of the It looks like this only happens in function parameters. If I try a completion later like const self = @This(); ZLS sends a range where |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When using a builtin function in Zig the editor removes the
@
after insertion. Try typing:When typing @ the menu opens and as soon as on chooses on of the options, e.g.
This
, the '@' is removed and doesn't return after enter.Beta Was this translation helpful? Give feedback.
All reactions