Skip to content

DanWlker/tree-sitter-go_tags

Repository files navigation

tree-sitter-go_tags

Go tags grammar for tree-sitter, should match https://cs.opensource.google/go/go/+/refs/tags/go1.24.1:src/reflect/type.go;l=1036

As an alternative (if you only would like to have syntax highlighting and do not care about the tree structure), you could do this:

(field_declaration
  tag: (raw_string_literal
    (raw_string_literal_content) @injection.content
    (#set! injection.self)
  ))

Installation instructions

Reference: https://github.com/nvim-treesitter/nvim-treesitter#adding-parsers

  1. Put this in your nvim-treesitter config function
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
parser_config.go_tags = {
  install_info = {
    url = 'https://github.com/DanWlker/tree-sitter-go_tags',
    files = { 'src/parser.c' },
    branch = 'main',
  },
}
  1. run TSInstall go_tags

Highlighting setup

  1. Copy the contents of queries/highlights.scm from this repo into <your nvim config folder>/queries/go_tags/highlights.scm to enable syntax highlighting (if anyone knows a better way do let me know)

  2. To allow for injections into go struct tags, Add this to your queries/go/injections.scm

(field_declaration
  tag: (raw_string_literal
    (raw_string_literal_content) @injection.content
    (#set! injection.language "go_tags")
  ))

Showcase for treesitter injection

image

About

This is a treesitter grammar for go tags, intended to be used for highlighting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published