jeff-hykin / better-go-syntax

💾 📦 ✅
MIT License
35 stars 6 forks source link

Go syntax highlighting missing for structs #7

Open jeff-hykin opened 4 years ago

jeff-hykin commented 4 years ago

Originally posted on https://github.com/microsoft/vscode/issues/89288

Description

The syntax highlighting for Go code is missing a lot of highlighting for structs, struct fields and other places of code related to Go structs. This makes the code very hard to read and is pretty much the only thing that Atom do a better job with than Visual Studio Code. I had hoped that this would be fixed by including #82549 in the source code, but it changed absolutely nothing for me. This is kind of a deal breaker for writing go code in Visual Studio Code...

  • VSCode Version: 1.42.0-insiders and 1.41.1 both have this issue.
  • OS Version: Solus 4.1 Fortitude (Linux kernel 5.4.12)

Steps to Reproduce:

  1. Open up a Go source file that has a lot of structs. (this one for example)
  2. Open the same project in Atom and compare syntax highlighting. You will see that a lot of syntax highlighting is missing and it makes it a lot hard to read in vscode.

See images below as an example:

Atom struct syntax:

image image

Visual Studio Code struct syntax:

image image

Does this issue occur when all extensions are disabled?: Yes both with Go extension active and not active.

Linking to microsoft/vscode-go#2892 for the original report.

jeff-hykin commented 4 years ago

Why they're different

Atom upgraded (not without issues) to the Tree-Sitter parser written by Max Brunsfeld who has done an awesome job. The tree sitter is an objectively more powerful parser and is order of magnitudes more efficient than the old standard: TextMate grammar parsers. Not to mention the design and documentation is great, while TextMate does not have any official documentation at all and contains multiple design shortfalls. (TM grammars are used well-beyond their creators intended scope).

Someone has written a tree-sitter go lang grammar, which is what Atom uses.

VS Code is working on switching to tree sitter parsers https://github.com/Microsoft/vscode/issues/50140 However, the TextMate grammar parser is heavily heavily heavily integrated into VS Code. Its going to be hard to switch. I've done some work myself with George Fraser (CEO of Fivetran) and Max Burnfelds to get experimental Tree Sitter support for VS Code via an extension.

What this repo is

AFAIK this repo better-go-syntax is the most up to date Go lang TextMate grammar at this time, which is what VS Code is using. I'm not a Microsoft dev or part of the vs code dev team. I wrote a library/wrapper that makes TM usable so that I could start fixing the C++ TextMate syntax (and some other syntaxes). I maintain this repo to make sure anyone who wants to fix something can fix it, and can fix it without seriously breaking other things. I do not even write Go code (although I respect the design of the Go language).

Most-up-to-date grammar isn't saying much because this is a relatively simple/primitive TextMate grammar.

How to fix what you're seeing

First, you probably want to get a theme that colors operators like *. I suggest Material Theme with the high-contrast option.

Next, coloring aspects like thing.member1.member2 isn't too difficult using TM. Coloring aspects like CircleDiameter float64 could be difficult depending on the Go syntax, which I do not know enough about. In C++ struct highlighting is nearly impossible, but C++ has a very convoluted syntax.

We can break issue into feature request issues, but in TextMate things like struct definitions and struct-type usage will be separate problems and struct-type usage will likely be broken into several more sub-problems, some of which may be unsolvable.

jeff-hykin commented 4 years ago

@Jacalz If you're interested in improving the Go Syntax let me know and I can help walk you through what needs to be done.

Jacalz commented 4 years ago

@Jacalz If you're interested in improving the Go Syntax let me know and I can help walk you through what needs to be done.

Thanks for the offer. I would definitely be interested in helping out in any way that I can. Perhaps not right now because I have a lot to do, but in a couple weeks maybe :)

gjermundgaraba commented 3 years ago

I just started using Go in vscode and started searching for this exact problem. Are there no solutions yet for this problem? Some struct heavy code I'm writing looks almost like writing without syntax highlighter :)