|
1 | 1 | -- This module contains code shared between at least two modules. This includes |
2 | 2 | -- actions common to multiple tree types, as well as general utility functions |
3 | 3 | -- that are specific to actions (like jumping to a file or opening a URL) |
| 4 | +local List = require("gitlab.utils.list") |
4 | 5 | local u = require("gitlab.utils") |
5 | 6 | local reviewer = require("gitlab.reviewer") |
6 | 7 | local common_indicators = require("gitlab.indicators.common") |
@@ -38,29 +39,52 @@ M.build_content = function(content) |
38 | 39 | return description_lines |
39 | 40 | end |
40 | 41 |
|
41 | | ----@class TitleArg |
42 | | ----@field bufnr integer |
43 | | ----@field title string |
44 | | ----@field data table |
45 | | - |
46 | | ----@param title_args TitleArg[] |
47 | | -M.add_empty_titles = function(title_args) |
48 | | - for _, v in ipairs(title_args) do |
49 | | - M.switch_can_edit_bufs(true, v.bufnr) |
50 | | - local ns_id = vim.api.nvim_create_namespace("GitlabNamespace") |
51 | | - vim.cmd("highlight default TitleHighlight guifg=#787878") |
52 | | - |
53 | | - -- Set empty title if applicable |
54 | | - if type(v.data) ~= "table" or #v.data == 0 then |
55 | | - vim.api.nvim_buf_set_lines(v.bufnr, 0, 1, false, { v.title }) |
56 | | - local linnr = 1 |
57 | | - vim.api.nvim_buf_set_extmark( |
58 | | - v.bufnr, |
59 | | - ns_id, |
60 | | - linnr - 1, |
61 | | - 0, |
62 | | - { end_row = linnr - 1, end_col = string.len(v.title), hl_group = "TitleHighlight" } |
63 | | - ) |
| 42 | +M.add_empty_titles = function() |
| 43 | + local draft_notes = require("gitlab.actions.draft_notes") |
| 44 | + local discussions = require("gitlab.actions.discussions") |
| 45 | + local linked, unlinked, drafts = |
| 46 | + List.new(u.ensure_table(state.DISCUSSION_DATA and state.DISCUSSION_DATA.discussions)), |
| 47 | + List.new(u.ensure_table(state.DISCUSSION_DATA and state.DISCUSSION_DATA.unlinked_discussions)), |
| 48 | + List.new(u.ensure_table(state.DRAFT_NOTES)) |
| 49 | + |
| 50 | + local position_drafts = drafts:filter(function(note) |
| 51 | + return draft_notes.has_position(note) |
| 52 | + end) |
| 53 | + local non_positioned_drafts = drafts:filter(function(note) |
| 54 | + return not draft_notes.has_position(note) |
| 55 | + end) |
| 56 | + |
| 57 | + local fields = { |
| 58 | + { |
| 59 | + bufnr = discussions.linked_bufnr, |
| 60 | + count = #linked + #position_drafts, |
| 61 | + title = "No Discussions for this MR", |
| 62 | + }, |
| 63 | + { |
| 64 | + bufnr = discussions.unlinked_bufnr, |
| 65 | + count = #unlinked + #non_positioned_drafts, |
| 66 | + title = "No Notes (Unlinked Discussions) for this MR", |
| 67 | + }, |
| 68 | + } |
| 69 | + |
| 70 | + for _, v in ipairs(fields) do |
| 71 | + if v.bufnr ~= nil then |
| 72 | + M.switch_can_edit_bufs(true, v.bufnr) |
| 73 | + local ns_id = vim.api.nvim_create_namespace("GitlabNamespace") |
| 74 | + vim.cmd("highlight default TitleHighlight guifg=#787878") |
| 75 | + |
| 76 | + -- Set empty title if applicable |
| 77 | + if v.count == 0 then |
| 78 | + vim.api.nvim_buf_set_lines(v.bufnr, 0, 1, false, { v.title }) |
| 79 | + local linnr = 1 |
| 80 | + vim.api.nvim_buf_set_extmark( |
| 81 | + v.bufnr, |
| 82 | + ns_id, |
| 83 | + linnr - 1, |
| 84 | + 0, |
| 85 | + { end_row = linnr - 1, end_col = string.len(v.title), hl_group = "TitleHighlight" } |
| 86 | + ) |
| 87 | + end |
64 | 88 | end |
65 | 89 | end |
66 | 90 | end |
|
0 commit comments