Powershell grammar for tree-sitter
Forked from github
This is a simple fork, with a prebuild powershell.so
that nvim-tree-sitter can use.
It also include somes of the additionals files that nvim-tree-sitter need to work properly :
./queries/highlights.scm ./queries/textobjects.scm ./queries/folds.scm
Most of the features from nvim-tree-sitter textobjects are working just fine.
Perfect to work with Mini.ai
zig cc -shared -o powershell.so src/parser.c src/scanner.c -Isrc
clang -shared -o powershell.dll src/parser.c src/scanner.c -Isrc
There is a issue to build automatically with default neovim on windows. GCC installed through choco install mingw
can't build on my system.
The workaround is to use zig choco install zig
and set is a default on nvim (see below).
This is my setup on LazyVIM
, but the setup should be similar on a standard nvim setup.
./plugins/tree-sitter.lua
:
return {
{
"nvim-treesitter/nvim-treesitter",
config = function()
-- Set preferred compiler order
local install = require("nvim-treesitter.install")
install.compilers = { "zig", "gcc" } --Use zig as default
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.powershell = {
install_info = {
url = parser_path, -- Directory of the installed parser ex "~/repo/tree-sitter-powershell/"
files = { "src/parser.c", "src/scanner.c" }, -- Both need to be include in the build process of it fail
branch = "main",
},
filetype = "ps1", -- Associate the parser with 'ps1' files
}
end,
},
}
Copy the .scm
files that are i queries
folder in ~/.config/nvim/queries/powershell/
or any other folder where neovim can access them : Neovim Docs
To use fold based on treesitter you need this in your config :
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
- Not all the possibles queries types are covered (indents,locals, etc... )
- The parser dont detect everything perfectly (ex: comment block )