Hi, I just moved to a rolling release Linux distro, so I discovered a recent version of VS Code. The Nim highlighting has changed here, and like in Aporia, the identifiers who begins by an upper case are highlighted in a specific color. This choice force the user to follow the naming convention, otherwise, the highlighting becomes inconsistent and annoying.
In my opinion the highlighting must follow the languages rules only, and not a convention, which is facultative by nature. If Nim community really wants to forbid class names who begin by a lower case so update the compiler to raise an error, but let the user the more freedom as possible ouside the scope of the language rules. The Textadept highlighting, for example, is fine.
IMO only using language rules for highlighting doesn't get you very far in Nim. If the code doesn't follow conventions, it's very hard to highlight anything at all. Here's an extreme example:
type float = object
bool: string
var false = "abc"
var string: float.bool = false
Either way, the syntax highlighting for VS Code isn't developed by the Nim developers. Here's the repo.In my opinion the highlighting must follow the languages rules only,
You can ask nimsuggest for high quality highlighting. I did that in a private version of my NEd editor (https://github.com/StefanSalewski/NEd) about one year ago, it was working really fine. The disadvantage is, that it creates a really high CPU load, as nearly for every keystroke a new full nimsuggest query is necessary. I had no really good idea how to avoid that, so I am still using plain highlighting similar as aporia does. (and of course nimsuggest may still crash in a few special situations, for example when we rename a Ruby file to nim extension and try to convert the code in editor to true Nim. But most of the time nimsuggest does not crash any more, so you may consider using its highlight information when CPU load is not a concern for you.)
@GULPF It's a bit better in Textadept because it highlight Nim's official types with it's own color.
@Stefan_Salewski: Interesting. Why not calling Nimsuggest on space hits and carriage returns only ?
This choice force the user to follow the naming convention, otherwise, the highlighting becomes inconsistent and annoying.
Yeah, that's precisely why it's done and you should follow it. It's that simple.
Why not make the compiler enforce it? Because there are genuine cases where it's just easier to not follow the convention (eg. wrappers). But the convention is there to motivate people to follow it, and I am glad the syntax highlighters are following it.
Why not calling Nimsuggest on space hits and carriage returns only ?
Yes this is one solution, but I was not really happy with it. In the general case one single keystroke can change highlight of the whole file. For example when we modify a var or type definition all occurrences of that var or type in that file can become invalid, and I think highlight should show that immediately. So only cursor movements are keystrokes which for sure do not need a new nimsuggest query. And if I remember correctly nimsuggest does send for each query the information for the whole file, which is a lot traffic and CPU load.
Yeah, that's precisely why it's done and you should follow it. It's that simple.
Why not make the compiler enforce it? Because there are genuine cases where it's just easier to not follow the convention (eg. wrappers). But the convention is there to motivate people >to follow it, and I am glad the syntax highlighters are following it.
I totally disagree but I understand your point.