Skip to content

Commit

Permalink
Added preset for let_expression (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wansmer authored Feb 28, 2023
1 parent 92bee6e commit 73341a8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
18 changes: 16 additions & 2 deletions lua/treesj/langs/nix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ return {
list_expression = u.set_preset_for_list({
both = {
separator = '',
}
},
}),
attrset_expression = {
target_nodes = { 'binding_set' },
Expand All @@ -18,7 +18,7 @@ return {
}),
formals = u.set_preset_for_args({
both = {
omit = { 'formal', 'ellipses' }
omit = { 'formal', 'ellipses' },
},
split = {
separator = '',
Expand All @@ -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,
},
}),
}
40 changes: 40 additions & 0 deletions tests/langs/nix_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down
40 changes: 34 additions & 6 deletions tests/sample/index.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -26,17 +26,45 @@

];

# 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
, blub
, ...
}:
{ };

# 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";
};
}

0 comments on commit 73341a8

Please sign in to comment.