From 3783df57058836a10d658f4c07eadf0237ed3846 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 20 May 2024 23:02:42 +0200 Subject: [PATCH] feat: initial commit --- lua/ts-comments.lua | 69 +++++++++++++++++++++++++++++++++++++++++++++ selene.toml | 1 + stylua.toml | 6 ++++ vim.toml | 49 ++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 lua/ts-comments.lua create mode 100644 selene.toml create mode 100644 stylua.toml create mode 100644 vim.toml diff --git a/lua/ts-comments.lua b/lua/ts-comments.lua new file mode 100644 index 0000000..c4d5d5a --- /dev/null +++ b/lua/ts-comments.lua @@ -0,0 +1,69 @@ +local M = {} + +local defaults = { + ---@type table> + lang = { + astro = "", + c = "// %s", + cpp = "// %s", + css = "/* %s */", + gleam = "// %s", + glimmer = "{{! %s }}", + graphql = "# %s", + handlebars = "{{! %s }}", + hcl = "# %s", + html = "", + ini = "; %s", + php = "// %s", + rego = "# %s", + rescript = "// %s", + sql = "-- %s", + svelte = "", + terraform = "# %s", + tsx = { + _ = "// %s", + call_expression = "// %s", + comment = "// %s", + jsx_attribute = "// %s", + jsx_element = "{/* %s */}", + jsx_fragment = "{/* %s */}", + spread_element = "// %s", + statement_block = "// %s", + }, + twig = "{# %s #}", + typescript = "// %s", + vim = '" %s', + vue = "", + }, +} +defaults.lang.javascript = vim.deepcopy(defaults.lang.tsx) + +function M.setup(opts) + opts = vim.tbl_deep_extend("force", defaults, opts or {}) + + local get_option = vim.filetype.get_option + vim.filetype.get_option = function(filetype, option) + if option ~= "commentstring" then + return get_option(filetype, option) + end + local lang = vim.treesitter.language.get_lang(filetype) + + local ret = opts.lang[lang] + if type(ret) == "table" then + local node = vim.treesitter.get_node({ ignore_injections = false }) + while node do + if ret[node:type()] then + ret = ret[node:type()] + break + end + node = node:parent() + end + if type(ret) == "table" then + ret = ret._ + end + end + return ret or get_option(filetype, option) + end +end + +return M diff --git a/selene.toml b/selene.toml new file mode 100644 index 0000000..7312a91 --- /dev/null +++ b/selene.toml @@ -0,0 +1 @@ +std="vim" diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..9732fe6 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,6 @@ +indent_type = "Spaces" +indent_width = 2 +column_width = 120 +[sort_requires] +enabled = true + diff --git a/vim.toml b/vim.toml new file mode 100644 index 0000000..4206f6c --- /dev/null +++ b/vim.toml @@ -0,0 +1,49 @@ +[selene] +base = "lua51" +name = "vim" + +[vim] +any = true + +[jit] +any = true + +[[describe.args]] +type = "string" +[[describe.args]] +type = "function" + +[[it.args]] +type = "string" +[[it.args]] +type = "function" + +[[before_each.args]] +type = "function" +[[after_each.args]] +type = "function" + +[assert.is_not] +any = true + +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +required = false + +[[assert.same.args]] +type = "any" +[[assert.same.args]] +type = "any" + +[[assert.truthy.args]] +type = "any" + +[[assert.spy.args]] +type = "any" + +[[assert.stub.args]] +type = "any"