-
I try to add support for Nix. I am not sure if treesj in its current form can handle some "special" Nix formattings and tree-sitter-nix specifics or if I just don't understand treesj good enough to express these things. The easiest way to get what I mean is to check out my nix branch and run the tests. (See also this diff between main and feat/nix) Problem 1What I struggle with the most is that tree-sitter-nix parses an attribute set {
a = 1;
b = 2;
c = "c";
} into
With my current knowledge of treesj I am only able to split an attribute set { a = 1;
b = 2;
c = "c"; } with the preset or {
a = 1; b = 2; c = "c";
} with the preset I tried to work with Problem 2The other problem I struggle with is that Nix has a very unusual formatting when splitting "function arguments". Take a look at the placement of the commas in https://github.com/pogopaule/treesj/blob/446df8a2833bdda43817dbb78302ce480946225e/tests/sample/index.nix#L29-L41 Potential workaroundsIn both cases I can make things work by using treesj and the Nix formatter in combination. So for example I split an attribute set into { a = 1;
b = 2;
c = "c"; } and let the formatter do the rest of the work. Same applies for the strange comma placement for function arguments. This would kind of work but I am not satisfied with it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello! Problem 1:{
attrset_expression = {
target_nodes = { 'binding_set' }, -- because target node for format is not attrset_expression, but binding_set
},
binding_set = u.set_preset_for_dict({
both = {
non_bracket_node = true, -- It will created empty framing nodes for get new line after '{' and before '}'
separator = ';',
last_separator = true,
},
}),
} Problem 2:Hmm, I see what all children of Maximum what can be settings with TreeSJ it: # from
func1 =
{ foo, bar, blub, ... }:
{ };
# to
func1 =
{ foo
, bar
, blub
, ...
}:
{ }; via {
formals = u.set_preset_for_args({
both = {
omit = { 'formal', 'ellipses' }
},
split = {
separator = '',
},
join = {
separator = ',',
space_in_brackets = true,
},
}),
} But this form adding extra space before separator, when joining. Looks like bug, will fix it. About
|
Beta Was this translation helpful? Give feedback.
-
Add preset for |
Beta Was this translation helpful? Give feedback.
Hello!
Problem 1:
Problem 2:
Hmm, I see what all children of
formals
should be with same indents, but at the moment all inner indents calculating withfirst indent + shiftwidth
.Maximum what can be settings with TreeSJ it: