diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index df6d143..54c57bb 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -61,13 +61,14 @@ entry.get_offset = function(self) local range = self:get_insert_range() if range then offset = self.context.cache:ensure('entry:' .. 'get_offset:' .. tostring(range.start.character), function() - for idx = range.start.character + 1, self.source_offset do + local start = math.min(range.start.character + 1, offset) + for idx = start, self.source_offset do local byte = string.byte(self.context.cursor_line, idx) - if byte ~= nil and not char.is_white(byte) then + if byte == nil or not char.is_white(byte) then return idx end end - return offset + return offset + 1 end) end else diff --git a/lua/cmp/entry_spec.lua b/lua/cmp/entry_spec.lua index 9f7e291..1ea3632 100644 --- a/lua/cmp/entry_spec.lua +++ b/lua/cmp/entry_spec.lua @@ -335,4 +335,33 @@ describe('entry', function() assert.are.equal(e:get_offset(), 3) assert.are.equal(e:get_vim_item(e:get_offset()).word, 'constructor() {') end) + + it('[#1533] clang regression test', function() + local state = spec.state('jsonReader', 3, 11) + local state_source = state.source() + + state.input('.') + local e = entry.new(state.manual(), state_source, { + filterText = 'getPath()', + kind = 1, + label = 'getPath()', + textEdit = { + newText = 'getPath()', + range = { + ['end'] = { + character = 11, + col = 12, + line = 2, + row = 3, + }, + start = { + character = 11, + line = 2, + }, + }, + }, + }) + assert.are.equal(e:get_offset(), 12) + assert.are.equal(e:get_vim_item(e:get_offset()).word, 'getPath()') + end) end)