CKolkey / ts-node-action

Neovim Plugin for running functions on nodes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ts-node-action/init.lua:130: attempt to index local 'choice' (a nil value)

unphased opened this issue · comments

My changes are summarized here: 3a0ddbd

Here is the error I get in nvim. the first 3 lines compose the menu made by vanilla ui.select:

Select Action
1: Conceal
2: Split Join
Type number and <Enter> or click with the mouse (q or empty cancels):
E5108: Error executing lua: vim/_editor.lua:420: nvim_exec2(): Vim(normal):E5108: Error executing lua ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:130: attempt to index
 local 'choice' (a nil value)
stack traceback:
        ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:130: in function 'on_choice'
        ...ar/neovim/HEAD-8c6b0a5/share/nvim/runtime/lua/vim/ui.lua:52: in function 'select'
        ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:124: in function 'fn'
        ...e/nvim/lazy/ts-node-action/lua/ts-node-action/repeat.lua:11: in function <...e/nvim/lazy/ts-node-action/lua/ts-node-action/repeat.lua:10>
        [C]: in function 'nvim_exec2'
        vim/_editor.lua:420: in function 'cmd'
        ...e/nvim/lazy/ts-node-action/lua/ts-node-action/repeat.lua:23: in function <...e/nvim/lazy/ts-node-action/lua/ts-node-action/repeat.lua:5>
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua:420: in function 'cmd'
        ...e/nvim/lazy/ts-node-action/lua/ts-node-action/repeat.lua:23: in function <...e/nvim/lazy/ts-node-action/lua/ts-node-action/repeat.lua:5>
Press ENTER or type command to continue

Note I never got a chance to type anything and its having an error where on_choice got called with nil... No idea whats going on here.

I went to configure dressing plugin with nui as the backend and the menu works. but it may be worth looking into why the vanilla select dies here.

Alright still same problem once a choice is made.

Error executing vim.schedule lua callback: ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:130: attempt to index local 'choice' (a nil value)
stack traceback:
        ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:130: in function 'on_choice'
        ...are/nvim/lazy/dressing.nvim/lua/dressing/select/init.lua:78: in function 'fn'
        vim/_editor.lua:343: in function <vim/_editor.lua:342>
Error executing vim.schedule lua callback: ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:54: attempt to call local 'action' (a table value)
stack traceback:
        ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:54: in function 'do_action'
        ...are/nvim/lazy/ts-node-action/lua/ts-node-action/init.lua:130: in function 'on_choice'
        ...are/nvim/lazy/dressing.nvim/lua/dressing/select/init.lua:78: in function 'fn'
        vim/_editor.lua:343: in function <vim/_editor.lua:342>

ok so i added some logging, the delta is
image

19:05:39:343 >>> 1 -> action
2 -> { { { <function 1>,
      name = "Conceal String"
    } }, { { <function 2>,
      name = "Toggle Multiline"
    } } }
19:05:42:735 >>> 1 -> CHOICE
19:05:43:434 >>> 1 -> CHOICE
2 -> { { <function 1>,
    name = "Toggle Multiline"
  } }

What that's saying is, the choice got fired once with nil and once with this overly nested choice which is why the menu showed two "nil" options. Why two times? no clue.

this is after i adjusted the definition to:

  ["statement_block"] = {
    actions.conceal_string(),
    actions.toggle_multiline(padding)
  },

seems like it's still too nested but (yea im a lua newbie) not sure how to un-nest this further.

Logging what the definition is now

19:11:32:852 >>> 1 -> ts-n-a: javascript.lua def:
2 -> {
  arguments = { { <function 1>,
      name = "Toggle Multiline"
    } },
  array = { { <function 2>,
      name = "Toggle Multiline"
    } },
  binary_expression = { { <function 3>,
      name = "Toggle Operator"
    } },
  formal_parameters = { { <function 4>,
      name = "Toggle Multiline"
    } },
  number = { { <function 5>,
      name = "Toggle Integer Format"
    } },
  object = { { <function 6>,
      name = "Toggle Multiline"
    } },
  object_pattern = { { <function 7>,
      name = "Toggle Multiline"
    } },
  object_type = { { <function 8>,
      name = "Toggle Multiline"
    } },
  property_identifier = { { <function 9>,
      name = "Cycle Case"
    } },
  statement_block = { { { <function 10>,
        name = "Conceal String"
      } }, { { <function 11>,
        name = "Toggle Multiline"
      } } },
  string_fragment = { { <function 12>,
      name = "Conceal String"
    } }
}

hmmm

looks like all the actions are by convention nested once but the operation of the select cant handle that. gonna need a simple architectural explanation now that i found the root cause in order to determine the correct way to define multiple actions per node type. I can guess though that it should work if I take the multiple options and merge them into a table.

Trying this now:

function merge_nested_tables(...)
    local merged = {}
    for _, tbl in ipairs({...}) do
        for _, nested_tbl in ipairs(tbl) do
            table.insert(merged, nested_tbl)
        end
    end
    return merged
end

Alright that actually works, but now i'm stuck with the problem of the callback getting called with a nil first always.

My attempt to conceal entire blocks of code works but only hides the whole code in there while leaving the lines present, which I dunno what I expected but it wasn't that, anyway though I seem to be tantalizingly close. let me know if you have trouble reproducing anything. should be pretty straightforward.

Sigh ok so... after disabling dressing i'm able not to not get a choice callback called with nil. seems like without something like dressing, the default picker always get dismissed somehow (could be another conflicting plugin though).

Once i put in a nil check in the on_choice it seems like functionality can be restored. please advise on which approach we should take, because the documentation is out of date now; specifying multiple actions on the same node type in the way shown in documentation will fail.