Skip to content

Commit

Permalink
fix: elixir: additional padding logic (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
giddie authored Dec 10, 2024
1 parent 03415ac commit 7a36de6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
5 changes: 4 additions & 1 deletion lua/treesj/langs/elixir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ return {
local pairs = tsj:children({ 'pair' })
for _, pair in ipairs(pairs) do
for keyword in pair:iter_children() do
if keyword:type() == 'map' then
local type = keyword:type()
local needs_padding =
type == 'map' or type == 'list' or type == 'tuple'
if needs_padding 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
Expand Down
6 changes: 3 additions & 3 deletions tests/langs/elixir/join_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ local data_for_join = {
mode = 'join',
lang = LANG,
desc = 'lang "%s", node "map" with "keywords" and "map_content", preset default',
cursor = { 65, 8 },
expected = { 61, 62 },
result = { 64, 65 },
cursor = { 67, 8 },
expected = { 63, 64 },
result = { 66, 67 },
},
{
path = PATH,
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, 59 },
result = { 52, 56 },
expected = { 55, 61 },
result = { 52, 58 },
},
{
path = PATH,
mode = 'split',
lang = LANG,
desc = 'lang "%s", node "map" with "keywords" and "map_content", preset default',
cursor = { 62, 8 },
expected = { 64, 69 },
result = { 61, 66 },
cursor = { 64, 8 },
expected = { 66, 71 },
result = { 63, 68 },
},
{
path = PATH,
mode = 'split',
lang = LANG,
desc = 'lang "%s", node "list" with "keywords" and "map", preset default',
cursor = { 72, 9 },
expected = { 74, 80 },
result = { 71, 77 },
cursor = { 74, 9 },
expected = { 76, 82 },
result = { 73, 79 },
},
{
path = PATH,
mode = 'split',
lang = LANG,
desc = 'lang "%s", node "map" nested "keywords" and "maps", preset default',
cursor = { 83, 15 },
expected = { 85, 91 },
result = { 82, 88 },
cursor = { 85, 15 },
expected = { 87, 93 },
result = { 84, 90 },
},
}

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

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

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

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

0 comments on commit 7a36de6

Please sign in to comment.