Skip to content

Commit

Permalink
split keywords & optimize go highlights, update go tree sitter
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jun 19, 2024
1 parent 54677bc commit 0fffaed
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
51 changes: 33 additions & 18 deletions config/queries/go/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,30 @@

(call_expression
function: (identifier) @function.builtin
(#match? @function.builtin "^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover|min|max)$"))
(#any-of? @function.builtin "append" "cap" "close" "complex" "copy" "delete" "imag" "len" "make" "new" "panic" "print" "println" "real" "recover" "min" "max"))

; Type Conversions
(call_expression
function: (identifier) @type.builtin
(#match? @type.builtin "^(any|bool|byte|comparable|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$"))
(#any-of? @type.builtin "any" "bool" "byte" "comparable" "complex128" "complex64" "error" "float32" "float64" "int" "int16" "int32" "int64" "int8" "rune" "string" "uint" "uint16" "uint32" "uint64" "uint8" "uintptr"))

(call_expression
function: (selector_expression
field: (field_identifier) @function.method))

; Types

[
"chan"
"map"
] @type.builtin

(type_parameter_list
(type_parameter_declaration
name: (identifier) @type.parameter))

((type_identifier) @type.builtin
(#match? @type.builtin "^(any|bool|byte|comparable|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$"))
(#any-of? @function.builtin "append" "cap" "close" "complex" "copy" "delete" "imag" "len" "make" "new" "panic" "print" "println" "real" "recover" "min" "max"))

(composite_literal
(literal_value
Expand Down Expand Up @@ -131,31 +136,41 @@

[
"break"
"case"
"chan"
"const"
"continue"
"default"
"defer"
"else"
"fallthrough"
"for"
"func"
"go"
"goto"
"if"
"import"
"interface"
"map"
"package"
"range"
"return"
"select"
"struct"
] @keyword

"func" @keyword.function

"return" @keyword.return

[
"import"
"package"
] @keyword.control.import

[
"else"
"case"
"switch"
"type"
"if"
] @keyword.conditional

"for" @keyword.repeat

[
"var"
] @keyword
"const"
"type"
"struct"
"interface"
] @keyword.storage.type

; Delimiters

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
go.gopad.dev/fuzzysearch v0.0.0-20240526153819-c12185e04fe2
go.gopad.dev/go-tree-sitter v0.0.0-20240614175658-13906aaed6af
go.gopad.dev/go-tree-sitter v0.0.0-20240619234809-725453cd8bed
go.lsp.dev/jsonrpc2 v0.10.0
go.lsp.dev/protocol v0.12.1-0.20240203004437-3c0d4339e51f
golang.org/x/text v0.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
go.gopad.dev/fuzzysearch v0.0.0-20240526153819-c12185e04fe2 h1:TJfF4DCI0kn8rOfKkp8r11YRW4I+fr1iMdof9EJ1oaI=
go.gopad.dev/fuzzysearch v0.0.0-20240526153819-c12185e04fe2/go.mod h1:MSXvJXowkplateQlS2yCqIZhHzEkKsJTSORMBdRFSGM=
go.gopad.dev/go-tree-sitter v0.0.0-20240614175658-13906aaed6af h1:2dLPtYwbdpnWnsAPBNmcKa0qfcI028bJBC5w8FMXUuI=
go.gopad.dev/go-tree-sitter v0.0.0-20240614175658-13906aaed6af/go.mod h1:BOuWhgzfq9syKxjzjB5VQOiQUVV/Kl3fcn5BSUjEMvE=
go.gopad.dev/go-tree-sitter v0.0.0-20240619234809-725453cd8bed h1:2mD37uiHphfLgeZ52X3RoY1RBa/sWAbpPOFey5IqcbQ=
go.gopad.dev/go-tree-sitter v0.0.0-20240619234809-725453cd8bed/go.mod h1:BOuWhgzfq9syKxjzjB5VQOiQUVV/Kl3fcn5BSUjEMvE=
go.lsp.dev/jsonrpc2 v0.10.0 h1:Pr/YcXJoEOTMc/b6OTmcR1DPJ3mSWl/SWiU1Cct6VmI=
go.lsp.dev/jsonrpc2 v0.10.0/go.mod h1:fmEzIdXPi/rf6d4uFcayi8HpFP1nBF99ERP1htC72Ac=
go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2 h1:hCzQgh6UcwbKgNSRurYWSqh8MufqRRPODRBblutn4TE=
Expand Down
2 changes: 1 addition & 1 deletion gopad/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func (e Editor) Update(msg tea.Msg) (Editor, tea.Cmd) {
case key.Matches(msg, config.Keys.Editor.ToggleTreeSitterDebug):
e.ToggleTreeSitterDebug()
case key.Matches(msg, config.Keys.Editor.DebugTreeSitterNodes):
buff, err := buffer.New("tree.scm", bytes.NewReader([]byte(f.Tree().Print())), "utf-8", buffer.LineEndingLF, false)
buff, err := buffer.New(f.FileName()+".tree", bytes.NewReader([]byte(f.Tree().Print())), "utf-8", buffer.LineEndingLF, false)
if err != nil {
cmds = append(cmds, notifications.Add(fmt.Sprintf("error while opening tree.scm: %s", err.Error())))
return e, tea.Batch(cmds...)
Expand Down

0 comments on commit 0fffaed

Please sign in to comment.