Skip to content

Commit

Permalink
chore: update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvandenberg committed Jul 18, 2024
1 parent fe9da94 commit fd8ff97
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ This parser extends [tree-sitter-html](https://github.com/tree-sitter/tree-sitte
- [x] Defer-statements (v17)
- [x] ICU message format

## Requirements

- [Neovim](https://neovim.io/) nightly recommended (as it includes the filetype detection of Angular Templates)

## Filetype

By default Angular's template files are marked as HTML and it will use the HTML parser. To use the Angular parser instead, you will need to create a _plugin_ that sets the filetype correctly and registers the filetype for the `angular` parser in treesitter.
In the nightly neovim built (or release 0.11.x), the filetype detection for Angular templates is included. It will detect Angular HTML templates, based on it's contents, and set the filetype to `htmlangular`.

If you are using an older version, you must set the filetype yourself.

E.g. mark the file as `htmlangular` if it matches the pattern `*.component.html`:

Create a `plugin` in `~/.config/nvim/plugin/angular.lua` with the following:

Expand All @@ -35,20 +43,15 @@ vim.filetype.add({
[".*%.component%.html"] = "angular.html", -- Sets the filetype to `angular.html` if it matches the pattern
},
})

vim.api.nvim_create_autocmd("FileType", {
pattern = "angular.html",
callback = function()
vim.treesitter.language.register("angular", "angular.html") -- Register the filetype with treesitter for the `angular` language/parser
end,
})
```

You may need to include this new filetype (`angular.html`) for other plugins, like [LSP](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#angularls) for example:
## LSP's or other plugins

You may need to include this new filetype (`htmlangular`) for other plugins, like [LSP](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#angularls) for example:

```lua
require('lspconfig').angularls.setup {
filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx', 'angular.html' }
filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx', 'htmlangular' }
}
```

Expand Down

0 comments on commit fd8ff97

Please sign in to comment.