1
0
Fork 0
mirror of https://github.com/pnx/tree-sitter-dotenv synced 2026-08-16 01:08:13 +02:00

test(nvim): add minimal main/master configs

This commit is contained in:
Henrik Hautakoski 2026-07-15 08:12:20 +02:00
parent 1f5baa64dd
commit 72ea51c5a0
3 changed files with 136 additions and 0 deletions

43
test/nvim/README.md Normal file
View file

@ -0,0 +1,43 @@
# Neovim test configs
This directory contains minimal Neovim configs for testing `tree-sitter-dotenv` with both
legacy and rewritten `nvim-treesitter`.
## Files
- `init-main.lua``nvim-treesitter` `main` (new API)
- `init-master.lua``nvim-treesitter` `master` (legacy API)
## Run
From the repository root, use isolated app names so test state does not mix:
```bash
NVIM_APPNAME=ts-dotenv-main nvim -u "$(pwd)/test/nvim/init-main.lua"
NVIM_APPNAME=ts-dotenv-master nvim -u "$(pwd)/test/nvim/init-master.lua"
```
## Install parser
Run:
```vim
:TSUpdate
:TSInstall dotenv
```
## Verify
Open a `.env` file and check:
```vim
:echo &filetype
```
Expected output: `dotenv`.
### Show the syntax tree
```vim
:InspectTree
```

50
test/nvim/init-main.lua Normal file
View file

@ -0,0 +1,50 @@
local script_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h")
local repo_root = vim.fn.fnamemodify(vim.fn.fnamemodify(script_dir, ":h"), ":h")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
require("lazy").setup({
{
"nvim-treesitter/nvim-treesitter",
branch = "main",
lazy = false,
config = function (_, opts)
require("nvim-treesitter").setup({})
vim.api.nvim_create_autocmd("User", {
pattern = "TSUpdate",
callback = function()
require("nvim-treesitter.parsers").dotenv = {
install_info = {
path = repo_root,
},
}
end,
})
vim.filetype.add({
filename = { [".env"] = "dotenv" },
pattern = { [".env%..+"] = "dotenv" },
})
vim.api.nvim_create_autocmd("FileType", {
pattern = "dotenv",
callback = function()
pcall(vim.treesitter.start)
end,
})
end
},
})

43
test/nvim/init-master.lua Normal file
View file

@ -0,0 +1,43 @@
local script_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h")
local repo_root = vim.fn.fnamemodify(vim.fn.fnamemodify(script_dir, ":h"), ":h")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
require("lazy").setup({
{
"nvim-treesitter/nvim-treesitter",
branch = "master",
lazy = false,
build = ":TSUpdate",
opts = {
highlight = { enable = true },
},
config = function(_, opts)
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.dotenv = {
install_info = {
url = repo_root,
files = { "src/parser.c", "src/scanner.c" },
},
filetype = "dotenv",
}
vim.filetype.add({
filename = { [".env"] = "dotenv" },
pattern = { [".env%..+"] = "dotenv" },
})
end
},
})