Commit c84f44d6 authored by Günther Wagner's avatar Günther Wagner

Show multiple diagnostics on same line

parent 2d6d5086
Pipeline #192342 passed with stage
in 53 minutes and 40 seconds
......@@ -452,16 +452,19 @@ ide_diagnostics_foreach_line_in_range (IdeDiagnostics *self,
*
* Since: 3.32
*/
IdeDiagnostic *
GPtrArray *
ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
GFile *file,
guint line)
{
IdeDiagnosticsPrivate *priv = ide_diagnostics_get_instance_private (self);
GPtrArray *valid_diag = NULL;
g_return_val_if_fail (IDE_IS_DIAGNOSTICS (self), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
valid_diag = g_ptr_array_new ();
for (guint i = 0; i < priv->items->len; i++)
{
IdeDiagnostic *diag = g_ptr_array_index (priv->items, i);
......@@ -476,9 +479,12 @@ ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
loc_line = ide_location_get_line (loc);
if (loc_line == line && g_file_equal (file, loc_file))
return diag;
g_ptr_array_add (valid_diag, diag);
}
if (valid_diag->len != 0)
return valid_diag;
return NULL;
}
......
......@@ -88,7 +88,7 @@ void ide_diagnostics_foreach_line_in_range (IdeDiagnostics
IdeDiagnosticsLineCallback callback,
gpointer user_data);
IDE_AVAILABLE_IN_3_32
IdeDiagnostic *ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
GPtrArray *ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
GFile *file,
guint line);
......
......@@ -3402,11 +3402,12 @@ ide_source_view_real_move_error (IdeSourceView *self,
wrapped:
while (movement (&iter))
{
IdeDiagnostic *diag;
GPtrArray *line_diags;
guint line = gtk_text_iter_get_line (&iter);
if ((diag = ide_diagnostics_get_diagnostic_at_line (diagnostics, file, line)))
if ((line_diags = ide_diagnostics_get_diagnostic_at_line (diagnostics, file, line)))
{
IdeDiagnostic *diag = g_ptr_array_index (line_diags, 0);
IdeLocation *location;
location = ide_diagnostic_get_location (diag);
......@@ -4491,7 +4492,7 @@ ide_source_view_real_populate_popup (GtkTextView *text_view,
IdeSourceView *self = (IdeSourceView *)text_view;
GtkSeparatorMenuItem *sep;
IdeDiagnostics *diagnostics;
IdeDiagnostic *diagnostic = NULL;
GPtrArray *line_diags = NULL;
GtkTextBuffer *buffer;
GtkMenuItem *menu_item;
GtkTextMark *insert;
......@@ -4529,60 +4530,64 @@ ide_source_view_real_populate_popup (GtkTextView *text_view,
* If so, display the "Apply TextEdit" menu item with available fixits.
*/
if ((diagnostics = ide_buffer_get_diagnostics (IDE_BUFFER (buffer))))
diagnostic = ide_diagnostics_get_diagnostic_at_line (diagnostics,
line_diags = ide_diagnostics_get_diagnostic_at_line (diagnostics,
ide_buffer_get_file (IDE_BUFFER (buffer)),
gtk_text_iter_get_line (&iter));
if (diagnostic != NULL)
if (line_diags != NULL)
{
guint num_fixits;
for (int j = 0; j < line_diags->len; j++)
{
IdeDiagnostic *diag = g_ptr_array_index (line_diags, j);
guint num_fixits;
num_fixits = ide_diagnostic_get_n_fixits (diagnostic);
num_fixits = ide_diagnostic_get_n_fixits (diag);
if (num_fixits > 0)
{
GtkWidget *parent;
GtkWidget *submenu;
guint i;
if (num_fixits > 0)
{
GtkWidget *parent;
GtkWidget *submenu;
guint i;
sep = g_object_new (GTK_TYPE_SEPARATOR_MENU_ITEM,
"visible", TRUE,
NULL);
gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), GTK_WIDGET (sep));
sep = g_object_new (GTK_TYPE_SEPARATOR_MENU_ITEM,
"visible", TRUE,
NULL);
gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), GTK_WIDGET (sep));
submenu = gtk_menu_new ();
submenu = gtk_menu_new ();
parent = g_object_new (GTK_TYPE_MENU_ITEM,
"label", _("Apply Fix-It"),
"submenu", submenu,
"visible", TRUE,
NULL);
gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), parent);
parent = g_object_new (GTK_TYPE_MENU_ITEM,
"label", _("Apply Fix-It"),
"submenu", submenu,
"visible", TRUE,
NULL);
gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), parent);
for (i = 0; i < num_fixits; i++)
{
IdeTextEdit *fixit;
gchar *label;
fixit = ide_diagnostic_get_fixit (diagnostic, i);
label = ide_source_view_get_fixit_label (self, fixit);
menu_item = g_object_new (GTK_TYPE_MENU_ITEM,
"label", label,
"visible", TRUE,
NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (menu_item));
g_object_set_data_full (G_OBJECT (menu_item),
"IDE_FIXIT",
g_object_ref (fixit),
(GDestroyNotify)g_object_unref);
g_signal_connect_object (menu_item,
"activate",
G_CALLBACK (ide_source_view__fixit_activate),
self,
G_CONNECT_SWAPPED);
for (i = 0; i < num_fixits; i++)
{
IdeTextEdit *fixit;
gchar *label;
fixit = ide_diagnostic_get_fixit (diag, i);
label = ide_source_view_get_fixit_label (self, fixit);
menu_item = g_object_new (GTK_TYPE_MENU_ITEM,
"label", label,
"visible", TRUE,
NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (menu_item));
g_object_set_data_full (G_OBJECT (menu_item),
"IDE_FIXIT",
g_object_ref (fixit),
(GDestroyNotify)g_object_unref);
g_signal_connect_object (menu_item,
"activate",
G_CALLBACK (ide_source_view__fixit_activate),
self,
G_CONNECT_SWAPPED);
}
}
}
}
......
......@@ -62,21 +62,26 @@ gbp_editor_hover_provider_hover_async (IdeHoverProvider *provider,
GFile *file = ide_buffer_get_file (IDE_BUFFER (buffer));
guint line = gtk_text_iter_get_line (iter);
IdeDiagnostics *diagnostics;
IdeDiagnostic *diag;
GPtrArray *line_diags;
if ((diagnostics = ide_buffer_get_diagnostics (IDE_BUFFER (buffer))) &&
(diag = ide_diagnostics_get_diagnostic_at_line (diagnostics, file, line)))
(line_diags = ide_diagnostics_get_diagnostic_at_line (diagnostics, file, line)))
{
g_autoptr(IdeMarkedContent) content = NULL;
g_autofree gchar *text = ide_diagnostic_get_text_for_display (diag);
content = ide_marked_content_new_from_data (text,
strlen (text),
IDE_MARKED_KIND_PLAINTEXT);
ide_hover_context_add_content (context,
DIAGNOSTICS_HOVER_PRIORITY,
_("Diagnostics"),
content);
for (int i = 0; i < line_diags->len; i++)
{
IdeDiagnostic *diag = g_ptr_array_index (line_diags, i);
g_autoptr(IdeMarkedContent) content = NULL;
g_autofree gchar *text = ide_diagnostic_get_text_for_display (diag);
content = ide_marked_content_new_from_data (text,
strlen (text),
IDE_MARKED_KIND_PLAINTEXT);
ide_hover_context_add_content (context,
DIAGNOSTICS_HOVER_PRIORITY,
_("Diagnostics"),
content);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment