Skip to content

Commit

Permalink
Safer string.sub
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed May 13, 2024
1 parent f9c8991 commit a6c210f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 10 additions & 3 deletions lua/fittencode/engines/inline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,15 @@ function M.accept_word()
return
end
local next_index = next_indices(line)
local word = string.sub(line, 1, next_index)
line = string.sub(line, string.len(word) + 1)
local word = ''
if next_index > 0 then
word = string.sub(line, 1, next_index)
end
if #word < #line then
line = string.sub(line, string.len(word) + 1)
else
line = ''
end
if string.len(line) == 0 then
cache:remove_line(1)
if M.has_suggestions() then
Expand Down Expand Up @@ -482,7 +489,7 @@ function M.lazy_inline_completion()
if adv_type > 0 then
local cur_line = api.nvim_buf_get_lines(0, row, row + 1, false)[1]
local cache_line = cache:get_line(1)
if not cache_line then
if not cache_line or #cache_line == 0 then
return false
end
if adv_type == 1 then
Expand Down
3 changes: 1 addition & 2 deletions lua/fittencode/fs/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ end

function M.name(buffer)
local path = api.nvim_buf_get_name(buffer)
local i = Base.rfind(path, M.nvim_sep())
return i and string.sub(path, -i + 1, -1) or path
return vim.fn.fnamemodify(path, ":t")
end

return M

0 comments on commit a6c210f

Please sign in to comment.