diff --git a/lua/cmp_git/config.lua b/lua/cmp_git/config.lua index 4075055..80327b3 100644 --- a/lua/cmp_git/config.lua +++ b/lua/cmp_git/config.lua @@ -1,5 +1,6 @@ local M = { filetypes = { "gitcommit" }, + remote = "origin", git = { commits = { limit = 100, @@ -16,8 +17,8 @@ local M = { }, pull_requests = { limit = 100, - state = "open" -- open, closed, merged, all - } + state = "open", -- open, closed, merged, all + }, }, gitlab = { issues = { diff --git a/lua/cmp_git/source.lua b/lua/cmp_git/source.lua index 39e5895..fc8fd04 100644 --- a/lua/cmp_git/source.lua +++ b/lua/cmp_git/source.lua @@ -43,6 +43,8 @@ function Source:complete(params, callback) trigger_character = params.completion_context.triggerCharacter end + local git_info = utils.get_git_info(self.config.remote) + if trigger_character == ":" then if not self.cache_commits[bufnr] then if self.config.git and self.config.git.commits then @@ -57,8 +59,6 @@ function Source:complete(params, callback) end elseif trigger_character == "#" then if not self.cache_issues[bufnr] then - local git_info = utils.get_git_info() - if self.config.github and self.config.github.issues @@ -84,8 +84,6 @@ function Source:complete(params, callback) end elseif trigger_character == "@" then if not self.cache_mentions[bufnr] then - local git_info = utils.get_git_info() - if self.config.github and self.config.github.mentions @@ -111,8 +109,6 @@ function Source:complete(params, callback) end elseif trigger_character == "!" then if not self.cache_merge_requests[bufnr] then - local git_info = utils.get_git_info() - if self.config.gitlab and self.config.gitlab.mentions diff --git a/lua/cmp_git/utils.lua b/lua/cmp_git/utils.lua index f91f418..59e53bf 100644 --- a/lua/cmp_git/utils.lua +++ b/lua/cmp_git/utils.lua @@ -8,10 +8,9 @@ M.url_encode = function(value) return string.gsub(value, "([^%w _%%%-%.~])", char_to_hex) end - -M.get_git_info = function() +M.get_git_info = function(remote) return M.run_in_cwd(M.get_cwd(), function() - local remote_origin_url = vim.fn.system("git config --get remote.origin.url") + local remote_origin_url = vim.fn.system("git config --get remote." .. remote .. ".url") local clean_remote_origin_url = remote_origin_url:gsub("%.git", ""):gsub("%s", "") local host, owner, repo = string.match(clean_remote_origin_url, "^git@(.+):(.+)/(.+)$") @@ -38,8 +37,8 @@ M.run_in_cwd = function(cwd, callback) end M.get_cwd = function() - if vim.fn.getreg('%') ~= '' then - return vim.fn.expand('%:p:h') + if vim.fn.getreg("%") ~= "" then + return vim.fn.expand("%:p:h") end return vim.fn.getcwd() end