[gnome-builder] code: add ide_diagnostics_get_diagnostics_at_line()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] code: add ide_diagnostics_get_diagnostics_at_line()
- Date: Wed, 1 Jul 2020 01:29:25 +0000 (UTC)
commit 2610902596a141c5a128a8821eac313e2abc7f34
Author: Günther Wagner <info gunibert de>
Date: Mon Jun 29 22:13:53 2020 +0200
code: add ide_diagnostics_get_diagnostics_at_line()
src/libide/code/ide-diagnostics.c | 48 +++++++++++++++++++++++++++++++++++++++
src/libide/code/ide-diagnostics.h | 46 ++++++++++++++++++++-----------------
2 files changed, 73 insertions(+), 21 deletions(-)
---
diff --git a/src/libide/code/ide-diagnostics.c b/src/libide/code/ide-diagnostics.c
index 0bb462465..ec430b5ee 100644
--- a/src/libide/code/ide-diagnostics.c
+++ b/src/libide/code/ide-diagnostics.c
@@ -482,6 +482,54 @@ ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
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++)
+ {
+ 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))
+ g_ptr_array_add (valid_diag, g_object_ref(diag));
+ }
+
+ if (valid_diag->len != 0)
+ return IDE_PTR_ARRAY_STEAL_FULL (&valid_diag);
+
+ return NULL;
+}
+
/**
* ide_diagnostics_new_from_array:
* @array: (nullable) (element-type IdeDiagnostic): optional array
diff --git a/src/libide/code/ide-diagnostics.h b/src/libide/code/ide-diagnostics.h
index 5fbc47d97..40041d103 100644
--- a/src/libide/code/ide-diagnostics.h
+++ b/src/libide/code/ide-diagnostics.h
@@ -60,37 +60,41 @@ struct _IdeDiagnosticsClass
};
IDE_AVAILABLE_IN_3_32
-IdeDiagnostics *ide_diagnostics_new (void);
+IdeDiagnostics *ide_diagnostics_new (void);
IDE_AVAILABLE_IN_3_32
-IdeDiagnostics *ide_diagnostics_new_from_array (GPtrArray *array);
+IdeDiagnostics *ide_diagnostics_new_from_array (GPtrArray *array);
IDE_AVAILABLE_IN_3_32
-void ide_diagnostics_add (IdeDiagnostics *self,
- IdeDiagnostic *diagnostic);
+void ide_diagnostics_add (IdeDiagnostics *self,
+ IdeDiagnostic *diagnostic);
IDE_AVAILABLE_IN_3_32
-void ide_diagnostics_take (IdeDiagnostics *self,
- IdeDiagnostic *diagnostic);
+void ide_diagnostics_take (IdeDiagnostics *self,
+ IdeDiagnostic *diagnostic);
IDE_AVAILABLE_IN_3_32
-void ide_diagnostics_merge (IdeDiagnostics *self,
- IdeDiagnostics *other);
+void ide_diagnostics_merge (IdeDiagnostics *self,
+ IdeDiagnostics *other);
IDE_AVAILABLE_IN_3_32
-guint ide_diagnostics_get_n_errors (IdeDiagnostics *self);
+guint ide_diagnostics_get_n_errors (IdeDiagnostics *self);
IDE_AVAILABLE_IN_3_32
-gboolean ide_diagnostics_get_has_errors (IdeDiagnostics *self);
+gboolean ide_diagnostics_get_has_errors (IdeDiagnostics *self);
IDE_AVAILABLE_IN_3_32
-guint ide_diagnostics_get_n_warnings (IdeDiagnostics *self);
+guint ide_diagnostics_get_n_warnings (IdeDiagnostics *self);
IDE_AVAILABLE_IN_3_32
-gboolean ide_diagnostics_get_has_warnings (IdeDiagnostics *self);
+gboolean ide_diagnostics_get_has_warnings (IdeDiagnostics *self);
IDE_AVAILABLE_IN_3_32
-void ide_diagnostics_foreach_line_in_range (IdeDiagnostics *self,
- GFile *file,
- guint begin_line,
- guint end_line,
- IdeDiagnosticsLineCallback callback,
- gpointer user_data);
+void ide_diagnostics_foreach_line_in_range (IdeDiagnostics *self,
+ GFile *file,
+ guint begin_line,
+ guint end_line,
+ IdeDiagnosticsLineCallback callback,
+ gpointer user_data);
IDE_AVAILABLE_IN_3_32
-IdeDiagnostic *ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
- GFile *file,
- guint line);
+IdeDiagnostic *ide_diagnostics_get_diagnostic_at_line (IdeDiagnostics *self,
+ GFile *file,
+ guint line);
+IDE_AVAILABLE_IN_3_38
+GPtrArray *ide_diagnostics_get_diagnostics_at_line (IdeDiagnostics *self,
+ GFile *file,
+ guint line);
#define ide_diagnostics_get_size(d) ((gsize)g_list_model_get_n_items(G_LIST_MODEL(d)))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]