CKolkey / ts-node-action

Neovim Plugin for running functions on nodes.
359 stars 20 forks source link

fix: toggle_operator breaks in multiline context #30

Closed alexpw closed 1 year ago

alexpw commented 1 year ago

Issue:

if (100 >
    foo(x,
        y)):
    x = 1

On master, toggling > produces this error:

E5108: Error executing lua ...ts-node-action/init.lua:49: invalid value (table) at index 3 in table for 'concat'

Before the change to helpers.node_text() it produced this error:

E5108: Error executing lua .../ts-node-action/init.lua:15: String cannot contain newlines

Implementation:

This alters actions.toggle_operator() to only replace the unnamed node for >, by targeting it directly, rather than replacing the entire expression.

Bonus:

This will now preserve the original formatting. Previously, it collapsed the expression, eg:

if (100 >
    foo(x, y)):
    x = 1

became:

if (100 > foo(x, y)):
    x = 1
CKolkey commented 1 year ago

Great, thanks :)