-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong coloring of field names that collide with builtin primitive types #23
Comments
The same thing also seems to happen with I came up with an idea that we could enable these types' highlighting of these types when they are used in type specifications (a.k.a. after a colon), such as var my_var: u8 = 10; The problem with this solution, though, is that this same type @as(u8, value);
fn doSomething(comptime T: type) void {}
doSomething(u8); I then had another idea - preventing the highlighting of these types in field declarations and on field accesses: const En = enum { u8 }; // this wouldn't be highlighted because of the surrounding brackets and the
// enum keyword right before
_ = En.u8; // neither would this because it comes right after a dot
const St = struct { u8: u16 }; // u8 wouldn't be highlighted here; the u16 would. This could be done by
// detecting the `:` right after it, and also maybe only while inside a
// `{}` block with a `struct` keyword before (might be complicated)
const inst = St{ .u8 = 53 }; // I believe we can re-use the same rule as in `En.u8` here
_ = inst.u8; // same thing here This might be a little complicated for structs and enums, but for the rest it seems quite simple. Also, although the code below doesn't compile (because it shadows const std = @import("std");
const MyStruct = struct {
pub fn u8() void {
std.debug.print("(hopefully) this is not a valid function name.\n", .{});
}
var u16 = struct {}; // neither is this for a variable name
}; |
Unfortunately the vim grammar is rather primitive/simple in that any nesting logic must be encoded explicitly with regexes (and the rather long regex becomes more slow to evaluate).
Dont try fancy with regexes, when the problem requires a parser to detect all cases. @YohananDiamond If the solution only works for some cases, its probably not worth it. Closing? |
Fair enough. I've heard nvim-treesiter may help with this, but it seems to work in a completely different way and probably is neovim-only. |
@YohananDiamond The alternative is to go out full crazy with implementing a parser in vim. The problem with nvim-treesitter is that it adds significant initial delay for big files (>a few thousand LOC) and a workaround is still not upstream (its just disabled for big files) nvim-treesitter/nvim-treesitter#1708 And sure, its neovim only. |
A full parser in vimscript probably wouldn't be worth the effort, I think. |
Within neovim: The stalling for very big file is not the case anymore, as the highlighting tokens are now added asynchronously without blocking the editor. A workaround for the slowdown for very big files exists also. However, very big files like |
These are all valid field identifiers that do not clash against identifiers in the main namespace.
The text was updated successfully, but these errors were encountered: