diff --git a/lua/treesj/langs/elixir.lua b/lua/treesj/langs/elixir.lua index 68dc791..38334d6 100644 --- a/lua/treesj/langs/elixir.lua +++ b/lua/treesj/langs/elixir.lua @@ -35,8 +35,8 @@ 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) @@ -44,15 +44,14 @@ return { 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 diff --git a/tests/langs/elixir/join_spec.lua b/tests/langs/elixir/join_spec.lua index 697c45a..6f42cc7 100644 --- a/tests/langs/elixir/join_spec.lua +++ b/tests/langs/elixir/join_spec.lua @@ -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 }, }, } diff --git a/tests/langs/elixir/split_spec.lua b/tests/langs/elixir/split_spec.lua index 518a88c..83d8ebb 100644 --- a/tests/langs/elixir/split_spec.lua +++ b/tests/langs/elixir/split_spec.lua @@ -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 }, }, } diff --git a/tests/sample/index.ex b/tests/sample/index.ex index 91ba764..4013bc5 100644 --- a/tests/sample/index.ex +++ b/tests/sample/index.ex @@ -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)