|
7 | 7 | with lib; |
8 | 8 | let |
9 | 9 | cfg = config.plugins.cmp-git; |
| 10 | + |
| 11 | + mkAction = |
| 12 | + action: target: |
| 13 | + helpers.defaultNullOpts.mkLuaFn "require('cmp_git.${action}').git.${target}" '' |
| 14 | + Function used to ${action} the ${replaceStrings [ "_" ] [ " " ] target}. |
| 15 | + ''; |
10 | 16 | in |
11 | 17 | { |
12 | 18 | options.plugins.cmp-git.settings = helpers.neovim-plugin.mkSettingsOption { |
13 | 19 | pluginName = "cmp_git"; |
14 | 20 | options = { |
15 | | - filetypes = helpers.defaultNullOpts.mkListOf types.str ''["gitcommit" "octo"]'' '' |
16 | | - Filetypes for which to trigger. |
17 | | - ''; |
| 21 | + filetypes = helpers.defaultNullOpts.mkListOf types.str [ |
| 22 | + "gitcommit" |
| 23 | + "octo" |
| 24 | + ] "Filetypes for which to trigger."; |
18 | 25 |
|
19 | | - remotes = helpers.defaultNullOpts.mkListOf types.str ''["upstream" "origin"]'' '' |
20 | | - List of git remotes. |
21 | | - ''; |
| 26 | + remotes = helpers.defaultNullOpts.mkListOf types.str [ |
| 27 | + "upstream" |
| 28 | + "origin" |
| 29 | + ] "List of git remotes."; |
22 | 30 |
|
23 | 31 | enableRemoteUrlRewrites = helpers.defaultNullOpts.mkBool false '' |
24 | 32 | Whether to enable remote URL rewrites. |
|
30 | 38 | Max number of git commits to fetch. |
31 | 39 | ''; |
32 | 40 |
|
33 | | - sort_by = |
34 | | - helpers.defaultNullOpts.mkNullable types.anything |
35 | | - ''{__raw = "require('cmp_git.sort').git.commits";}'' |
36 | | - "Function used to sort the commits."; |
37 | | - |
38 | | - format = |
39 | | - helpers.defaultNullOpts.mkNullable types.anything |
40 | | - ''{__raw = "require('cmp_git.format').git.commits";}'' |
41 | | - "Function used to format the commits."; |
| 41 | + sort_by = mkAction "sort" "commits"; |
| 42 | + format = mkAction "format" "commits"; |
42 | 43 | }; |
43 | 44 | }; |
44 | 45 |
|
45 | 46 | github = { |
46 | | - hosts = helpers.defaultNullOpts.mkListOf types.str "[]" '' |
| 47 | + hosts = helpers.defaultNullOpts.mkListOf types.str [ ] '' |
47 | 48 | List of private instances of github. |
48 | 49 | ''; |
49 | 50 |
|
50 | 51 | issues = { |
51 | | - fields = |
52 | | - helpers.defaultNullOpts.mkListOf types.str ''["title" "number" "body" "updatedAt" "state"]'' |
53 | | - "The fields used for issues."; |
| 52 | + fields = helpers.defaultNullOpts.mkListOf types.str [ |
| 53 | + "title" |
| 54 | + "number" |
| 55 | + "body" |
| 56 | + "updatedAt" |
| 57 | + "state" |
| 58 | + ] "The fields used for issues."; |
54 | 59 |
|
55 | 60 | filter = helpers.defaultNullOpts.mkStr "all" '' |
56 | 61 | The filter to use when fetching issues. |
|
64 | 69 | Which issues to fetch (`"open"`, `"closed"` or `"all"`). |
65 | 70 | ''; |
66 | 71 |
|
67 | | - sort_by = |
68 | | - helpers.defaultNullOpts.mkNullable types.anything |
69 | | - ''{__raw = "require('cmp_git.sort').github.issues";}'' |
70 | | - "Function used to sort the issues."; |
71 | | - |
72 | | - format = |
73 | | - helpers.defaultNullOpts.mkNullable types.anything |
74 | | - ''{__raw = "require('cmp_git.format').github.issues";}'' |
75 | | - "Function used to format the issues."; |
| 72 | + sort_by = mkAction "sort" "issues"; |
| 73 | + format = mkAction "format" "issues"; |
76 | 74 | }; |
77 | 75 |
|
78 | 76 | mentions = { |
79 | 77 | limit = helpers.defaultNullOpts.mkUnsignedInt 100 '' |
80 | 78 | Max number of mentions to fetch. |
81 | 79 | ''; |
82 | 80 |
|
83 | | - sort_by = |
84 | | - helpers.defaultNullOpts.mkNullable types.anything |
85 | | - ''{__raw = "require('cmp_git.sort').github.mentions";}'' |
86 | | - "Function used to sort the mentions."; |
87 | | - |
88 | | - format = |
89 | | - helpers.defaultNullOpts.mkNullable types.anything |
90 | | - ''{__raw = "require('cmp_git.format').github.mentions";}'' |
91 | | - "Function used to format the mentions."; |
| 81 | + sort_by = mkAction "sort" "mentions"; |
| 82 | + format = mkAction "format" "mentions"; |
92 | 83 | }; |
93 | 84 |
|
94 | 85 | pull_requests = { |
95 | | - fields = |
96 | | - helpers.defaultNullOpts.mkListOf types.str ''["title" "number" "body" "updatedAt" "state"]'' |
97 | | - "The fields used for pull requests."; |
| 86 | + fields = helpers.defaultNullOpts.mkListOf types.str [ |
| 87 | + "title" |
| 88 | + "number" |
| 89 | + "body" |
| 90 | + "updatedAt" |
| 91 | + "state" |
| 92 | + ] "The fields used for pull requests."; |
98 | 93 |
|
99 | 94 | limit = helpers.defaultNullOpts.mkUnsignedInt 100 '' |
100 | 95 | Max number of pull requests to fetch. |
|
104 | 99 | Which issues to fetch (`"open"`, `"closed"`, `"merged"` or `"all"`). |
105 | 100 | ''; |
106 | 101 |
|
107 | | - sort_by = |
108 | | - helpers.defaultNullOpts.mkNullable types.anything |
109 | | - ''{__raw = "require('cmp_git.sort').github.pull_requests";}'' |
110 | | - "Function used to sort the pull requests."; |
111 | | - |
112 | | - format = |
113 | | - helpers.defaultNullOpts.mkNullable types.anything |
114 | | - ''{__raw = "require('cmp_git.format').github.pull_requests";}'' |
115 | | - "Function used to format the pull requests."; |
| 102 | + sort_by = mkAction "sort" "pull_requests"; |
| 103 | + format = mkAction "format" "pull_requests"; |
116 | 104 | }; |
117 | 105 | }; |
118 | 106 |
|
119 | 107 | gitlab = { |
120 | | - hosts = helpers.defaultNullOpts.mkListOf types.str "[]" '' |
| 108 | + hosts = helpers.defaultNullOpts.mkListOf types.str [ ] '' |
121 | 109 | List of private instances of gitlab. |
122 | 110 | ''; |
123 | 111 |
|
|
130 | 118 | Which issues to fetch (`"open"`, `"closed"` or `"all"`). |
131 | 119 | ''; |
132 | 120 |
|
133 | | - sort_by = |
134 | | - helpers.defaultNullOpts.mkNullable types.anything |
135 | | - ''{__raw = "require('cmp_git.sort').gitlab.issues";}'' |
136 | | - "Function used to sort the issues."; |
137 | | - |
138 | | - format = |
139 | | - helpers.defaultNullOpts.mkNullable types.anything |
140 | | - ''{__raw = "require('cmp_git.format').gitlab.issues";}'' |
141 | | - "Function used to format the issues."; |
| 121 | + sort_by = mkAction "sort" "issues"; |
| 122 | + format = mkAction "format" "issues"; |
142 | 123 | }; |
143 | 124 |
|
144 | 125 | mentions = { |
145 | 126 | limit = helpers.defaultNullOpts.mkUnsignedInt 100 '' |
146 | 127 | Max number of mentions to fetch. |
147 | 128 | ''; |
148 | 129 |
|
149 | | - sort_by = |
150 | | - helpers.defaultNullOpts.mkNullable types.anything |
151 | | - ''{__raw = "require('cmp_git.sort').gitlab.mentions";}'' |
152 | | - "Function used to sort the mentions."; |
153 | | - |
154 | | - format = |
155 | | - helpers.defaultNullOpts.mkNullable types.anything |
156 | | - ''{__raw = "require('cmp_git.format').gitlab.mentions";}'' |
157 | | - "Function used to format the mentions."; |
| 130 | + sort_by = mkAction "sort" "mentions"; |
| 131 | + format = mkAction "format" "mentions"; |
158 | 132 | }; |
159 | 133 |
|
160 | 134 | merge_requests = { |
|
166 | 140 | Which issues to fetch (`"open"`, `"closed"`, `"locked"` or `"merged"`). |
167 | 141 | ''; |
168 | 142 |
|
169 | | - sort_by = |
170 | | - helpers.defaultNullOpts.mkNullable types.anything |
171 | | - ''{__raw = "require('cmp_git.sort').gitlab.merge_requests";}'' |
172 | | - "Function used to sort the merge requests."; |
173 | | - |
174 | | - format = |
175 | | - helpers.defaultNullOpts.mkNullable types.anything |
176 | | - ''{__raw = "require('cmp_git.format').gitlab.merge_requests";}'' |
177 | | - "Function used to format the merge requests."; |
| 143 | + sort_by = mkAction "sort" "merge_requests"; |
| 144 | + format = mkAction "format" "merge_requests"; |
178 | 145 | }; |
179 | 146 | }; |
180 | 147 |
|
|
209 | 176 | }; |
210 | 177 | }; |
211 | 178 | }) |
212 | | - '' |
213 | | - [ |
214 | | - { |
215 | | - debug_name = "git_commits"; |
216 | | - trigger_character = ":"; |
217 | | - action = \'\' |
218 | | - function(sources, trigger_char, callback, params, git_info) |
219 | | - return sources.git:get_commits(callback, params, trigger_char) |
220 | | - end |
221 | | - \'\'; |
222 | | - } |
223 | | - { |
224 | | - debug_name = "gitlab_issues"; |
225 | | - trigger_character = "#"; |
226 | | - action = \'\' |
227 | | - function(sources, trigger_char, callback, params, git_info) |
228 | | - return sources.gitlab:get_issues(callback, git_info, trigger_char) |
229 | | - end |
230 | | - \'\'; |
231 | | - } |
232 | | - { |
233 | | - debug_name = "gitlab_mentions"; |
234 | | - trigger_character = "@"; |
235 | | - action = \'\' |
236 | | - function(sources, trigger_char, callback, params, git_info) |
237 | | - return sources.gitlab:get_mentions(callback, git_info, trigger_char) |
238 | | - end |
239 | | - \'\'; |
240 | | - } |
241 | | - { |
242 | | - debug_name = "gitlab_mrs"; |
243 | | - trigger_character = "!"; |
244 | | - action = \'\' |
245 | | - function(sources, trigger_char, callback, params, git_info) |
246 | | - return sources.gitlab:get_merge_requests(callback, git_info, trigger_char) |
247 | | - end |
248 | | - \'\'; |
249 | | - } |
250 | | - { |
251 | | - debug_name = "github_issues_and_pr"; |
252 | | - trigger_character = "#"; |
253 | | - action = \'\' |
254 | | - function(sources, trigger_char, callback, params, git_info) |
255 | | - return sources.github:get_issues_and_prs(callback, git_info, trigger_char) |
256 | | - end |
257 | | - \'\'; |
258 | | - } |
259 | | - { |
260 | | - debug_name = "github_mentions"; |
261 | | - trigger_character = "@"; |
262 | | - action = \'\' |
263 | | - function(sources, trigger_char, callback, params, git_info) |
264 | | - return sources.github:get_mentions(callback, git_info, trigger_char) |
265 | | - end |
266 | | - \'\'; |
267 | | - } |
268 | | - ] |
269 | | - '' |
| 179 | + [ |
| 180 | + { |
| 181 | + debug_name = "git_commits"; |
| 182 | + trigger_character = ":"; |
| 183 | + action = '' |
| 184 | + function(sources, trigger_char, callback, params, git_info) |
| 185 | + return sources.git:get_commits(callback, params, trigger_char) |
| 186 | + end |
| 187 | + ''; |
| 188 | + } |
| 189 | + { |
| 190 | + debug_name = "gitlab_issues"; |
| 191 | + trigger_character = "#"; |
| 192 | + action = '' |
| 193 | + function(sources, trigger_char, callback, params, git_info) |
| 194 | + return sources.gitlab:get_issues(callback, git_info, trigger_char) |
| 195 | + end |
| 196 | + ''; |
| 197 | + } |
| 198 | + { |
| 199 | + debug_name = "gitlab_mentions"; |
| 200 | + trigger_character = "@"; |
| 201 | + action = '' |
| 202 | + function(sources, trigger_char, callback, params, git_info) |
| 203 | + return sources.gitlab:get_mentions(callback, git_info, trigger_char) |
| 204 | + end |
| 205 | + ''; |
| 206 | + } |
| 207 | + { |
| 208 | + debug_name = "gitlab_mrs"; |
| 209 | + trigger_character = "!"; |
| 210 | + action = '' |
| 211 | + function(sources, trigger_char, callback, params, git_info) |
| 212 | + return sources.gitlab:get_merge_requests(callback, git_info, trigger_char) |
| 213 | + end |
| 214 | + ''; |
| 215 | + } |
| 216 | + { |
| 217 | + debug_name = "github_issues_and_pr"; |
| 218 | + trigger_character = "#"; |
| 219 | + action = '' |
| 220 | + function(sources, trigger_char, callback, params, git_info) |
| 221 | + return sources.github:get_issues_and_prs(callback, git_info, trigger_char) |
| 222 | + end |
| 223 | + ''; |
| 224 | + } |
| 225 | + { |
| 226 | + debug_name = "github_mentions"; |
| 227 | + trigger_character = "@"; |
| 228 | + action = '' |
| 229 | + function(sources, trigger_char, callback, params, git_info) |
| 230 | + return sources.github:get_mentions(callback, git_info, trigger_char) |
| 231 | + end |
| 232 | + ''; |
| 233 | + } |
| 234 | + ] |
270 | 235 | '' |
271 | 236 | If you want specific behaviour for a trigger or new behaviour for a trigger, you need to |
272 | 237 | add an entry in the `trigger_actions` list of the config. |
|
284 | 249 | filter = "all"; |
285 | 250 | limit = 250; |
286 | 251 | state = "all"; |
287 | | - format.label.__raw = '' |
| 252 | + format = '' |
288 | 253 | function(_, issue) |
289 | 254 | local icon = ({ |
290 | 255 | open = '', |
|
293 | 258 | return string.format('%s #%d: %s', icon, issue.number, issue.title) |
294 | 259 | end |
295 | 260 | ''; |
296 | | - sort_by.__raw = '' |
| 261 | + sort_by = '' |
297 | 262 | function(issue) |
298 | 263 | local kind_rank = issue.pull_request and 1 or 0 |
299 | 264 | local state_rank = issue.state == 'open' and 0 or 1 |
300 | 265 | local age = os.difftime(os.time(), require('cmp_git.utils').parse_github_date(issue.updatedAt)) |
301 | 266 | return string.format('%d%d%010d', kind_rank, state_rank, age) |
302 | 267 | end |
303 | 268 | ''; |
304 | | - filter_fn.__raw = '' |
305 | | - function(trigger_char, issue) |
306 | | - return string.format('%s %s %s', trigger_char, issue.number, issue.title) |
307 | | - end |
308 | | - ''; |
309 | 269 | }; |
310 | 270 | trigger_actions = [ |
311 | 271 | { |
|
0 commit comments