Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upbad argument #1 to 'str_utfindex' (string expected, got nil) #12623
Comments
|
I'm guessing this would be as simple as checking for nil here: local function make_position_param()
local row, col = unpack(api.nvim_win_get_cursor(0))
row = row - 1
local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
-- vvvvvvvv
col = str_utfindex(line, col)
return { line = row; character = col; }
endBut I don't have time at the moment to test it. |
|
@tjdevries I am interested in working this issue. Do you know if anyone else has started? |
|
I don't think anyone has started. Feel free to make a PR and tag me in it! Thanks! |
|
I get a different error, can you perhaps post the go file you tried this script on, or a chunk of it. |
|
sorry cannot recall what go file was associated with this error. |
|
Have you encountered this error again anytime, or are you able to reproduce it now? |
|
I get the exact error when I put the code above in my init.vim Build type: Release
LuaJIT 2.1.0-beta3
Compilation: /Applications/Xcode-10.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/Users/travis/build/neovim/bot-ci/build/neovim/build/config -I/Users/travis/build/neovim/bot-ci/build/neovim/src -I/Users/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/usr/local/opt/gettext/include -I/Users/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/Users/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@Traviss-Mac-6.local
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/share/nvim"I think the nil check as suggested by @tjdevries is a good idea anyway. |
|
I think I know what's going on, you said you put the exact code in your init.vim, and that includes this line
so you're calling the function. But the problem is, as far as I know init script is run before any buffer is loaded (or present, I'm not sure) and there is no line at that moment. So it's really reasonable for this function to return nil.
As for a solution though, I'm not sure what to do, I mean it's reasonable but should we give a more informative error message or just, as @tjdevries mentioned, check for nil. Either way there is a logic error in script. |
|
I am calling the go_organize_imports_sync as a test. |


nvim --version:NVIM v0.5.0-nightly
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20200711-88642-ii3lmc/build/config -I/tmp/neovim-20200711-88642-ii3lmc/src -I/usr/local/include -I/tmp/neovim-20200711-88642-ii3lmc/deps-build/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20200711-88642-ii3lmc/build/src/nvim/auto -I/tmp/neovim-20200711-88642-ii3lmc/build/include
Compiled by <>
Features: +acl +iconv +tui
Operating system/version:
Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
Terminal name/version:
alacritty 0.4.3 (c723247)
$TERM:$TERM
Actual behaviour
This code
produce this error
E5108: Error executing lua ...vim/HEAD-a695da7/share/nvim/runtime/lua/vim/lsp /util.lua:1297: bad argument #1 to 'str_utfindex' (string expected, got nil)
Expected behaviour
no internal error.