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

fix: elixir: pad everything in keywords except strings #168

Merged
merged 1 commit into from
Dec 10, 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
17 changes: 8 additions & 9 deletions lua/treesj/langs/elixir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,23 @@ return {
keywords = lang_utils.set_preset_for_list({
both = {
non_bracket_node = true,
-- This is only needed because for some reason join and
-- split on a keyword where the value is a map goes like this:
-- This is only needed because for some reason join and split on a keyword
-- where the value is certain types of term looks like:
-- expected: 'key: %{ a: "b" }'
-- result: 'key:%{ a: "b" }'
format_tree = function(tsj)
if tsj:has_children({ 'pair' }) then
local pairs = tsj:children({ 'pair' })
for _, pair in ipairs(pairs) do
for keyword in pair:iter_children() do
local type = keyword:type()
local needs_padding =
type == 'map' or type == 'list' or type == 'tuple'
if needs_padding then
if keyword:type() ~= 'string' then
-- Grab the previous node which is the map key
local map_key = keyword:prev()
-- Add an extra space to account for keyword + map quirkness
local text = map_key:text():gsub(':$', ': ')
map_key:update_text(text)
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
end
Expand Down
18 changes: 9 additions & 9 deletions tests/langs/elixir/join_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,27 @@ local data_for_join = {
mode = 'join',
lang = LANG,
desc = 'lang "%s", node "map" with "keywords" and "map_content", preset default',
cursor = { 67, 8 },
expected = { 63, 64 },
result = { 66, 67 },
cursor = { 68, 8 },
expected = { 64, 65 },
result = { 67, 68 },
},
{
path = PATH,
mode = 'join',
lang = LANG,
desc = 'lang "%s", node "list" with "keywords" and "map", preset default',
cursor = { 76, 4 },
expected = { 71, 72 },
result = { 74, 75 },
cursor = { 77, 4 },
expected = { 72, 73 },
result = { 75, 76 },
},
{
path = PATH,
mode = 'join',
lang = LANG,
desc = 'lang "%s", node "map" nested "keywords" and "maps", preset default',
cursor = { 87, 10 },
expected = { 82, 83 },
result = { 85, 86 },
cursor = { 88, 10 },
expected = { 83, 84 },
result = { 86, 87 },
},
}

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

Expand Down
5 changes: 3 additions & 2 deletions tests/sample/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ test(
}

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

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

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