Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Elixir Tweaks #169

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions lua/treesj/langs/elixir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ return {
last_separator = false,
format_tree = function(tsj)
if tsj:has_children({ 'keywords' }) then
tsj:update_preset(
{ recursive = true, recursive_ignore = { 'map' } },
'split'
)
local keywords = tsj:child('keywords')
keywords:update_preset({ inner_indent = 'normal' }, 'split')
keywords:_format()
end
end,
},
Expand All @@ -44,14 +41,12 @@ return {
local pairs = tsj:children({ 'pair' })
for _, pair in ipairs(pairs) do
for keyword in pair:iter_children() do
if keyword:type() ~= 'string' then
-- Grab the previous node which is the map key
local map_key = keyword:prev()
if map_key then
-- Add an extra space to account for keyword + value quirkness
local text = map_key:text():gsub(':$', ': ')
map_key:update_text(text)
end
-- Grab the previous node which is the map key
local map_key = keyword:prev()
if map_key then
-- Add an extra space to account for keyword + value quirkness
local text = map_key:text():gsub(':$', ': ')
map_key:update_text(text)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions tests/langs/elixir/join_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ local data_for_join = {
mode = 'join',
lang = LANG,
desc = 'lang "%s", node "list" with "keywords" and "map", preset default',
cursor = { 77, 4 },
expected = { 72, 73 },
result = { 75, 76 },
cursor = { 79, 4 },
expected = { 74, 75 },
result = { 77, 78 },
},
{
path = PATH,
mode = 'join',
lang = LANG,
desc = 'lang "%s", node "map" nested "keywords" and "maps", preset default',
cursor = { 88, 10 },
expected = { 83, 84 },
result = { 86, 87 },
cursor = { 90, 10 },
expected = { 85, 86 },
result = { 88, 89 },
},
}

Expand Down
16 changes: 8 additions & 8 deletions tests/langs/elixir/split_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,26 @@ local data_for_split = {
lang = LANG,
desc = 'lang "%s", node "map" with "keywords" and "map_content", preset default',
cursor = { 65, 8 },
expected = { 67, 72 },
result = { 64, 69 },
expected = { 67, 74 },
result = { 64, 71 },
},
{
path = PATH,
mode = 'split',
lang = LANG,
desc = 'lang "%s", node "list" with "keywords" and "map", preset default',
cursor = { 75, 9 },
expected = { 77, 83 },
result = { 74, 80 },
cursor = { 77, 9 },
expected = { 79, 85 },
result = { 76, 82 },
},
{
path = PATH,
mode = 'split',
lang = LANG,
desc = 'lang "%s", node "map" nested "keywords" and "maps", preset default',
cursor = { 86, 15 },
expected = { 88, 94 },
result = { 85, 91 },
cursor = { 88, 15 },
expected = { 90, 96 },
result = { 87, 93 },
},
}

Expand Down
8 changes: 5 additions & 3 deletions tests/sample/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ map = %{
}

# RESULT OF JOIN (node "map" with "keywords" and "map_content", preset default)
map = %{"key" => "value", foo: "bar", baz: "bar"}
map = %{"key" => "value", "baz" => [], abc: %{}, def: {}, hij: a(1) + 1}

# RESULT OF SPLIT (node "map" with "keywords" and "map_content", preset default)
map = %{
"key" => "value",
foo: "bar",
baz: "bar"
"baz" => [],
abc: %{},
def: {},
hij: a(1) + 1
}

# RESULT OF JOIN (node "list" with "keywords" and "map", preset default)
Expand Down
Loading