@@ -69,30 +69,9 @@ local function get_diff_square_counts(text_document_edit)
69
69
}
70
70
end
71
71
72
- -- We need to use virtual text here as coloring the squares differently simply
73
- -- is not possible with traditional syntax highlighting. At least not without
74
- -- much pita.
75
- local function add_colored_diff_square_as_virtual_text (buffer_number , action )
76
- local workspace_edit = action :get_workspace_edit ()
77
-
78
- for index , text_document_edit in ipairs (workspace_edit .all_text_document_edits ) do
79
- local square_counts = get_diff_square_counts (text_document_edit )
80
- local chunks = {}
81
-
82
- if square_counts .added > 0 then
83
- table.insert (chunks , { string.rep (' ■' , square_counts .added ), ' CodeActionMenuDetailsAddedSquares' })
84
- end
85
-
86
- if square_counts .deleted > 0 then
87
- table.insert (chunks , { string.rep (' ■' , square_counts .deleted ), ' CodeActionMenuDetailsDeletedSquares' })
88
- end
89
-
90
- if square_counts .neutral > 0 then
91
- table.insert (chunks , { string.rep (' ■' , square_counts .neutral ), ' CodeActionMenuDetailsNeutralSquares' })
92
- end
93
-
94
- vim .api .nvim_buf_set_virtual_text (buffer_number , - 1 , index - 1 , chunks , {} )
95
- end
72
+ function get_count_of_edits_diff_lines (text_document_edit )
73
+ local diff_lines = get_diff_lines_formatted (text_document_edit )
74
+ return # diff_lines
96
75
end
97
76
98
77
DiffWindow = StackingWindow :new ()
@@ -121,7 +100,37 @@ function DiffWindow:get_content()
121
100
end
122
101
123
102
return content
124
- -- add_colored_diff_square_as_virtual_text(buffer_number, self.action)
103
+ end
104
+
105
+ function DiffWindow :update_virtual_text ()
106
+ local workspace_edit = self .action :get_workspace_edit ()
107
+ local summary_line_index = 0
108
+
109
+ for _ , text_document_edit in ipairs (workspace_edit .all_text_document_edits ) do
110
+ local square_counts = get_diff_square_counts (text_document_edit )
111
+ local chunks = {}
112
+
113
+ if square_counts .added > 0 then
114
+ table.insert (chunks , { string.rep (' ■' , square_counts .added ), ' CodeActionMenuDetailsAddedSquares' })
115
+ end
116
+
117
+ if square_counts .deleted > 0 then
118
+ table.insert (chunks , { string.rep (' ■' , square_counts .deleted ), ' CodeActionMenuDetailsDeletedSquares' })
119
+ end
120
+
121
+ if square_counts .neutral > 0 then
122
+ table.insert (chunks , { string.rep (' ■' , square_counts .neutral ), ' CodeActionMenuDetailsNeutralSquares' })
123
+ end
124
+
125
+ vim .api .nvim_buf_set_virtual_text (
126
+ self .buffer_number ,
127
+ self .namespace_id ,
128
+ summary_line_index ,
129
+ chunks ,
130
+ {}
131
+ )
132
+ summary_line_index = summary_line_index + get_count_of_edits_diff_lines (text_document_edit )
133
+ end
125
134
end
126
135
127
136
function DiffWindow :set_action (action )
0 commit comments