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: all-CAPS struct fields are highlighted differently from non-all-CAPS #8390

Closed
ygabuev opened this issue Sep 25, 2023 · 1 comment · Fixed by #8399
Closed

go: all-CAPS struct fields are highlighted differently from non-all-CAPS #8390

ygabuev opened this issue Sep 25, 2023 · 1 comment · Fixed by #8399
Labels
A-language-support Area: Support for programming/text languages C-bug Category: This is a bug E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR

Comments

@ygabuev
Copy link
Contributor

ygabuev commented Sep 25, 2023

Summary

Hi!

I have a following piece of Go code:

package main

type Something struct {
	FIELD      int
	Another    int
	YetAnother int
}

func main() {
	var s = Something{
		FIELD:      0,
		Another:    0,
		YetAnother: 0,
	}
}

In helix, the string FIELD - which is all-CAPS - is highlighted differently from other field names when I instantiate a struct:

image

Similar code in e.g. Rust doesn't have this problem:

image

Is this a bug? What may be causing this issue?

Platform

Arch Linux 6.5.4 x86_64

Terminal Emulator

alacritty 0.12.2

Helix Version

helix 23.05

@ygabuev ygabuev added the C-bug Category: This is a bug label Sep 25, 2023
@the-mikedavis the-mikedavis added the A-language-support Area: Support for programming/text languages label Sep 26, 2023
@the-mikedavis
Copy link
Member

This line in the Go highlight queries gives constants (all caps identifiers) the special highlighting:

((identifier) @constant (match? @constant "^[A-Z][A-Z\\d_]+$"))
. We should move that line down further in the file (probably next to (comment) @comment) so that it takes the least precedence.

That won't quite fix this case though. We can highlight the fields in the literal struct by adding a line to the Go highlights:

(keyed_element (literal_element (identifier) @variable.other.member))

Which would fit nicely next to

(field_identifier) @variable.other.member
(the line that gives struct fields their highlight in the type Something struct { .. } block)

@the-mikedavis the-mikedavis added E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR labels Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages C-bug Category: This is a bug E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants