Git Product home page Git Product logo

better-go-syntax's Introduction

Like this extension?

You'll probably like this as well: The Better Syntax Megapack

What does this do?

This will get you the bleeding-edge syntax highlighting for Go. Which means your theme will be able to color your code better.

NOTE: The default VS Code theme does not color much. Switch to the Dark+ theme (installed by default) or use a theme like one of the following to benefit from the changes:

How do I use it?

Just install the VS Code extension and the changes will automatically be applied to all relevent files.

Contributing

If you'd like to help improve the syntax, take a look at main/main.rb. And make sure to take a look at documentation/CONTRIBUTING.md to get a better idea of how code works.

better-go-syntax's People

Contributors

dependabot[bot] avatar egonelbre avatar flowchartsman avatar hyangah avatar jeff-hykin avatar tristan957 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

better-go-syntax's Issues

Enhanced colorization

One of my main problems with our large codebase is that some functions change or interact with global variables. I'd like to style them differently for Go.

According to https://code.visualstudio.com/docs/cpp/colorization-cpp it looks like C++ has this on vscode, but I'm trying the same with Go and it does not work, which leads me to assume that support for this needs to be added somewhere.

Would you be able to provide guidance on how to achieve this?

Integer and float literals with underscores

Integer, and floating point literals allow underscores, and the regex associated with them here doesn't seem to support underscores. Is there a way these could be updated to support underscores.

{
    "comment": "Floating-point literals",
    "match": "(\\.\\d+([Ee][-+]\\d+)?i?)\\b|\\b\\d+\\.\\d*(([Ee][-+]\\d+)?i?\\b)?",
    "name": "constant.numeric.floating-point.go"
},
{
    "comment": "Integers",
    "match": "\\b((0x[0-9a-fA-F]+)|(0[0-7]+i?)|(\\d+([Ee]\\d+)?i?)|(\\d+[Ee][-+]\\d+i?))\\b",
    "name": "constant.numeric.integer.go"
},

Wrong color for two import declarations with semicolon between

(Originally reported at golang/vscode-go#2273.)

The first import path string is colored white instead of orange. If there are two import keywords, the second one is white too.

Steps to reproduce the behavior:

Start a new Go file and paste in this:

package p
import ("p";"q")
import "p";import "q"

Screenshot

Screen Shot 2022-06-01 at 4 59 08 PM

Versions

Found in VS Code, which apparently copies this repo for its Go syntax highlighting.

go version:

go version go1.18.2 darwin/amd64

code -v:

1.67.2
c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
x64

Highlight new doc syntax

There's new Go 1.19 markup syntax in doc comments for headings, lists, pre-formatted blocks, and links:

golang/go#51082

It might be accentuated with the right colors. Could help hint to programmers when their formatting is wrong.

Go Syntax Highlighting Incorrect for Constants

Originally from @bruce-quickplay in microsoft/vscode#191339

Type: Bug

I have found what I believe to be an issue with Go language syntax highlighting. Constants that are declared with an explicit type have the wrong colour for the identifier and type tokens:

go-syntax-highlighting

This screenshot shows the issue while running the Dark+ theme. I included a variety of different uses of variables and constants to demonstrate the respective syntax highlighting.

Comparing constant to variable declarations shows the issue:

  • Constant/variable declarations and assignments should have a light blue identifier
    • Constant declarations that include a type have a white identifier
  • Constant/variable references should have a white identifier
  • Types should be green
    • Constant declarations that include a type have a light blue identifier

The problem appears to be, when constant declarations include a type, the type is incorrectly interpreted as the identifier. I believe this may have slipped through because when declaring constants in Go,

I find this most obvious with the Dark+ theme, but the issue exists with all themes I checked.

I disabled all extensions and found the issue persists.

The issue goes away when enabling Semantic Highlighting in the settings, as recommended in the Go in Visual Studio Code doc (this requires the official Go Language Extension). The issue is fixed for all themes except the standard Dark and Light themes.

Here is the sample code in case anyone wants to copy into their own IDE:

package test

import "fmt"

type customType string

const testConst string = "test"
const testConst2 = "test"
const testConst3 customType = "test"

var testVar string = "test"
var testVar2 = "test"
var testVar3 customType = "test"
var testVar4 string

func testFunc(arg string) string {
	const localTestConst string = "test"
	const localTestConst2 = "test"

	var localTestVar string = arg
	testVar2 = arg

	fmt.Println(localTestVar)
	fmt.Println(testConst)

	return localTestVar
}

VS Code version: Code 1.80.2 (Universal) (2ccd690cbff1569e4a83d7c43d45101f817401dc, 2023-07-27T21:05:41.366Z)
OS version: Darwin arm64 22.2.0
Modes:

System Info
Item Value
CPUs Apple M1 Pro (10 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 5, 4, 4
Memory (System) 16.00GB (0.07GB free)
Process Argv --crash-reporter-id 70ee87b8-bad3-40fb-a659-1cd8cc3a4260
Screen Reader no
VM 0%
Extensions: none
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263:30792226
vscaat:30438848
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30803844
282f8724:30602487
89544117:30613380
showlangstatbar:30737416
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
gsofb:30804716
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
dsvsc013:30795093
dsvsc014:30804076
diffeditorv1:30821571

Generic multi-line strings break syntax highlighting.

The following code breaks syntax highlighting:

type myString[D interface{}] string

var properlyColored string = `Multi-line
string with no generic type
is colored properly.`

var notProperlyColored myString[int] = `Multi-line
string with generic type
not colored properly.`

// This messes up all the coloring after as well.
var someInt int = 10

func (s *stringValue) Get() any {
	return string(*s)
}

image

Go language syntax for function with generic not properly highlighted

Originally from @uudashr in microsoft/vscode#146313

  • VS Code Version: 1.65.2
  • OS Version: Darwin arm64 20.6.0

Steps to Reproduce:

  1. Create new file math.go
package generics

type Number interface {
	int64 | float64
}

func SumInts(m map[string]int64) int64 {
	var s int64
	for _, v := range m {
		s += v
	}
	return s
}

func SumFloats(m map[string]float64) float64 {
	var s float64
	for _, v := range m {
		s += v
	}
	return s
}

func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V {
	var s V
	for _, v := range m {
		s += v
	}
	return s
}

func SumNumbers[K comparable, V Number](m map[K]V) V {
	var s V
	for _, v := range m {
		s += v
	}
	return s
}

The generic function is inside the red rectangle. We can see the expected should be like on the green rectangle.
Screen Shot 2022-03-30 at 16 57 52

Syntax doesn't handle double pointer syntax

func (k *Kvdb) Names() ([]string, error) {
	var namesc C.uint
	var namesv **C.char

	err := C.hse_kvdb_get_names(k.impl, &namesc, &namesv)
	if err != 0 {
		return nil, hseErrToErrno(err)
	}

	names := make([]string, namesc)
	for i, s := range (*[limits.KvsCountMax]*C.char)(unsafe.Pointer(namesv))[:namesc:namesc] {
		names[i] = C.GoString(s)
	}

	C.hse_kvdb_free_names(k.impl, namesv)

	return names, nil
}

image

Go syntax highlighting missing for structs

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.

It would be good to support Doxygen or Javadoc style comments

https://www.doxygen.nl/index.html

https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html

As the code below,

/**
 * @file test.go
 * @author your name ([email protected])
 * @brief a test file
 * @version 0.1
 * @date 2021-05-18
 *
 * @copyright Copyright (c) 2021
 *
 */
package main

import "fmt"

/**
 * @brief a function to swap two data
 *
 * @param[in,out] a   a pointer for the first element
 * @param[in,out] b   a pointer for the second element
 * @return int
 */
func my_swap_function(a *int, b *int) int {
	var t int = *a
	*a = *b
	*b = t
	return 0
}

/**
 * @brief main function
 */
func main() {
	var a int = 3
	var b int = 4
	var ret int = my_swap_function(&a, &b)
	if ret == 0 {
		fmt.Printf("%d %d\n", a, b)
	}
}

there is no any syntax highlight on the Doxygen comments.
go

But the C code works fine on Doxygen style syntax highlight.
c

Even the function toolbox supports Doxygen well.
c_toolbox

I hope this feature can be supported in Go as well.

Incorrect Textmate scopes for keyword.operator.arithmetic

Under certain circumstances, * is wrongly indicated as textmate scope keyword.operator.address.go when used as a multiplication operator (keyword.operator.arithmetic.go).

To reproduce, use the following:

package main

import "fmt"

func main() {
	fmt.Print(1*2 + 3) // Bad - * indicated as keyword.operator.address.go
	fmt.Print(4 * 5)   // Good - * indicated as keyword.operator.arithmetic.go
}

Ref: golang/vscode-go#1524

Broken highlights in go files when using raw string literal in some cases

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Open an empty Go file
  2. Paste this code:
package main

import (
	"fmt"
)

func main() {
	var a interface{} = []byte(`{"a": "When only 1 line it's ok."}`)
	fmt.Println(a)
	var b interface{} = []byte(`{
		"b": "But when multiple lines highlighting is broken."
	}`)
	fmt.Println(b)
	// And only one more ` will stop it...
}

Github highlights it correctly but here's how VS Code does it:

image

Originally from @DimaGashko in microsoft/vscode#141360

Repo General Discussion

This is just an issue to create a public-chat for the repo discussing general repo progress and misc topics. It will be closed just so that it doesn't contribute to total issue count.

Slow to open a Go file with long line

The grammar here has similar issues as mentioned in microsoft/vscode#86703.

An example file: https://gist.githubusercontent.com/egonelbre/f93be4d31e7f4dad766a5e8f63374bb3/raw/747cf854bef769e3b8f57edbe207e4e001d98421/example.go

The culprit patterns:

By removing them, opening time for the scanning time goes from 15s to 0.006s.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.