Skip to content

Commit

Permalink
Merge pull request #17 from dlvandenberg/filetype-change
Browse files Browse the repository at this point in the history
Filetype change
  • Loading branch information
dlvandenberg authored Mar 12, 2024
2 parents a1b5ff4 + edfedb3 commit 52594e2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 103 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,3 @@ jobs:
node-version: 18
- run: npm install
- run: npm run test:windows

tag_release:
runs-on: ubuntu-latest
if: github.ref_name == github.event.repository.default_branch
steps:
- name: Create tag
uses: mathieudutour/github-tag-action@v6.1
id: tag_version
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Create release
uses: ncipollo/release-action@v1.14.0
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: ${{ steps.tag_version.outputs.new_version }}
body: ${{ steps.tag_version.outputs.changelog }}
27 changes: 27 additions & 0 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tag and release

on:
workflow_dispatch:
inputs:
version:
description: Manually set release version
required: false
type: string

jobs:
tag_release:
runs-on: ubuntu-latest
steps:
- name: Create tag
uses: mathieudutour/github-tag-action@v6.1
id: tag_version
with:
custom_tag: ${{ inputs.version }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Create release
uses: ncipollo/release-action@v1.14.0
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: ${{ steps.tag_version.outputs.new_version }}
body: ${{ steps.tag_version.outputs.changelog }}
99 changes: 13 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,99 +24,26 @@ This parser extends [tree-sitter-html](https://github.com/tree-sitter/tree-sitte

## Filetype

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

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

## Plugins

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.

### VonHeikemen/lsp-zero.nvim

Add this to your config:

```lua
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" },
})
```

### stevearc/conform.nvim

Add this to your config:

```lua
conform.setup({
formatters_by_ft = {
angular = { "prettier" },
}

...
}
```

### numToStr/Comment.nvim

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

```lua
config = function()
local comment = require("Comment")
local ft = require("Comment.ft")

local commentstr = "<!--%s-->"

ft.set("angular", { commentstr, commentstr })
vim.filetype.add({
pattern = {
[".*%.component%.html"] = "angular.html", -- Sets the filetype to `angular.html` if it matches the pattern
},
})

comment.setup()
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,
})
```

### tpope/vim-commentary

Add this to `~/.config/nvim/ftdetect/angular.vim`:

```
autocmd FileType angular setlocal commentstring=<!--%s-->
```

### L3MON4D3/LuaSnip

Add this to your config:

```lua
local ls = require('luasnip');
ls.filetype_extend('angular', { 'html' })
```

### nvimtools/none-ls.nvim

Add `angular` to `extra_filetypes` wherever needed.

For example:

```lua
require('null-ls').setup({
sources = {
null_ls.builtins.formatting.prettierd.with({
extra_filetypes = { 'angular' }
}),
},
});

```
By setting the filetype to `angular.html`, other functionality of nvim or other plugins should still work.

## Issues

Expand Down

0 comments on commit 52594e2

Please sign in to comment.