This guide explains how to add NATS server configuration file support to Neovim using nvim-treesitter.
- Neovim 0.9+ with tree-sitter support
- nvim-treesitter plugin installed
- A C compiler (gcc or clang)
Add this to your Neovim configuration (e.g., init.lua):
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.nats_server_conf = {
install_info = {
url = "https://github.com/synadia-labs/treesitter-nats-server",
files = { "src/parser.c", "src/scanner.c" },
branch = "main",
generate_requires_npm = false,
requires_generate_from_grammar = false,
},
filetype = "nats-server-conf",
}Create ~/.config/nvim/ftdetect/nats.lua:
vim.filetype.add({
pattern = {
-- Files specifically named nats*.conf or nats-server*.conf (or with underscore)
[".*nats[%-_]?server.*%.conf"] = "nats-server-conf",
[".*nats%.conf"] = "nats-server-conf",
-- Any .conf file under a directory whose name contains "nats"
[".*/[^/]*nats[^/]*/.*%.conf"] = "nats-server-conf",
},
})Or if you prefer Vimscript, create ~/.config/nvim/ftdetect/nats.vim:
autocmd BufRead,BufNewFile *nats-server*.conf,*nats*.conf set filetype=nats-server-confIn Neovim, run:
:TSInstall nats_server_confCopy the query files from this repository into your Neovim runtime:
QUERIES_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvim/queries/nats_server_conf"
mkdir -p "$QUERIES_DIR"
cp queries/highlights.scm "$QUERIES_DIR/"
cp queries/folds.scm "$QUERIES_DIR/"
cp queries/indents.scm "$QUERIES_DIR/"
cp queries/locals.scm "$QUERIES_DIR/"Open a .conf file and run:
:InspectTreeYou should see the parsed syntax tree. Syntax highlighting should also be active.
If you use lazy.nvim:
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.nats_server_conf = {
install_info = {
url = "https://github.com/synadia-labs/treesitter-nats-server",
files = { "src/parser.c", "src/scanner.c" },
branch = "main",
},
filetype = "nats-server-conf",
}
require("nvim-treesitter.configs").setup({
ensure_installed = { "nats_server_conf" },
highlight = { enable = true },
indent = { enable = true },
})
end,
}Let the filetype system know about the existence of nats-server-conf as a
filetype, so that you can type :set ft=nats<tab> and have the type work:
touch "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/ftplugin/nats-server-conf.lua"This may help some components integrate fully, by associating the filetype name with hyphens with the treesitter name with underscores, and also enables alternative names as markdown code fence language tags (see below):
vim.treesitter.language.register('nats_server_conf', {
'nats-server-conf',
'nats-conf',
'nats_conf',
})After registering the language aliases above, all of the following code fence tags will produce syntax highlighting in markdown files:
```nats_server_conf
port: 4222
```
```nats-server-conf
port: 4222
```
```nats-conf
port: 4222
```If you load this repository as a Neovim plugin (e.g. via lazy.nvim using
"synadia-labs/treesitter-nats-server" as a plugin spec), the aliases are
registered automatically via plugin/nats_server_conf.lua — no extra
configuration is needed.
- No highlighting: Ensure query files are in the correct directory and the filetype is detected (
:set ft?) - Parser not found: Run
:TSInstallInfoand check thatnats_server_confappears in the list - Compilation errors: Ensure you have a C compiler available and that
ccorgccis in yourPATH