PaysanCorrezien / nvim-treesitter-powershell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nvim-treesitter-powershell

Powershell grammar for tree-sitter

Forked from github

Description

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

Build manualy

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

Build by Neovim

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).

Neovim TS Windows

Manual setup

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,
	},
}

Using the Queries

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

Tips

To use fold based on treesitter you need this in your config :

vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"

Shortcomings

  • Not all the possibles queries types are covered (indents,locals, etc... )
  • The parser dont detect everything perfectly (ex: comment block )

References

About

License:MIT License


Languages

Language:C 99.1%Language:JavaScript 0.7%Language:Scheme 0.1%Language:Rust 0.1%Language:C++ 0.0%Language:Python 0.0%