Skip to content
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

Go syntax highlighting missing for structs #7

Open
jeff-hykin opened this issue Jan 26, 2020 · 4 comments
Open

Go syntax highlighting missing for structs #7

jeff-hykin opened this issue Jan 26, 2020 · 4 comments
Labels
Big Lots of effort (or depends on other things that require lots of effort)

Comments

@jeff-hykin
Copy link
Owner

Originally posted on microsoft/vscode#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
Copy link
Owner Author

jeff-hykin commented Jan 26, 2020

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 microsoft/vscode#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
Copy link
Owner Author

jeff-hykin commented Jan 26, 2020

@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.

@jeff-hykin jeff-hykin added the Big Lots of effort (or depends on other things that require lots of effort) label Jan 26, 2020
@Jacalz
Copy link

Jacalz commented Feb 2, 2020

@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
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Big Lots of effort (or depends on other things that require lots of effort)
Projects
None yet
Development

No branches or pull requests

3 participants