-
Notifications
You must be signed in to change notification settings - Fork 58
Fixed highlighting of brackets, punctuations and identifiers. #52
Changes from all commits
fc6e849
afdbccf
6023332
02ec1f1
8ac94d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,7 +85,7 @@ | |
| } | ||
| { | ||
| 'name': 'storage.type.go' | ||
| 'match': '\\b(chan|map|bool|string|error|int|int8|int16|int32|int64|rune|byte|uint|uint8|uint16|uint32|uint64|uintptr|float32|float64|complex64|complex128)\\b' | ||
| 'match': '\\b(bool|string|error|int|int8|int16|int32|int64|rune|byte|uint|uint8|uint16|uint32|uint64|uintptr|float32|float64|complex64|complex128)\\b' | ||
| } | ||
| { | ||
| 'name': 'invalid.illegal.numeric.go' | ||
|
|
@@ -105,12 +105,18 @@ | |
| } | ||
| { | ||
| 'name': 'keyword.go' | ||
| 'match': '\\b(func|var|const|type|struct|interface|case|default)\\b' | ||
| 'match': '\\b(chan|map|func|var|const|type|struct|interface|case|default)\\b' | ||
| } | ||
| { | ||
| 'name': 'keyword.directive.go' | ||
| 'match': '\\b(package|import)\\b' | ||
| } | ||
| { | ||
| 'match': '\\bpackage\\b\\s+([\\w_][\\w\\d_]*)' | ||
| 'captures': | ||
| '1': | ||
| 'name': 'entity.name.package.go' | ||
| } | ||
| { | ||
| 'name': 'keyword.statement.go' | ||
| 'match': '\\b(defer|go|goto|return|break|continue|fallthrough)\\b' | ||
|
|
@@ -127,6 +133,10 @@ | |
| 'name': 'constant.language.go' | ||
| 'match': '\\b(iota|true|false|nil)\\b' | ||
| } | ||
| { | ||
| 'match': '\\;' | ||
| 'name': 'meta.terminator.semicolon.go' | ||
| } | ||
| { | ||
| 'include': '#string_escaped_char' | ||
| } | ||
|
|
@@ -142,6 +152,9 @@ | |
| { | ||
| 'include': '#variables' | ||
| } | ||
| { | ||
| 'include': '#delimiters' | ||
| } | ||
| ] | ||
| 'repository': | ||
| 'string_escaped_char': | ||
|
|
@@ -159,22 +172,41 @@ | |
| 'patterns': [ | ||
| { | ||
| "name": "keyword.operator.go", | ||
| "match": "(\\+|&|\\+=|&=|&&|==|!=|\\-|\\||\\-=|\\|=|\\|\\||<|<=|\\*|\\^|\\*=|\\^=|<\\-|>|>=|/|<<|/=|<<=|\\+\\+|=|:=|;|%|>>|%=|>>=|\\-\\-|!|\\.\\.\\.|&\\^|&\\^=)" | ||
| "match": "(\\+|&|\\+=|&=|&&|==|!=|\\-|\\||\\-=|\\|=|\\|\\||<|<=|\\*|\\^|\\*=|\\^=|<\\-|>|>=|/|<<|/=|<<=|\\+\\+|=|:=|%|>>|%=|>>=|\\-\\-|!|\\.\\.\\.|&\\^|&\\^=)" | ||
| } | ||
| { | ||
| 'match': '\\{|\\}' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the specs these are not delimiters, but operators. If you are keen on having them named more precise, I would suggest scopes like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since braces aren't listed as keywords in the spec, I don't think they should have a scope name with The braces are described in the section on Operators and Delimiters, but they are never mentioned in the Operators section. I concluded that they are are not operators, and must therefore be delimiters. The reason for changing the scopes is to better align braces with how other packages (C++, C#, JavaScript, CSS, Perl, Shell, Python etc.) treat braces. The advantage of aligning with them is that a larger number of syntax highlighting themes will work well equally with Go's scopes. From these few examples of What is your opinion on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fair point... So I guess |
||
| 'name': 'meta.brace.curly.go' | ||
| } | ||
| { | ||
| "name": "keyword.operator.bracket.go", | ||
| "match": "(\\(|\\)|\\[|\\]|\\{|\\})" | ||
| 'match': '\\(|\\)' | ||
| 'name': 'meta.brace.round.go' | ||
| } | ||
| { | ||
| "name": "keyword.operator.punctuation.go", | ||
| "match": "(\\.|,|:)" | ||
| 'match': '\\[|\\]' | ||
| 'name': 'meta.brace.square.go' | ||
| } | ||
| ] | ||
| 'variables': | ||
| 'patterns': [ | ||
| { | ||
| 'name': 'variable.go' | ||
| 'match': '\\b[\\w_][\\w\\d_]*\\b', | ||
| 'match': '\\b[\\w_][\\w\\d_]*\\b' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would you remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be added back, if you prefer. We'd have to be careful around type declarations, etc. since a type name isn't a variable. type User struct {
name string
yob int
}There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true, but those (type's) it seem to be hard to scope them consistently as also discussed on Slack and here: #49 For the package name it should be no problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... Yes, that is true. While I understand that it's a lot more work, it would be really neat to have a highlighter which is context aware. |
||
| } | ||
| ] | ||
| 'delimiters': | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this also goes that these are operators, so we not scope it as such? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be delimiters for the same reason as braces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check... Even through these (and the braces) operators are not documented in more detail by the language specs, they really are still operators. They could (and maybe should) have been documented more along these lines for example: https://msdn.microsoft.com/en-us/library/6a71f45d.aspx But then again, I agree that as they are not described and other language packages seem to describe them as delimiters I think the scopes like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C# really documents those operators very neatly! While I love the simplicity of Go, including it's website and documentation, sometimes it's a bit too plain. It would have been nice to have something similar. 😉 |
||
| 'patterns': [ | ||
| { | ||
| 'match': ',' | ||
| 'name': 'meta.delimiter.comma.go' | ||
| } | ||
| { | ||
| 'match': '\\.' | ||
| 'name': 'meta.delimiter.period.go' | ||
| } | ||
| { | ||
| 'match': ':' | ||
| 'name': 'meta.delimiter.colon.go' | ||
| } | ||
| ] | ||
| 'printf_verbs': | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even through your absolutely correct that both
chanandmapare listed as reserved (key)words, they are also both types (https://golang.org/ref/spec#Map_types and https://golang.org/ref/spec#Channel_types) listed and explained right along side all other types (https://golang.org/ref/spec#Types).Taking that into account and looking at how the words are used within the language (to define types) I think it makes much more sense to assign the
storage.type.goscope instead of thekeyword.goscope.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is true that
chanandmapare keywords used to define types; your opinion isn't unfounded.However, the specification does list them as keywords. Additionally, all other type related keywords
type,struct,interfaceandfuncare arguably also used to define types, but they aren't marked with thestorage.type.goscope; they have thekeyword.goscope. So shouldchanandmap.Consider this example using all type related keywords:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look it this with the theme I'm using, the current scoping still makes a lot more sense to me:
It makes very clear that I'm using the types
mapandchan. If you make them as keywords they fade away together with all the other keywords making the same line harder and less clear to read:So IMO this should really be scoped as
storage.type.go.@joefitzgerald what's your take on this specific one? It seems the language spec leaves room for both
keyword.goandstorage.type.goto be used. So it comes down to usability and personal preference I think...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit of a silly example, of course. It's very unlikely to use all type related keywords together like that.
The difference with the new scopes on a more likely example is more appealing:


and
Builtin functions, keywords, primitive types and other types, are all highlighted differently.