diff options
author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-22 00:31:10 -0800 |
---|---|---|
committer | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-22 00:31:10 -0800 |
commit | 73487f4130581da72c9e838189aab39c79c177c5 (patch) | |
tree | 288419d9965366e14ba1d0383f827f32bc472d18 /runtime/lua/vim/lsp/util.lua | |
parent | 78991ffbf4357ba1ad477a13991078bb4a0bdc58 (diff) | |
download | rneovim-73487f4130581da72c9e838189aab39c79c177c5.tar.gz rneovim-73487f4130581da72c9e838189aab39c79c177c5.tar.bz2 rneovim-73487f4130581da72c9e838189aab39c79c177c5.zip |
Improve the character_offset code.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 94b4223a20..e2a8748a20 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -11,14 +11,6 @@ end local list_extend = vim.list_extend -local function ok_or_nil(status, ...) - if not status then return end - return ... -end -local function npcall(fn, ...) - return ok_or_nil(pcall(fn, ...)) -end - --- Find the longest shared prefix between prefix and word. -- e.g. remove_prefix("123tes", "testing") == "ting" local function remove_prefix(prefix, word) @@ -668,9 +660,11 @@ end -- @param col 0-indexed byte offset in line function M.character_offset(buf, row, col) local line = api.nvim_buf_get_lines(buf, row, row+1, true)[1] - -- TODO(ashkan) is there a better way to handle col being past line length? -- If the col is past the EOL, use the line length. - return npcall(str_utfindex, line, col) or str_utfindex(line) + if col > #line then + return str_utfindex(line) + end + return str_utfindex(line, col) end return M |