diff --git a/lua/treesj/langs/nix.lua b/lua/treesj/langs/nix.lua index 1149f27..f254d8a 100644 --- a/lua/treesj/langs/nix.lua +++ b/lua/treesj/langs/nix.lua @@ -4,7 +4,7 @@ return { list_expression = u.set_preset_for_list({ both = { separator = '', - } + }, }), attrset_expression = { target_nodes = { 'binding_set' }, @@ -18,7 +18,7 @@ return { }), formals = u.set_preset_for_args({ both = { - omit = { 'formal', 'ellipses' } + omit = { 'formal', 'ellipses' }, }, split = { separator = '', @@ -29,4 +29,18 @@ return { space_in_brackets = true, }, }), + let_expression = u.set_default_preset({ + both = { + omit = { 'binding_set' }, + }, + split = { + recursive = true, + inner_indent = 'normal', + last_indent = 'inner', + }, + join = { + space_in_brackets = true, + space_separator = 1, + }, + }), } diff --git a/tests/langs/nix_spec.lua b/tests/langs/nix_spec.lua index e61d4c3..841298c 100644 --- a/tests/langs/nix_spec.lua +++ b/tests/langs/nix_spec.lua @@ -34,6 +34,26 @@ local data_for_split = { result = { 30, 36 }, settings = {}, }, + { + path = PATH, + mode = 'split', + lang = LANG, + desc = 'lang "%s", node "let_expression", preset default', + cursor = { 45, 6 }, + expected = { 48, 53 }, + result = { 44, 49 }, + settings = {}, + }, + { + path = PATH, + mode = 'split', + lang = LANG, + desc = 'lang "%s", node "let_expression" with "attrset_expression", preset default', + cursor = { 57, 6 }, + expected = { 60, 69 }, + result = { 56, 65 }, + settings = {}, + }, } local data_for_join = { @@ -67,6 +87,26 @@ local data_for_join = { result = { 35, 36 }, settings = {}, }, + { + path = PATH, + mode = 'join', + lang = LANG, + desc = 'lang "%s", node "let_expression", preset default', + cursor = { 49, 6 }, + expected = { 44, 45 }, + result = { 48, 49 }, + settings = {}, + }, + { + path = PATH, + mode = 'join', + lang = LANG, + desc = 'lang "%s", node "let_expression" with "attrset_expression", preset default', + cursor = { 61, 6 }, + expected = { 56, 57 }, + result = { 60, 61 }, + settings = {}, + }, } describe('TreeSJ SPLIT:', function() diff --git a/tests/sample/index.nix b/tests/sample/index.nix index 9475dab..41c8739 100644 --- a/tests/sample/index.nix +++ b/tests/sample/index.nix @@ -1,10 +1,10 @@ { foo, ... }: { bar = [ - # RESULT OF JOIN (nix "list_expression", preset default) + # RESULT OF JOIN (node "list_expression", preset default) [ 1 2 3 4 "a" "b" ] - # RESULT OF SPLIT (nix "list_expression", preset default) + # RESULT OF SPLIT (node "list_expression", preset default) [ 1 2 @@ -14,10 +14,10 @@ "b" ] - # RESULT OF JOIN (nix "binding_set", preset default) + # RESULT OF JOIN (node "binding_set", preset default) { a = 1; b = 2; c = "c"; } - # RESULT OF SPLIT (nix "binding_set", preset default) + # RESULT OF SPLIT (node "binding_set", preset default) { a = 1; b = 2; @@ -26,12 +26,12 @@ ]; - # RESULT OF JOIN (nix "formals", preset default) + # RESULT OF JOIN (node "formals", preset default) func1 = { foo, bar, blub, ... }: { }; - # RESULT OF SPLIT (nix "formals", preset default) + # RESULT OF SPLIT (node "formals", preset default) func2 = { foo , bar @@ -39,4 +39,32 @@ , ... }: { }; + + # RESULT OF JOIN (node "let_expression", preset default) + bla = + let x=1; y=2; in x + y; + + # RESULT OF SPLIT (node "let_expression", preset default) + bla = + let + x=1; + y=2; + in + x + y; + + # RESULT OF JOIN (node "let_expression" with "attrset_expression", preset default) + bla = + let x=1; y=2; in { a = 1; b = 2; c = "c"; }; + + # RESULT OF SPLIT (node "let_expression" with "attrset_expression", preset default) + bla = + let + x=1; + y=2; + in + { + a = 1; + b = 2; + c = "c"; + }; }