Skip to content

Commit

Permalink
compat
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed Sep 23, 2021
1 parent 3ef0e2f commit abdf4b8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 251 deletions.
6 changes: 5 additions & 1 deletion lua/cmp/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ end

---Check auto-completion
core.on_change = function(self, event)
if self.suspending or self.view:active() then
local ignore = false
ignore = ignore or self.suspending
ignore = ignore or (vim.fn.pumvisible() == 1 and (vim.v.completed_item).word)
if ignore then
self:get_context({ reason = types.cmp.ContextReason.Auto })
return
end

Expand Down
50 changes: 27 additions & 23 deletions lua/cmp/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ local async = require('cmp.utils.async')
local event = require('cmp.utils.event')
local keymap = require('cmp.utils.keymap')
local docs_view = require('cmp.view.docs_view')
local entries_view = require('cmp.view.entries_view')
local custom_entries_view = require('cmp.view.custom_entries_view')
local native_entries_view = require('cmp.view.native_entries_view')
local ghost_text_view = require('cmp.view.ghost_text_view')

---@class cmp.View
---@field public event cmp.Event
---@field public resolve_dedup cmp.AsyncDedup
---@field public change_dedup cmp.AsyncDedup
---@field public entries_view cmp.EntriesView
---@field public docs_view cmp.DocsView
---@field public ghost_text_view cmp.GhostTextView
Expand All @@ -18,8 +18,8 @@ local view = {}
---Create menu
view.new = function()
local self = setmetatable({}, { __index = view })
self.resolve_dedup = async.dedup()
self.entries_view = entries_view.new()
self.change_dedup = async.dedup()
self.entries_view = custom_entries_view.new()
self.entries_view = native_entries_view.new()
self.docs_view = docs_view.new()
self.ghost_text_view = ghost_text_view.new()
Expand Down Expand Up @@ -91,10 +91,6 @@ view.visible = function(self)
return self.entries_view:visible()
end

view.active = function(self)
return self.entries_view:active()
end

view.scroll_docs = function(self, delta)
self.docs_view:scroll(delta)
end
Expand All @@ -107,34 +103,42 @@ view.select_prev_item = function(self)
self.entries_view:select_prev_item()
end

---Get first entry
---@param self cmp.Entry|nil
view.get_first_entry = function(self)
return self.entries_view:get_first_entry()
end

---Get current selected entry
---@return cmp.Entry|nil
view.get_selected_entry = function(self)
return self.entries_view:get_selected_entry()
end

---Get first entry
---@param self cmp.Entry|nil
view.get_first_entry = function(self)
return self.entries_view:get_first_entry()
view.get_active_entry = function(self)
return self.entries_view:get_active_entry()
end

---On entry change
view.on_entry_change = function(self)
local e = self:get_selected_entry()
if e then
for _, c in ipairs(config.get().confirmation.get_commit_characters(e:get_commit_characters())) do
keymap.listen('i', c, function(...)
self.event:emit('keymap', ...)
self.ghost_text_view:show(e or self:get_first_entry())

vim.schedule(self.change_dedup(function()
if e then
for _, c in ipairs(config.get().confirmation.get_commit_characters(e:get_commit_characters())) do
keymap.listen('i', c, function(...)
self.event:emit('keymap', ...)
end)
end
e:resolve(function()
self.docs_view:open(e, self.entries_view:info())
end)
else
self.docs_view:close()
end
e:resolve(self.resolve_dedup(function()
self.docs_view:open(e, self.entries_view:info())
end))
else
self.docs_view:close()
end
self.ghost_text_view:show(e or self:get_first_entry())
end))
end

return view

221 changes: 0 additions & 221 deletions lua/cmp/view/entries_view.lua

This file was deleted.

16 changes: 10 additions & 6 deletions lua/cmp/view/native_entries_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ local native_entries_view = {}
native_entries_view.new = function()
local self = setmetatable({}, { __index = native_entries_view })
self.event = event.new()
autocmd.subscribe('CompleteChanged', vim.schedule(function()
autocmd.subscribe('CompleteChanged', function()
self.event:emit('change')
end))
end)
return self
end

Expand Down Expand Up @@ -48,10 +48,6 @@ native_entries_view.visible = function(_)
return vim.fn.pumvisible() == 1
end

native_entries_view.active = function(self)
return (vim.v.completed_item or {}).word and self:visible()
end

native_entries_view.info = function(self)
if self:visible() then
local info = vim.fn.pum_getpos()
Expand Down Expand Up @@ -91,5 +87,13 @@ native_entries_view.get_selected_entry = function(self)
end
end

native_entries_view.get_active_entry = function(self)
if self:visible() then
if (vim.v.completed_item or {}).word then
return self:get_selected_entry()
end
end
end

return native_entries_view

0 comments on commit abdf4b8

Please sign in to comment.