Skip to content

Commit

Permalink
add rescript
Browse files Browse the repository at this point in the history
  • Loading branch information
aspeddro authored and windwp committed Feb 9, 2022
1 parent 5bbdfda commit 5149f0c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Use treesitter to **autoclose** and **autorename** html tag

It work with html,tsx,vue,svelte,php.
It work with html,tsx,vue,svelte,php,rescript.

## Usage

Expand Down Expand Up @@ -56,7 +56,7 @@ vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(

``` lua
local filetypes = {
'html', 'javascript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue'
'html', 'javascript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'rescript'
}
local skip_tags = {
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'slot',
Expand Down
10 changes: 5 additions & 5 deletions lua/nvim-ts-autotag/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local log = require('nvim-ts-autotag._log')
local M = {}

M.tbl_filetypes = {
'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx',
'html', 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'svelte', 'vue', 'tsx', 'jsx', 'rescript',
'xml',
'php',
'markdown',
Expand Down Expand Up @@ -36,14 +36,14 @@ local HTML_TAG = {
local JSX_TAG = {
filetypes = {
'typescriptreact', 'javascriptreact', 'javascript.jsx',
'typescript.tsx', 'javascript', 'typescript'},
'typescript.tsx', 'javascript', 'typescript', 'rescript'},

start_tag_pattern = 'jsx_opening_element',
start_name_tag_pattern = 'identifier|nested_identifier',
start_name_tag_pattern = 'identifier|nested_identifier|jsx_identifier',
end_tag_pattern = "jsx_closing_element",
end_name_tag_pattern = "identifier",
end_name_tag_pattern = "identifier|jsx_identifier",
close_tag_pattern = 'jsx_closing_element',
close_name_tag_pattern = 'identifier|nested_identifier',
close_name_tag_pattern = 'identifier|nested_identifier|jsx_identifier',
element_tag = 'jsx_element',
skip_tag_pattern = {'jsx_closing_element','jsx_expression', 'string', 'jsx_attribute'},
}
Expand Down
18 changes: 18 additions & 0 deletions sample/index.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@react.component
let make = () => {
let (count, setCount) = React.useState(_ => 0);

let onClick = (_evt) => {
setCount(prev => prev + 1)
};

let msg = "You clicked" ++ Belt.Int.toString(count) ++ "times"

<div>





</div>
}
58 changes: 58 additions & 0 deletions tests/closetag_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ if not _G.test_close then
return
end

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
local ts = require 'nvim-treesitter.configs'
local helpers = {}

parser_config.rescript = {
install_info = {
url = "https://github.com/nkrkv/nvim-treesitter-rescript",
files = {"src/parser.c", "src/scanner.c"},
branch = "main",
},
maintainers = { "@nkrkv" },
filetype = "rescript",
}


ts.setup {
ensure_installed = 'maintained',
highlight = {enable = true},
Expand Down Expand Up @@ -186,6 +199,51 @@ local data = {
before = [[<div| ]],
after = [[<div>|</div> ]]
},
{
name = "19 rescript close tag",
filepath = './sample/index.res',
filetype = 'rescript',
linenr = 12,
key = [[>]],
before = [[<Img|]],
after = [[<Img>|</Img>]]
},
{
name = "20 rescript close",
filepath = './sample/index.res',
filetype = 'rescript',
linenr = 13,
key = [[>]],
before = [[<div class="abc"|]],
after = [[<div class="abc">|</div>]],
},
{
name = "21 rescript not close on exist tag" ,
filepath = './sample/index.res',
filetype = "rescript",
linenr = 14,
key = [[>]],
before = [[<div><div|</div></div>]],
after = [[<div><div>|</div></div>]]
},
{
name = "22 rescript not close on close tag" ,
filepath = './sample/index.res',
filetype = "rescript",
linenr = 15,
key = [[>]],
before = [[<button onClick> </button|]],
after = [[<button onClick> </button>|]]
},
{
name = "23 rescrpt not close on expresion" ,
filepath = './sample/index.res',
filetype = "rescript",
linenr = 15,
key = [[>]],
before = [[<button onClick>{|}</button> ]],
after = [[<button onClick>{>|}</button> ]]
},
}
local run_data = {}
for _, value in pairs(data) do
Expand Down
38 changes: 38 additions & 0 deletions tests/renametag_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
local ts = require 'nvim-treesitter.configs'
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()

parser_config.rescript = {
install_info = {
url = "https://github.com/nkrkv/nvim-treesitter-rescript",
files = {"src/parser.c", "src/scanner.c"},
branch = "main",
},
maintainers = { "@nkrkv" },
filetype = "rescript",
}

local log=require('nvim-ts-autotag._log')

Expand Down Expand Up @@ -162,6 +173,33 @@ local data = {
before = [[<data></da|ta>]],
after = [[<lala></lala>]]
},
{
name = "21 rescript rename open tag" ,
filepath = './sample/index.res',
filetype = "rescript",
linenr = 12,
key = [[ciwlala]],
before = [[<di|v> dsadsa </div> ]],
after = [[<lala|> dsadsa </lala> ]]
},
{
name = "22 rescript rename open tag with attr" ,
filepath = './sample/index.res',
filetype = "rescript",
linenr = 12,
key = [[ciwlala]],
before = [[<di|v class="lla"> dsadsa </div> ]],
after = [[<lala| class="lla"> dsadsa </lala> ]]
},
{
name = "23 rescript rename close tag with attr" ,
filepath = './sample/index.res',
filetype = "rescript",
linenr = 12,
key = [[ciwlala]],
before = [[<div class="lla"> dsadsa </di|v> ]],
after = [[<lala class="lla"> dsadsa </lala|> ]]
},
-- {
-- only = true,
-- name = "18 rename node to empty node " ,
Expand Down

0 comments on commit 5149f0c

Please sign in to comment.