Fix #129 (experimental)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
local debug = require('cmp.utils.debug')
|
||||
local char = require('cmp.utils.char')
|
||||
local str = require('cmp.utils.str')
|
||||
local pattern = require('cmp.utils.pattern')
|
||||
local async = require('cmp.utils.async')
|
||||
local keymap = require('cmp.utils.keymap')
|
||||
local context = require('cmp.context')
|
||||
@@ -130,6 +130,7 @@ end
|
||||
|
||||
---Check auto-completion
|
||||
core.on_change = function(event)
|
||||
core.autoindent(event, function()
|
||||
local ctx = core.get_context({ reason = types.cmp.ContextReason.Auto })
|
||||
|
||||
-- Skip autocompletion when the item is selected manually.
|
||||
@@ -151,6 +152,25 @@ core.on_change = function(event)
|
||||
else
|
||||
debug.log('unchanged')
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
---Check autoindent
|
||||
---@param event cmp.TriggerEvent
|
||||
---@param callback function
|
||||
core.autoindent = function(event, callback)
|
||||
if event == types.cmp.TriggerEvent.TextChanged then
|
||||
local ctx = context.new()
|
||||
local prefix = pattern.matchstr('[^[:blank:]]\\+$', ctx.cursor_before_line)
|
||||
if prefix then
|
||||
for _, key in ipairs(vim.split(vim.bo.indentkeys, ',')) do
|
||||
if vim.tbl_contains({ '=' .. prefix, '0=' .. prefix }, key) then
|
||||
return keymap.feedkeys(keymap.t('<C-f>'), 'n', callback)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
callback()
|
||||
end
|
||||
|
||||
---Invoke completion
|
||||
|
||||
@@ -17,5 +17,13 @@ pattern.offset = function(p, text)
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
pattern.matchstr = function(p, text)
|
||||
local s, e = pattern.offset(p, text)
|
||||
if s then
|
||||
return string.sub(text, s, e)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return pattern
|
||||
|
||||
|
||||
Reference in New Issue
Block a user