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 language syntax for function with generic not properly highlighted #30

Open
alexr00 opened this issue Apr 1, 2022 · 2 comments
Open

Comments

@alexr00
Copy link

alexr00 commented Apr 1, 2022

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

@hyangah
Copy link
Contributor

hyangah commented Apr 19, 2022

Users who use vscode-go extension can enable richer syntax highlighting through the semantic tokens provided by gopls. But I think supporting basic syntax highlighting for Go by default (without extra extension installation or running gopls process which isn't supported in web-based IDEs like github.dev or vscode.dev) will be ideal.

@alexr00 AFAIK TextMate-based grammar system has limitation and people desired to get Tree-sitter-based syntax highlighting. I thought VS Code team was looking into the tree-sitter option https://github.com/microsoft/vscode-anycode already. Does VS Code have plan to leverage the work in vscode-anycode and have generics support there (if it doesn't have)?

@alexr00
Copy link
Author

alexr00 commented Apr 20, 2022

It's still an exploration, we don't have any plan in place switch to tree-sitter right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants