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

Reserve API and transfer full for diagnostics

parent c84f44d6
Pipeline #192406 passed with stage
in 33 minutes and 35 seconds
......@@ -452,18 +452,60 @@ ide_diagnostics_foreach_line_in_range (IdeDiagnostics *self,
*
* Since: 3.32
*/
GPtrArray *
IdeDiagnostic *
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);
IdeLocation *loc = ide_diagnostic_get_location (diag);
GFile *loc_file;
guint loc_line;
if (loc == NULL)
continue;
loc_file = ide_location_get_file (loc);
loc_line = ide_location_get_line (loc);
if (loc_line == line && g_file_equal (file, loc_file))
return diag;
}
return NULL;
}
/**
* ide_diagnostics_get_diagnostics_at_line:
* @self: a #IdeDiagnostics
* @file: the target file
* @line: a line number
*
* Locates all #IdeDiagnostic in @file at @line.
*
* Returns: (transfer full) (element-type IdeDiagnostic) (nullable): an #GPtrArray or %NULL
*
* Since: 3.38
*/
GPtrArray *
ide_diagnostics_get_diagnostics_at_line (IdeDiagnostics *self,
GFile *file,
guint line)
{
IdeDiagnosticsPrivate *priv = ide_diagnostics_get_instance_private (self);
g_autoptr(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_with_free_func (g_object_unref);
for (guint i = 0; i < priv->items->len; i++)
{
......@@ -479,11 +521,11 @@ 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))
g_ptr_array_add (valid_diag, diag);
g_ptr_array_add (valid_diag, g_object_ref(diag));
}
if (valid_diag->len != 0)
return valid_diag;
return IDE_PTR_ARRAY_STEAL_FULL (&valid_diag);
return NULL;
}
......
......@@ -88,7 +88,11 @@ void ide_diagnostics_foreach_line_in_range (IdeDiagnostics
IdeDiagnosticsLineCallback callback,
gpointer user_data);
IDE_AVAILABLE_IN_3_32
GPtrArray *ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
IdeDiagnostic *ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
GFile *file,
guint line);
IDE_AVAILABLE_IN_3_36
GPtrArray *ide_diagnostics_get_diagnostics_at_line (IdeDiagnostics *self,
GFile *file,
guint line);
......
......@@ -3402,12 +3402,11 @@ ide_source_view_real_move_error (IdeSourceView *self,
wrapped:
while (movement (&iter))
{
GPtrArray *line_diags;
IdeDiagnostic *diag;
guint line = gtk_text_iter_get_line (&iter);
if ((line_diags = ide_diagnostics_get_diagnostic_at_line (diagnostics, file, line)))
if ((diag = 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);
......@@ -4530,13 +4529,16 @@ 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))))
line_diags = ide_diagnostics_get_diagnostic_at_line (diagnostics,
{
line_diags = ide_diagnostics_get_diagnostics_at_line (diagnostics,
ide_buffer_get_file (IDE_BUFFER (buffer)),
gtk_text_iter_get_line (&iter));
IDE_PTR_ARRAY_SET_FREE_FUNC (line_diags, g_object_unref);
}
if (line_diags != NULL)
{
for (int j = 0; j < line_diags->len; j++)
for (guint j = 0; j < line_diags->len; j++)
{
IdeDiagnostic *diag = g_ptr_array_index (line_diags, j);
guint num_fixits;
......
......@@ -64,10 +64,13 @@ gbp_editor_hover_provider_hover_async (IdeHoverProvider *provider,
IdeDiagnostics *diagnostics;
GPtrArray *line_diags;
if ((diagnostics = ide_buffer_get_diagnostics (IDE_BUFFER (buffer))) &&
(line_diags = ide_diagnostics_get_diagnostic_at_line (diagnostics, file, line)))
diagnostics = ide_buffer_get_diagnostics (IDE_BUFFER (buffer));
line_diags = ide_diagnostics_get_diagnostics_at_line (diagnostics, file, line);
IDE_PTR_ARRAY_SET_FREE_FUNC (line_diags, g_object_unref);
if (diagnostics && line_diags)
{
for (int i = 0; i < line_diags->len; i++)
for (guint i = 0; i < line_diags->len; i++)
{
IdeDiagnostic *diag = g_ptr_array_index (line_diags, i);
g_autoptr(IdeMarkedContent) content = NULL;
......
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