From 5149f0c6557fa4a492d82895a564f4cd4a9c7715 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 7 Feb 2022 17:05:41 -0300 Subject: [PATCH] add rescript --- README.md | 4 +-- lua/nvim-ts-autotag/internal.lua | 10 +++--- sample/index.res | 18 ++++++++++ tests/closetag_spec.lua | 58 ++++++++++++++++++++++++++++++++ tests/renametag_spec.lua | 38 +++++++++++++++++++++ 5 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 sample/index.res diff --git a/README.md b/README.md index b6d8f4d..8c86784 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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', diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index 75db513..fa59501 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -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', @@ -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'}, } diff --git a/sample/index.res b/sample/index.res new file mode 100644 index 0000000..eb94cf8 --- /dev/null +++ b/sample/index.res @@ -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" + +
+ + + + + +
+} diff --git a/tests/closetag_spec.lua b/tests/closetag_spec.lua index 34deee7..11a4bb4 100644 --- a/tests/closetag_spec.lua +++ b/tests/closetag_spec.lua @@ -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}, @@ -186,6 +199,51 @@ local data = { before = [[| ]] }, + { + name = "19 rescript close tag", + filepath = './sample/index.res', + filetype = 'rescript', + linenr = 12, + key = [[>]], + before = [[|]] + }, + { + name = "20 rescript close", + filepath = './sample/index.res', + filetype = 'rescript', + linenr = 13, + key = [[>]], + before = [[
|
]], + }, + { + name = "21 rescript not close on exist tag" , + filepath = './sample/index.res', + filetype = "rescript", + linenr = 14, + key = [[>]], + before = [[
]], + after = [[
|
]] + }, + { + name = "22 rescript not close on close tag" , + filepath = './sample/index.res', + filetype = "rescript", + linenr = 15, + key = [[>]], + before = [[|]] + }, + { + name = "23 rescrpt not close on expresion" , + filepath = './sample/index.res', + filetype = "rescript", + linenr = 15, + key = [[>]], + before = [[ ]], + after = [[ ]] + }, } local run_data = {} for _, value in pairs(data) do diff --git a/tests/renametag_spec.lua b/tests/renametag_spec.lua index e87a567..7eba727 100644 --- a/tests/renametag_spec.lua +++ b/tests/renametag_spec.lua @@ -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') @@ -162,6 +173,33 @@ local data = { before = [[]], after = [[]] }, + { + name = "21 rescript rename open tag" , + filepath = './sample/index.res', + filetype = "rescript", + linenr = 12, + key = [[ciwlala]], + before = [[ dsadsa ]], + after = [[ dsadsa ]] + }, + { + name = "22 rescript rename open tag with attr" , + filepath = './sample/index.res', + filetype = "rescript", + linenr = 12, + key = [[ciwlala]], + before = [[ dsadsa ]], + after = [[ dsadsa ]] + }, + { + name = "23 rescript rename close tag with attr" , + filepath = './sample/index.res', + filetype = "rescript", + linenr = 12, + key = [[ciwlala]], + before = [[
dsadsa ]], + after = [[ dsadsa ]] + }, -- { -- only = true, -- name = "18 rename node to empty node " ,