mirror of
https://github.com/pnx/tree-sitter-dotenv
synced 2026-08-15 12:58:12 +02:00
docs: move neovim setup into dedicated guide
This commit is contained in:
parent
8b2a6e188a
commit
c40585e9c0
2 changed files with 75 additions and 34 deletions
35
README.md
35
README.md
|
|
@ -4,40 +4,7 @@ tree-sitter grammar for [dotenv](https://dotenvx.com)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Neovim
|
[neovim](docs/neovim.md)
|
||||||
|
|
||||||
To use this parser in neovim, you need to configure [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)
|
|
||||||
|
|
||||||
Add this to nvim-treesitter's config function:
|
|
||||||
|
|
||||||
```lua
|
|
||||||
config = function(_, opts)
|
|
||||||
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
|
|
||||||
|
|
||||||
-- Tell treesitter where dotenv parser is located
|
|
||||||
parser_config.dotenv = {
|
|
||||||
install_info = {
|
|
||||||
url = "https://github.com/pnx/tree-sitter-dotenv",
|
|
||||||
branch = "main",
|
|
||||||
files = { "src/parser.c", "src/scanner.c" },
|
|
||||||
},
|
|
||||||
filetype = "dotenv",
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Associate .env files as "dotenv"
|
|
||||||
vim.filetype.add({
|
|
||||||
pattern = {
|
|
||||||
['%.env'] = 'dotenv',
|
|
||||||
['%.env%..+'] = 'dotenv',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Syntax highlighting
|
|
||||||
|
|
||||||
In order for neovim to know how to color the text, a `highlights.scm` file is needed.
|
|
||||||
Copy [highlights.scm](queries/highlights.scm) from this repo to your nvim config under `queries/dotenv/highlights.scm`
|
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
|
|
|
||||||
74
docs/neovim.md
Normal file
74
docs/neovim.md
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
# Neovim
|
||||||
|
|
||||||
|
## nvim-treesitter
|
||||||
|
|
||||||
|
To use this parser in neovim, configure [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter).
|
||||||
|
|
||||||
|
### nvim-treesitter `main` (new API)
|
||||||
|
|
||||||
|
Use this if you are on the rewritten `main` branch (Neovim 0.12+):
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.api.nvim_create_autocmd('User', {
|
||||||
|
pattern = 'TSUpdate',
|
||||||
|
callback = function()
|
||||||
|
require('nvim-treesitter.parsers').dotenv = {
|
||||||
|
install_info = {
|
||||||
|
url = 'https://github.com/pnx/tree-sitter-dotenv',
|
||||||
|
},
|
||||||
|
filetype = "dotenv"
|
||||||
|
}
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### nvim-treesitter `master` (legacy API)
|
||||||
|
|
||||||
|
Use this if you are on the legacy `master` branch (Neovim 0.10/0.11), add this to `config` block:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
config = function(_, opts)
|
||||||
|
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
|
||||||
|
|
||||||
|
-- Tell treesitter where dotenv parser is located
|
||||||
|
parser_config.dotenv = {
|
||||||
|
install_info = {
|
||||||
|
url = "https://github.com/pnx/tree-sitter-dotenv",
|
||||||
|
branch = "main",
|
||||||
|
files = { "src/parser.c", "src/scanner.c" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.filetype.add({
|
||||||
|
filename = {
|
||||||
|
['.env'] = 'dotenv',
|
||||||
|
},
|
||||||
|
pattern = {
|
||||||
|
['%.env%..+'] = 'dotenv',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run `:TSInstall dotenv`.
|
||||||
|
|
||||||
|
## Syntax highlighting
|
||||||
|
|
||||||
|
In order for neovim to know how to color the text, a `highlights.scm` file is needed.
|
||||||
|
Copy [highlights.scm](../queries/highlights.scm) from this repo to your nvim config under `queries/dotenv/highlights.scm`
|
||||||
Loading…
Add table
Add a link
Reference in a new issue