Add default value for template

This commit is contained in:
Daniel Mathiot
2021-08-27 21:19:19 +02:00
parent 2c9936781f
commit 1d97f1415e
3 changed files with 24 additions and 7 deletions

View File

@@ -55,13 +55,24 @@ neogen.generate = function(opts)
if #content ~= 0 then
local jump_text = language.jump_text or neogen.configuration.jump_text
--- Removes jump_text marks and keep the second part of jump_text|other_text if there is one (which is other_text)
local delete_marks = function(v)
return string.gsub(v, jump_text, "")
local pattern = jump_text.. "[|%w]+"
local matched = string.match(v, pattern)
if matched then
local split = vim.split(matched, "|", true)
if #split == 2 then
return string.gsub(v, jump_text .. "|", "")
end
else
return string.gsub(v, jump_text, "")
end
end
local content_with_marks = vim.deepcopy(content)
-- delete all jump_text marks
neogen.utilities.cursor.replace_jump_text(content, language.template)
content = vim.tbl_map(delete_marks, content)
-- Append the annotation in required place
@@ -107,3 +118,4 @@ neogen.setup = function(opts)
end
return neogen

View File

@@ -118,10 +118,10 @@ return {
emmylua = {
{ nil, "- $1", { type = { "class", "func" } } }, -- add this string only on requested types
{ nil, "- $1", { no_results = true } }, -- Shows only when there's no results from the granulator
{ "parameters", "- @param %s any $1" },
{ "vararg", "- @vararg any $1" },
{ "return_statement", "- @return any $1" },
{ "class_name", "- @class any $1" },
{ "parameters", "- @param %s $1|any" },
{ "vararg", "- @vararg $1|any" },
{ "return_statement", "- @return $1|any" },
{ "class_name", "- @class $1|any" },
{ "type", "- @type %s $1" },
},
},

View File

@@ -37,4 +37,9 @@ neogen.utilities.cursor.jump = function()
end
end
neogen.utilities.cursor.replace_jump_text = function(content, template) end
neogen.utilities.cursor.del_extmarks = function()
local extmarks = vim.api.nvim_buf_get_extmarks(0, neogen_ns, 0, -1, {})
for _,v in pairs(extmarks) do
vim.api.nvim_buf_del_extmark(0, neogen_ns, v[1])
end
end