This parser is a complete rewrite of steelsojka's tree-sitter-angular. This parser extends tree-sitter-html because the new Control Flow syntax is not valid HTML code.
- Structural Directives
- Property binding
- Event binding
- String interpolation
- If-statements (v17)
- For-statements (v17)
- Switch-statements (v17)
- Defer-statements (v17)
By default Angular's template files are marked as HTML. In order for this parser to work, it has to be marked as angular
.
Currently Neovim does not do that yet, so to automatically set the filetype for Angular components, put:
autocmd BufRead,BufEnter *.component.html set filetype=angular
in ~/.config/nvim/ftdetect/angular.vim
.
Alternatively, you can use :set filetype=angular
on a given buffer.
As this parser works on angular
filetypes, it will cause other plugins to possibly not work correctly. Below are some fixes for the plugins that I use which I had to modify.
Add this to your config:
local config = require("lspconfig")
local util = require("lspconfig.util")
config.angularls.setup({
root_dir = util.root_pattern("angular.json", "project.json"), -- This is for monorepo's
filetypes = { "angular", "html", "typescript", "typescriptreact" },
})
Add this to your config:
conform.setup({
formatters_by_ft = {
angular = { "prettier" },
}
...
}
Add this to your config:
config = function()
local comment = require("Comment")
local ft = require("Comment.ft")
local commentstr = "<!--%s-->"
ft.set("angular", { commentstr, commentstr })
comment.setup()
end,
If you experience any issues, please feel free to open an issue with the code that's causing problems.