-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.lua
107 lines (100 loc) · 3.11 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
local utils = require('blink-cmp-git.utils')
local log = require('blink-cmp-git.log')
log.setup({ title = 'blink-cmp-git' })
local last_git_repo
local function default_should_reload_cache()
-- Do not reload cache when the buffer is a prompt buffer
-- or the source provider is disabled
if vim.bo.buftype == 'prompt' or
not utils.source_provider_enabled()
then
return false
end
if last_git_repo == nil then
last_git_repo = utils.get_git_repo_absolute_path()
if not last_git_repo then
last_git_repo = ''
end
return false
end
local new_git_repo = utils.get_git_repo_absolute_path() or last_git_repo
if new_git_repo ~= last_git_repo then
last_git_repo = new_git_repo
return true
end
return false
end
local function default_before_reload_cache()
log.info('Start reloading blink-cmp-git cache.')
end
local function default_get_remote_name()
local possible_remotes = {
'upstream',
'origin',
}
for _, remote in ipairs(possible_remotes) do
if utils.truthy(utils.get_repo_remote_url(remote)) then
return remote
end
end
return ''
end
local function default_kind_highlight(context, _)
return 'BlinkCmpGitKind' .. context.kind
end
local function default_kind_icon_highlight(context, _)
return 'BlinkCmpGitKindIcon' .. context.kind
end
local function default_label_highlight(context, _)
local id_len = #(context.label:match('^[^%s]+'))
-- Find id like #123, !123 or hash,
-- but not for mention
if id_len > 0 and id_len ~= #context.label then
local highlights = {
{
0,
id_len,
group = 'BlinkCmpGitLabel' .. context.kind .. 'Id'
},
{
id_len,
#context.label - id_len,
group = 'BlinkCmpGitLabel' .. context.kind .. 'Rest'
}
}
-- characters matched on the label by the fuzzy matcher
for _, idx in ipairs(context.label_matched_indices) do
table.insert(highlights,
{ idx, idx + 1, group = 'BlinkCmpLabelMatch' })
end
return highlights
end
-- return nil to use the default highlight
return nil
end
--- @type blink-cmp-git.Options
return {
async = true,
use_items_cache = true,
-- Whether or not cache the triggers when the source is loaded
use_items_pre_cache = true,
should_reload_cache = default_should_reload_cache,
before_reload_cache = default_before_reload_cache,
kind_icons = {
Commit = '',
Mention = '',
PR = '',
MR = '',
Issue = '',
},
get_cwd = vim.fn.getcwd,
get_remote_name = default_get_remote_name,
kind_highlight = default_kind_highlight,
kind_icon_highlight = default_kind_icon_highlight,
label_highlight = default_label_highlight,
commit = require('blink-cmp-git.default.commit'),
git_centers = {
github = require('blink-cmp-git.default.github'),
gitlab = require('blink-cmp-git.default.gitlab'),
}
}