diff --git a/lua/luasnip/loaders/from_snipmate.lua b/lua/luasnip/loaders/from_snipmate.lua index c9f251186..364de78bc 100644 --- a/lua/luasnip/loaders/from_snipmate.lua +++ b/lua/luasnip/loaders/from_snipmate.lua @@ -47,14 +47,18 @@ local function parse_snipmate(buffer, filename) end body = table.concat(body, "\n") - local snip = sp({ - trig = prefix, - dscr = description, - wordTrig = true, - priority = snipmate_opts.priority, - }, body, { - parse_fn = snipmate_parse_fn - }) + local snip = sp( + { + trig = prefix, + dscr = description, + wordTrig = true, + priority = snipmate_opts.priority, + }, + body, + { + parse_fn = snipmate_parse_fn, + } + ) table.insert(snippets[snippet_type], snip) end diff --git a/lua/luasnip/nodes/dynamicNode.lua b/lua/luasnip/nodes/dynamicNode.lua index c5ed2268b..924f5a339 100644 --- a/lua/luasnip/nodes/dynamicNode.lua +++ b/lua/luasnip/nodes/dynamicNode.lua @@ -45,7 +45,7 @@ function DynamicNode:get_static_text() if self.snip then return self.snip:get_static_text() else - return {""} + return { "" } end end end diff --git a/lua/luasnip/nodes/functionNode.lua b/lua/luasnip/nodes/functionNode.lua index ec46a97d4..b028a224a 100644 --- a/lua/luasnip/nodes/functionNode.lua +++ b/lua/luasnip/nodes/functionNode.lua @@ -118,10 +118,16 @@ function FunctionNode:set_dependents() -- appends the key. -- Maybe this is stupid?? if rawget(arg, "type") ~= nil then - dict:set(vim.list_extend({arg}, append_list), self) + dict:set(vim.list_extend({ arg }, append_list), self) elseif arg.absolute_insert_position then -- copy, list_extend mutates. - dict:set(vim.list_extend(vim.deepcopy(arg.absolute_insert_position), append_list), self) + dict:set( + vim.list_extend( + vim.deepcopy(arg.absolute_insert_position), + append_list + ), + self + ) end end end diff --git a/lua/luasnip/nodes/node.lua b/lua/luasnip/nodes/node.lua index 6ba543251..84466d8db 100644 --- a/lua/luasnip/nodes/node.lua +++ b/lua/luasnip/nodes/node.lua @@ -151,7 +151,10 @@ local function find_dependents(self, position_self, dict) vim.list_extend(nodes, dict:find_all(position_self, "dependent") or {}) position_self[#position_self] = nil - vim.list_extend(nodes, dict:find_all({self, "dependents"}, "dependent") or {}) + vim.list_extend( + nodes, + dict:find_all({ self, "dependents" }, "dependent") or {} + ) return nodes end @@ -251,7 +254,9 @@ local function get_args(node, get_text_func_name) -- the node is not (yet, maybe) visible. return nil end - local arg_table = node.parent.snippet.dependents_dict:get(arg.absolute_insert_position) + local arg_table = node.parent.snippet.dependents_dict:get( + arg.absolute_insert_position + ) if not arg_table then return nil end diff --git a/lua/luasnip/nodes/snippetProxy.lua b/lua/luasnip/nodes/snippetProxy.lua index 93708ba83..7b2b905fb 100644 --- a/lua/luasnip/nodes/snippetProxy.lua +++ b/lua/luasnip/nodes/snippetProxy.lua @@ -46,7 +46,7 @@ end -- some values of the snippet are nil by default, list them here so snippets -- aren't instantiated because of them. -local license_to_nil = {priority = true} +local license_to_nil = { priority = true } -- context and opts are (almost) the same objects as in s(contex, nodes, opts), snippet is a string representing the snippet. -- opts can aditionally contain the key `parse_fn`, which will be used to parse diff --git a/lua/luasnip/nodes/util.lua b/lua/luasnip/nodes/util.lua index 9b3a74ebd..977d71449 100644 --- a/lua/luasnip/nodes/util.lua +++ b/lua/luasnip/nodes/util.lua @@ -39,7 +39,7 @@ local function make_args_absolute(args, parent_insert_position, target) -- parent. local t = vim.deepcopy(parent_insert_position) table.insert(t, arg) - target[i] = {absolute_insert_position = t} + target[i] = { absolute_insert_position = t } else -- insert node or absolute_indexer itself, node's absolute_insert_position may be nil, check for that during -- usage. diff --git a/lua/luasnip/util/directed_graph.lua b/lua/luasnip/util/directed_graph.lua index 26c1ea1e9..e22928ebb 100644 --- a/lua/luasnip/util/directed_graph.lua +++ b/lua/luasnip/util/directed_graph.lua @@ -11,7 +11,7 @@ Vertex.__index = Vertex local function new_graph() return setmetatable({ -- all vertices of this graph. - vertices = {} + vertices = {}, }, DirectedGraph) end local function new_vertex() @@ -19,7 +19,7 @@ local function new_vertex() -- vertices this vertex has an edge from/to. -- map[vert -> bool] incoming_edge_verts = {}, - outgoing_edge_verts = {} + outgoing_edge_verts = {}, }, Vertex) end @@ -125,7 +125,6 @@ function DirectedGraph:topological_sort() -- function (alternative: maybe return indices in graph.vertices?). table.insert(sorting, original_vert[v]) - -- find vertices which, if v is removed from graph, have no more incoming edges. -- Those are sources after v is removed. for outgoing_edge_vert, _ in pairs(v.outgoing_edge_verts) do diff --git a/lua/luasnip/util/environ.lua b/lua/luasnip/util/environ.lua index aa31e43bb..af8f6b341 100644 --- a/lua/luasnip/util/environ.lua +++ b/lua/luasnip/util/environ.lua @@ -134,9 +134,9 @@ _env_namespace("", builtin_namespace) function Environ.env_namespace(name, opts) assert( name:match("^[a-zA-Z][a-zA-Z0-9]*$"), - ( - "You can't create a namespace with name '%s' it has to contain only and at least a non alpha-numeric character" - ):format(name) + ("You can't create a namespace with name '%s' it has to contain only and at least a non alpha-numeric character"):format( + name + ) ) assert( not builtin_namespace.builtin_ns[name], diff --git a/lua/luasnip/util/functions.lua b/lua/luasnip/util/functions.lua index 3d6cd7989..9e0cf059e 100644 --- a/lua/luasnip/util/functions.lua +++ b/lua/luasnip/util/functions.lua @@ -33,10 +33,17 @@ return { eval_vim_dynamic = function(vimstring) return function() -- 'echo'd string is returned to lua. - return sn(nil, {t(vim.split( - vim.api.nvim_exec("echo " .. vimstring, true), - "\n" - ))}) + return sn( + nil, + { + t( + vim.split( + vim.api.nvim_exec("echo " .. vimstring, true), + "\n" + ) + ), + } + ) end end, copy = function(args) diff --git a/lua/luasnip/util/parser/ast_parser.lua b/lua/luasnip/util/parser/ast_parser.lua index 037057863..20f056a3b 100644 --- a/lua/luasnip/util/parser/ast_parser.lua +++ b/lua/luasnip/util/parser/ast_parser.lua @@ -83,7 +83,7 @@ local function var_func(ast) return variable_default else -- lines might still just be {} (#lines == 0). - lines = {""} + lines = { "" } end end @@ -124,7 +124,10 @@ local function placeholder_func(_, parent, _, placeholder_snip) return sNode.SN(nil, iNode.I(1, iText)) end - return sNode.SN(nil, session.config.parser_nested_assembler(1, placeholder_snip)) + return sNode.SN( + nil, + session.config.parser_nested_assembler(1, placeholder_snip) + ) end ---If this tabstop-node (CHOICE, TABSTOP or PLACEHOLDER) is a copy of another, @@ -135,7 +138,8 @@ local function tabstop_node_copy_inst(ast) local existing_tabstop_ast_node = ast.copies if existing_tabstop_ast_node then -- this tabstop is a mirror of an already-parsed tabstop/placeholder. - ast.parsed = fNode.F(copy_func(ast), { existing_tabstop_ast_node.parsed }) + ast.parsed = + fNode.F(copy_func(ast), { existing_tabstop_ast_node.parsed }) return true end return false @@ -186,7 +190,7 @@ local to_node_funcs = { local snip = sNode.SN(1, ast2luasnip_nodes(ast.children)) node = dNode.D(ast.tabstop, placeholder_func, {}, { -- pass snip here, again to preserve references to other tables. - user_args = {snip} + user_args = { snip }, }) end @@ -223,13 +227,13 @@ local to_node_funcs = { -- just wrap it for more uniformity. if type(var_value) == "string" then - var_value = {var_value} + var_value = { var_value } end if (#var_value == 1 and #var_value[1] == 0) - or #var_value == 0 then - + or #var_value == 0 + then -- var is empty, default is inserted. -- if no default, it's not interactive (an empty string is inserted). return default and default:is_interactive() @@ -262,16 +266,15 @@ local to_node_funcs = { -- just needs to be documented a bit. -- -- `default` is potentially nil. - user_args = {default} + user_args = { default }, }) d.is_interactive = is_interactive_fn -- if the variable is preceded by \n, the indent is applied to -- all lines of the variable (important for eg. TM_SELECTED_TEXT). if ast.previous_text ~= nil and #ast.previous_text > 1 then - local last_line_indent = ast.previous_text[#ast.previous_text]:match( - "^%s+$" - ) + local last_line_indent = + ast.previous_text[#ast.previous_text]:match("^%s+$") if last_line_indent then -- TM_SELECTED_TEXT contains the indent of the selected -- snippets, which leads to correct indentation if the @@ -333,7 +336,10 @@ function M.to_luasnip_nodes(ast, state) ast_utils.give_vars_previous_text(ast) local ast_nodes_topsort = ast_utils.parse_order(ast) - assert(ast_nodes_topsort, "cannot represent snippet: contains circular dependencies") + assert( + ast_nodes_topsort, + "cannot represent snippet: contains circular dependencies" + ) for _, node in ipairs(ast_nodes_topsort) do to_node(node, state) end diff --git a/lua/luasnip/util/parser/ast_utils.lua b/lua/luasnip/util/parser/ast_utils.lua index b78890c6c..9949982bd 100644 --- a/lua/luasnip/util/parser/ast_utils.lua +++ b/lua/luasnip/util/parser/ast_utils.lua @@ -223,10 +223,9 @@ function M.fix_zero(ast) or ( zn and not is_copied - and ( - zn.type == types.TABSTOP or - (zn.type == types.PLACEHOLDER and text_only_placeholder(zn)) - ) + and (zn.type == types.TABSTOP or (zn.type == types.PLACEHOLDER and text_only_placeholder( + zn + ))) and ast.children[ast_child_with_0_indx] == zn ) then @@ -241,10 +240,7 @@ function M.fix_zero(ast) -- insert $0 as a direct child to snippet, just behind the original $0/the -- node containing it. - table.insert( - ast.children, - ast_child_with_0_indx + 1, - Ast.tabstop(0)) + table.insert(ast.children, ast_child_with_0_indx + 1, Ast.tabstop(0)) end ---This function identifies which tabstops/placeholder/choices are copies, and @@ -352,10 +348,8 @@ end function M.apply_transform(transform) if jsregexp_ok then - local reg_compiled = jsregexp.compile( - transform.pattern, - transform.option - ) + local reg_compiled = + jsregexp.compile(transform.pattern, transform.option) -- can be passed to functionNode! return function(lines) -- luasnip expects+passes lines as list, but regex needs one string. @@ -370,13 +364,13 @@ function M.apply_transform(transform) for _, match in ipairs(matches) do -- begin_ind and end_ind are inclusive. transformed = transformed - .. lines:sub(prev_match_end+1, match.begin_ind - 1) + .. lines:sub(prev_match_end + 1, match.begin_ind - 1) .. apply_transform_format(transform.format, match.groups) -- end-inclusive prev_match_end = match.end_ind end - transformed = transformed .. lines:sub(prev_match_end+1, #lines) + transformed = transformed .. lines:sub(prev_match_end + 1, #lines) return vim.split(transformed, "\n") end @@ -396,7 +390,7 @@ end ---The text is accessible as ast_node.previous_text, a string[]. ---@param ast table: the AST. function M.give_vars_previous_text(ast) - local last_text = {""} + local last_text = { "" } -- important: predicate_ltr_nodes visits the node in the order they appear, -- textually, in the snippet. -- This is necessary to actually ensure the variables actually get the text just in front of them. @@ -420,7 +414,7 @@ function M.give_vars_previous_text(ast) node.previous_text = last_text else -- reset last_text when a different node is encountered. - last_text = {""} + last_text = { "" } end -- continue.. return false @@ -432,7 +426,7 @@ end ---variable is just some text, inserts its default, or its variable-name has to ---be deferred to runtime. ---So, each variable is a dynamicNode, and needs a tabstop. ----In vscode the variables are visited +---In vscode the variables are visited --- 1) after all other tabstops/placeholders/choices and --- 2) in the order they appear in the snippet-body. ---We mimic this behaviour. diff --git a/lua/luasnip/util/parser/init.lua b/lua/luasnip/util/parser/init.lua index eb5a04655..b46f9c869 100644 --- a/lua/luasnip/util/parser/init.lua +++ b/lua/luasnip/util/parser/init.lua @@ -40,7 +40,7 @@ function M.parse_snippet(context, body, opts) end local nodes = ast_parser.to_luasnip_nodes(ast, { - var_functions = opts.variables + var_functions = opts.variables, }) if type(context) == "number" then @@ -81,7 +81,8 @@ local function backticks_to_variable(body) .. "}" -- don't include backticks in vimscript. - var_map[varname] = functions.eval_vim_dynamic(body:sub(from + 1, to - 1)) + var_map[varname] = + functions.eval_vim_dynamic(body:sub(from + 1, to - 1)) processed_to = to + 1 variable_indx = variable_indx + 1 end @@ -100,7 +101,7 @@ function M.parse_snipmate(context, body, opts) opts.variables = {} for name, fn in pairs(new_vars) do -- created dynamicNode is not interactive. - opts.variables[name] = {fn, util.no} + opts.variables[name] = { fn, util.no } end return M.parse_snippet(context, body, opts) end diff --git a/lua/luasnip/util/parser/neovim_ast.lua b/lua/luasnip/util/parser/neovim_ast.lua index 3fe215c58..5fcd62510 100644 --- a/lua/luasnip/util/parser/neovim_ast.lua +++ b/lua/luasnip/util/parser/neovim_ast.lua @@ -187,7 +187,11 @@ function M.merge_adjacent_text(ast) -- When we do this is not important, since it does not change the TEXT-nodes, here is just comfortable. M.merge_adjacent_text(child) - if child.type == node_type.TEXT and last_child and last_child.type == node_type.TEXT then + if + child.type == node_type.TEXT + and last_child + and last_child.type == node_type.TEXT + then last_child.raw = last_child.raw .. child.raw last_child.esc = last_child.esc .. child.esc else diff --git a/lua/luasnip/util/parser/neovim_parser.lua b/lua/luasnip/util/parser/neovim_parser.lua index 47030ec57..1eaca860f 100644 --- a/lua/luasnip/util/parser/neovim_parser.lua +++ b/lua/luasnip/util/parser/neovim_parser.lua @@ -323,7 +323,13 @@ S.transform = P.map( S.slash, P.take_until({ "/" }, { "\\" }), S.slash, - P.many(P.any(S.format, S.text({ "$", "/" }, { "\\" }), S.patterntext("[^/]"))), + P.many( + P.any( + S.format, + S.text({ "$", "/" }, { "\\" }), + S.patterntext("[^/]") + ) + ), S.slash, P.opt(P.pattern("[ig]+")) ), @@ -351,7 +357,15 @@ S.placeholder = P.any( S.open, S.int, S.colon, - P.opt(P.many(P.any(S.toplevel, S.text({ "$", "}" }, { "\\" }), S.patterntext("[^}]")))), + P.opt( + P.many( + P.any( + S.toplevel, + S.text({ "$", "}" }, { "\\" }), + S.patterntext("[^}]") + ) + ) + ), S.close ), function(values) @@ -396,7 +410,13 @@ S.variable = P.any( S.open, S.var, S.colon, - P.many(P.any(S.toplevel, S.text({ "$", "}" }, { "\\" }), S.patterntext("[^}]"))), + P.many( + P.any( + S.toplevel, + S.text({ "$", "}" }, { "\\" }), + S.patterntext("[^}]") + ) + ), S.close ), function(values) @@ -406,7 +426,9 @@ S.variable = P.any( ) S.snippet = P.map( - P.many(P.any(S.toplevel, S.text({ "$" }, { "}", "\\" }), S.patterntext("."))), + P.many( + P.any(S.toplevel, S.text({ "$" }, { "}", "\\" }), S.patterntext(".")) + ), function(values) -- Insp(values) return ast.snippet(values) diff --git a/tests/helpers.lua b/tests/helpers.lua index 5e47d2cf5..23c96f142 100644 --- a/tests/helpers.lua +++ b/tests/helpers.lua @@ -6,7 +6,9 @@ local M = {} function M.setup_jsregexp() -- append default-path. - exec_lua(("package.cpath = \"%s\""):format(os.getenv("JSREGEXP_PATH") .. "/?.so;;")) + exec_lua( + ('package.cpath = "%s"'):format(os.getenv("JSREGEXP_PATH") .. "/?.so;;") + ) end function M.session_setup_luasnip() diff --git a/tests/integration/dynamic_spec.lua b/tests/integration/dynamic_spec.lua index d1ee4c5bd..a4cfb54cb 100644 --- a/tests/integration/dynamic_spec.lua +++ b/tests/integration/dynamic_spec.lua @@ -289,22 +289,22 @@ describe("DynamicNode", function() end) }) ]] - ls_helpers.static_docstring_test( - snip, - { "" }, - { "$1$2$0" } - ) + ls_helpers.static_docstring_test(snip, { "" }, { "$1$2$0" }) exec_lua("ls.snip_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) feed("some text") exec_lua("ls.active_update_dependents()") - screen:expect{grid=[[ + screen:expect({ + grid = [[ some text^some text | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it( diff --git a/tests/integration/parser_spec.lua b/tests/integration/parser_spec.lua index a1cc1ec6b..48f86af87 100644 --- a/tests/integration/parser_spec.lua +++ b/tests/integration/parser_spec.lua @@ -191,13 +191,18 @@ describe("Parser", function() -- /g matches as often as possible, hence two matches, but one with an -- empty (eg. without a) group 1. - ls_helpers.lsp_static_test(snip, { "aasdf $TM_LINE_INDEX asdfasdf asdfa" }) + ls_helpers.lsp_static_test( + snip, + { "aasdf $TM_LINE_INDEX asdfasdf asdfa" } + ) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ aasdf 0 asdfasdf asdfa^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("just inserts the variable if jsregexp is not available.", function() @@ -209,10 +214,12 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { "a$TM_LINE_INDEXa" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a0a^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("can parse transformed tabstop.", function() @@ -223,10 +230,12 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { " a asdf asdf a" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ a asdf asdf a | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("copies tabstop if jsregexp is not available.", function() ls_helpers.session_setup_luasnip() @@ -235,16 +244,20 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { " a a" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ a a | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) feed("asdf") exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ asdf a asdf a^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("modifies invalid $0 with choice.", function() @@ -256,24 +269,30 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { "asdf asdf asdf" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ asdf ^asdf asdf | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) -- choice is copied exec_lua("ls.change_choice(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ qwer ^qwer asdf | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) -- make sure $0 is actually behind choice. exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ qwer qwer^ asdf | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("modifies invalid $0 with choice nested in placeholder.", function() @@ -285,24 +304,30 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { "asdf asdf asdf" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ asdf ^ asdf asdf | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) -- jump to choice.. exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ asdf ^asdf asdf | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) -- and to new $0. exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ asdf asdf^ asdf | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("does not modify $0 which can be represented.", function() @@ -312,15 +337,19 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { "qwer asdf" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^q{3:wer} asdf | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^q{3:wer} asdf | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) end) it("turns the correct nodes into insert/functionNode", function() @@ -333,10 +362,12 @@ describe("Parser", function() -- actually not sure if this is how it should be, vscode just spawns -- multicursors :( - screen:expect{grid=[[ + screen:expect({ + grid = [[ asdf ^a{3:sdf} asdf | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) end) it("turns the correct nodes into insert/functionNode v2", function() @@ -349,10 +380,12 @@ describe("Parser", function() -- actually not sure if this is how it should be, vscode just spawns -- multicursors :( - screen:expect{grid=[[ + screen:expect({ + grid = [[ asdf ^a{3:sdf} asdf | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) end) it("can modify groups in transform.", function() @@ -363,16 +396,20 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { " a asdf asdf a" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ a asdf asdf a | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) feed("rrrr") exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ rrrr a asdf RRRR asdf a^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("handle multiple captures in transform.", function() @@ -383,16 +420,20 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { "bbb a B b a" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^b{3:bb} a B b a | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) feed("bbbbbb") exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ bbbbbb a B bB b a^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("can parse lazy variables.", function() @@ -416,11 +457,12 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { "a$MISSING_VARa" }) exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a^M{3:ISSING_VAR}a | {0:~ }| - {2:-- SELECT --} |]]} - + {2:-- SELECT --} |]], + }) end) it("can parse missing user defined variable in placeholder.", function() @@ -429,18 +471,21 @@ describe("Parser", function() ls_helpers.lsp_static_test(snip, { "a$MISSING_VARa" }) - -- Assure this is parsed into choice+insertNode. exec_lua("ls.lsp_expand(" .. snip .. ")") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a^MISSING_VARa | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a^M{3:ISSING_VAR}a | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) end) it("can parse user defined variable with namespace.", function() @@ -568,10 +613,12 @@ describe("Parser", function() exec_lua("ls.lsp_expand([[" .. snip .. "]])") -- the \t in front of $1 is extended to both lines of $TM_SELECTED_TEXT. - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^A{3:_VARIABLE_DOES_IT_EXIST_QUESTION_MARK} | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) end) it("Inserts default when the variable is empty", function() @@ -580,17 +627,21 @@ describe("Parser", function() exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a ^d{3:efault} | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) feed("ccSELECTED TEXTV") exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ SELECTED TEXT^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("Applies transform to empty variable.", function() @@ -600,10 +651,12 @@ describe("Parser", function() exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ asd ^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("correctly transforms multiline-values.", function() @@ -615,10 +668,12 @@ describe("Parser", function() feed("iasdfasdfVk") exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a asdf | asdf a^ | - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("handles default correctly inside placeholder", function() @@ -628,21 +683,27 @@ describe("Parser", function() exec_lua("ls.lsp_expand([[" .. snip .. "]])") -- variable with default is parsed into choice - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ a default | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a ^d{3:efault} | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) exec_lua("ls.change_choice()") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("handles copy-source inside default.", function() @@ -652,28 +713,34 @@ describe("Parser", function() exec_lua("ls.lsp_expand([[" .. snip .. "]])") -- variable with default is parsed into choice - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ a default copied copied | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) exec_lua("ls.jump(1)") exec_lua("ls.jump(1)") feed("still copied") exec_lua("ls.active_update_dependents()") - screen:expect{grid=[[ + screen:expect({ + grid = [[ a default still copied^ still copied | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) exec_lua("ls.change_choice()") -- this is somewhat debatable, should the functionNode disappear if -- there is no source? Right now it just doesn't update, I think that's -- okay. - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ still copied | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("handles copy inside default", function() @@ -682,17 +749,21 @@ describe("Parser", function() -- indent, insert text, SELECT. exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ a default | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) feed("third_tabstop") exec_lua("ls.jump(1)") - screen:expect{grid=[[ + screen:expect({ + grid = [[ third_tabstop ^ a default third_tabstop | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) it("can parse vim-stuff in snipmate-snippets.", function() @@ -700,10 +771,12 @@ describe("Parser", function() local snip = [["The year is ${1:`'lel' . 'lol'`}"]] exec_lua("ls.snip_expand(ls.parser.parse_snipmate('', " .. snip .. "))") - screen:expect{grid=[[ + screen:expect({ + grid = [[ The year is ^l{3:ellol} | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) end) it("can parse multiple vim-stuff in snipmate-snippets.", function() @@ -711,10 +784,12 @@ describe("Parser", function() local snip = [["The year is ${1:`'rrr' . 'adsf'`} ` 'leeeee' . 'l'` "]] exec_lua("ls.snip_expand(ls.parser.parse_snipmate('', " .. snip .. "))") - screen:expect{grid=[[ + screen:expect({ + grid = [[ The year is ^r{3:rradsf} leeeeel | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) end) it("Correctly parses unescaped characters.", function() @@ -725,25 +800,31 @@ describe("Parser", function() -- indent, insert text, SELECT. exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ${} asdf^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) feed("cc") snip = "${1: asdf ${\\}}" exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ^ {3:asdf ${}} | {0:~ }| - {2:-- SELECT --} |]]} + {2:-- SELECT --} |]], + }) feed("cc") snip = "${TM_LINE_NUMBER/(.*)/ ${} aaaa/}" exec_lua("ls.lsp_expand([[" .. snip .. "]])") - screen:expect{grid=[[ + screen:expect({ + grid = [[ ${} aaaa^ | {0:~ }| - {2:-- INSERT --} |]]} + {2:-- INSERT --} |]], + }) end) end) diff --git a/tests/unit/directed_graph_spec.lua b/tests/unit/directed_graph_spec.lua index 581427b85..a15720bf7 100644 --- a/tests/unit/directed_graph_spec.lua +++ b/tests/unit/directed_graph_spec.lua @@ -9,7 +9,8 @@ describe("luasnip.util.directed_graph:", function() it(mess, function() assert.are.same( out_expected, - exec_lua([[ + exec_lua( + [[ local v_count, edges = ... verts = {} @@ -34,7 +35,10 @@ describe("luasnip.util.directed_graph:", function() return vim.tbl_map(function(vert) return graph_verts_reverse[vert] end, sorting) - ]], v_count, edges) + ]], + v_count, + edges + ) ) end) end @@ -42,28 +46,33 @@ describe("luasnip.util.directed_graph:", function() check_topsort( "simple check with unique sorting.", 4, - { {1,2}, {2,3}, {3,4} }, - {1,2,3,4} ) + { { 1, 2 }, { 2, 3 }, { 3, 4 } }, + { 1, 2, 3, 4 } + ) check_topsort( "another simple unique check, with more complicated dependencies.", 4, -- not going to add asciiart here, just draw the graph. - { {3,1}, {3,2}, {4,2}, {2,1}, {3,4} }, - {3,4,2,1} ) + { { 3, 1 }, { 3, 2 }, { 4, 2 }, { 2, 1 }, { 3, 4 } }, + { 3, 4, 2, 1 } + ) check_topsort( "more 'complicated' check (more edges).", 5, -- draw it. - {{5,1}, {3,1}, {5,3}, {3,4}, {3,2}, {1,2}, {2,4} }, - {5,3,1,2,4} ) + { { 5, 1 }, { 3, 1 }, { 5, 3 }, { 3, 4 }, { 3, 2 }, { 1, 2 }, { 2, 4 } }, + { 5, 3, 1, 2, 4 } + ) check_topsort( "finds circles.", 5, - {{1,5}, {5,3}, {3,2}, {2,4}, {1,2}, {2,3} }, - "invalid" ) + { { 1, 5 }, { 5, 3 }, { 3, 2 }, { 2, 4 }, { 1, 2 }, { 2, 3 } }, + "invalid" + ) check_topsort( "finds circles again, also with lone points for confusion or something.", 5, - { {1,3}, {3,1}, {4,1}, {4,2}, {2,1} }, - "invalid" ) + { { 1, 3 }, { 3, 1 }, { 4, 1 }, { 4, 2 }, { 2, 1 } }, + "invalid" + ) end) diff --git a/tests/unit/environ_spec.lua b/tests/unit/environ_spec.lua index 48a1d3ca2..3c70f70c3 100644 --- a/tests/unit/environ_spec.lua +++ b/tests/unit/environ_spec.lua @@ -127,7 +127,11 @@ describe("luasnip.util.environ", function() helpers.exec("set rtp+=" .. os.getenv("LUASNIP_SOURCE")) check_not_empty("Has builtin namespace var", [[]], "CURRENT_YEAR") - check_not_empty("Has a builtin namespace var without _ in its name", [[]], "UUID") + check_not_empty( + "Has a builtin namespace var without _ in its name", + [[]], + "UUID" + ) check( "Simple lazy table", [[Environ.env_namespace("TBL", {vars={AGE="120"}} )]],