Skip to content

Commit

Permalink
fix: options not being correctly read when loaded before cmp
Browse files Browse the repository at this point in the history
by delaying the initialization of `source`.

fixes #29
  • Loading branch information
lljbash committed Jan 16, 2024
1 parent 97ec06b commit 16ea329
Showing 1 changed file with 21 additions and 9 deletions.
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

0 comments on commit 16ea329

Please # to comment.