Compare commits

...

8 Commits

Author SHA1 Message Date
6eb4120a1a
Merge pull request #187 from seanbreckenridge/allow-empty-setup 2024-06-01 22:31:06 -05:00
seanbreckenridge
b873197cc5
use ? instead of nil
Co-authored-by: Price Hiller <price@orion-technologies.io>
2024-06-01 20:28:48 -07:00
Sean Breckenridge
ced3f1c780 fix: update luadoc to allow for empty setup call 2024-06-01 14:52:28 -07:00
bcf3146864
test: add tests for the templ filetype
Closes #179
2024-05-29 12:39:59 -05:00
e907a7ebe2
docs: add note about treesitter parsers
Closes #186
2024-05-29 12:28:08 -05:00
8ae54b90e3
Merge pull request #184 from cbochs/fix-183
fix: wrap vim.treesitter.get_parser in pcall
2024-05-22 18:20:40 -05:00
Calvin Bochulak
3d96e2c9f1
fix: add pcall to other uses of vim.treesitter.get_parser 2024-05-22 16:58:47 -06:00
Calvin Bochulak
5c93dfdfb3
fix: wrap vim.treesitter.get_parser in pcall 2024-05-22 16:47:43 -06:00
9 changed files with 147 additions and 9 deletions

View File

@ -36,6 +36,9 @@ Before Input After
Requires `Nvim 0.9.5` and up.
Note that `nvim-ts-autotag` will not work unless you have treesitter parsers (like `html`) installed for a given
filetype. See [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) for installing parsers.
```lua
require('nvim-ts-autotag').setup({
opts = {

View File

@ -141,7 +141,7 @@ local Setup = {
}
--- Do general plugin setup
---@param opts nvim-ts-autotag.PluginSetup
---@param opts nvim-ts-autotag.PluginSetup?
function Setup.setup(opts)
opts = opts or {}
if Setup.did_setup then

View File

@ -243,8 +243,8 @@ local function check_close_tag(close_slash_tag)
end
M.close_tag = function()
local buf_parser = vim.treesitter.get_parser()
if not buf_parser then
local ok, buf_parser = pcall(vim.treesitter.get_parser)
if not ok then
return
end
buf_parser:parse(true)
@ -256,8 +256,8 @@ M.close_tag = function()
end
M.close_slash_tag = function()
local buf_parser = vim.treesitter.get_parser()
if not buf_parser then
local ok, buf_parser = pcall(vim.treesitter.get_parser)
if not ok then
return
end
buf_parser:parse(true)
@ -430,8 +430,8 @@ local is_before_arrow = is_before("<", 0)
M.rename_tag = function()
if is_before_word() then
local parser = vim.treesitter.get_parser()
if not parser then
local ok, parser = pcall(vim.treesitter.get_parser)
if not ok then
return
end
parser:parse(true)

View File

@ -65,8 +65,8 @@ M.get_node_at_cursor = function(winnr)
local row, col = unpack(vim.api.nvim_win_get_cursor(winnr))
row = row - 1
local buf = vim.api.nvim_win_get_buf(winnr)
local root_lang_tree = vim.treesitter.get_parser(buf)
if not root_lang_tree then
local ok, root_lang_tree = pcall(vim.treesitter.get_parser, buf)
if not ok then
return
end

13
sample/index.templ Normal file
View File

@ -0,0 +1,13 @@
package main
templ hello(name string) {
<div class="">Hello, { name }</div>
}
templ foo(name string) {
<div>
@hello(name)
</div>
}

View File

@ -73,6 +73,7 @@ function M.setup_treesitter()
"php",
"glimmer",
"rescript",
"templ",
"embedded_template",
},
})

View File

@ -163,6 +163,42 @@ local data = {
before = [[<%= <div| %>]],
after = [[<%= <div/| %> ]],
},
{
name = "19 templ close tag after inputting /",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/]],
before = [[<div><| ]],
after = [[<div></div>|]],
},
{
name = "20 templ close tag after inputting /",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/]],
before = [[<div clas="laa"><| ]],
after = [[<div clas="laa"></div>|]],
},
{
name = "21 templ don't close tag when no opening tag is found",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/>]],
before = [[<div><|</div> ]],
after = [[<div></>|</div>]],
},
{
name = "22 templ not close inside quote",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[/]],
before = [[<div class="aa|"> </div> ]],
after = [[<div class="aa/|"> </div> ]],
},
}
local autotag = require("nvim-ts-autotag")

View File

@ -201,6 +201,42 @@ local data = {
before = [[<%= <div| %>]],
after = [[<%= <div>| %> ]],
},
{
name = "21 templ close tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<div| ]],
after = [[<div>|</div>]],
},
{
name = "22 templ close tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<div clas="laa"| ]],
after = [[<div clas="laa">|</div>]],
},
{
name = "23 templ not close tag on close tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<div>aa</div| ]],
after = [[<div>aa</div>|]],
},
{
name = "24 templ not close on input tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[>]],
before = [[<input| ]],
after = [[<input>| ]],
},
}
local autotag = require("nvim-ts-autotag")

View File

@ -302,6 +302,55 @@ local data = {
},
after = [[<%= <div></lala|> %>]],
},
{
name = "templ rename open tag",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[ciwlala]],
before = [[<di|v> dsadsa </div> ]],
after = [[<lala|> dsadsa </lala> ]],
},
{
name = "templ rename open tag with attr",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[ciwlala]],
before = [[<di|v class="lla"> dsadsa </div> ]],
after = [[<lala| class="lla"> dsadsa </lala|> ]],
},
{
name = "templ rename close tag with attr",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[ciwlala]],
before = [[<div class="lla"> dsadsa </di|v> ]],
after = [[<lala class="lla"> dsadsa </lal|a> ]],
},
{
name = "templ not rename close tag on char <",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 10,
key = [[i<]],
before = [[<div class="lla"> dsadsa |/button> ]],
after = [[<div class="lla"> dsadsa <|/button> ]],
},
{
name = "templ not rename close tag with not valid",
filepath = "./sample/index.templ",
filetype = "templ",
linenr = 11,
key = [[ciwlala]],
before = {
[[<di|v class="lla" ]],
[[ dsadsa </div>]],
},
after = [[<lala class="lla" ]],
},
}
local autotag = require("nvim-ts-autotag")