Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: options not being correctly read when loaded before cmp #30

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions lua/cmp_tmux/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
-- license: MIT
--

local config = require('cmp.config')
local Tmux = require('cmp_tmux.tmux')

local source = {}
Expand All @@ -20,39 +19,52 @@ local default_config = {
}

local function create_config()
local config = require('cmp.config')
local source_config = config.get_source_config('tmux') or {}
return vim.tbl_extend('force', default_config, source_config.option or {})
end

source.new = function()
local self = setmetatable({}, { __index = source })
self.config = create_config()
self.tmux = Tmux.new(self.config)
return self
end

source.get_debug_name = function()
return 'tmux'
end

function source:config()
if self.config_impl == nil then
self.config_impl = create_config()
end
return self.config_impl
end

function source:tmux()
if self.tmux_impl == nil then
self.tmux_impl = Tmux.new(self:config())
end
return self.tmux_impl
end

function source:is_available()
return self.tmux:is_enabled()
return self:tmux():is_enabled()
end

function source:get_keyword_pattern()
return self.config.keyword_pattern
return self:config().keyword_pattern
end

function source:get_trigger_characters()
local ft = vim.bo.filetype
local tcft = self.config.trigger_characters_ft[ft]
return tcft or self.config.trigger_characters
local tcft = self:config().trigger_characters_ft[ft]
return tcft or self:config().trigger_characters
end

function source:complete(request, callback)
local word = string.sub(request.context.cursor_before_line, request.offset)

self.tmux:complete(word, function(words)
self:tmux():complete(word, function(words)
if words == nil then
return callback()
end
Expand All @@ -62,7 +74,7 @@ function source:complete(request, callback)
word = w,
label = w,
labelDetails = {
detail = self.config.label,
detail = self:config().label,
},
}
end, words)
Expand Down
Loading