Iron-E / nvim-libmodal

Create new "modes" for Neovim!
Other
118 stars 7 forks source link

Attempt to compare number with string in Mode.lua:296 #37

Closed IkaSek closed 6 months ago

IkaSek commented 6 months ago
Error detected while processing LspAttach Autocommands for "*":
Error during nvim-libmodal mode: 

...ocal/share/nvim/lazy/nvim-libmodal/lua/libmodal/Mode.lua:296: attempt to compare number with string

let me be honest, i'm a noob. i don't understand the source code, is it something wrong i'm doing?

IkaSek commented 6 months ago

now i'm no lua expert, but what i did here is

if tonumber(user_input) ~= nil and 0 <= tonumber(user_input) and tonumber(user_input) <= 9 or not tonumber(user_input) == nil then
         local oldCount = self.count:get()
         local newCount = tonumber(oldCount .. string.char(user_input))
         self.count:set(newCount)
 end
Iron-E commented 6 months ago

Can you share the mode which produced this error?

vE5li commented 6 months ago

This looks like a regression. From what I can tell the problem occurs because of this.

getchar will not always return a number (for example, pressing the left arrow key will return a string with the same value as "<Left>"), so when you press any key that produces a string, it will be compared against a number and will error out.

I will try to submit a fix later today

vE5li commented 6 months ago

Seems like it really is that easy: https://github.com/Iron-E/nvim-libmodal/pull/38 I tested it with my own plugin and it works perfectly again

vE5li commented 6 months ago

This can be closed now I believe. Can you still produce the error on master @IkaSek?