[gnome-builder] diagnostic: add ide_diagnostic_get_file()



commit 606703649cd5c1f3383fbb39156e4f2b225b0c8c
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 27 18:17:41 2016 -0700

    diagnostic: add ide_diagnostic_get_file()
    
    This is a helper to get the file from the source location. It just cleans
    up consumers of the diagnostics.

 libide/diagnostics/ide-diagnostic.c |   33 ++++++++++++++++++++++++++++++---
 libide/diagnostics/ide-diagnostic.h |    3 +++
 2 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/libide/diagnostics/ide-diagnostic.c b/libide/diagnostics/ide-diagnostic.c
index 589576a..e35ed2b 100644
--- a/libide/diagnostics/ide-diagnostic.c
+++ b/libide/diagnostics/ide-diagnostic.c
@@ -20,10 +20,12 @@
 
 #include "egg-counter.h"
 
-#include "ide-diagnostic.h"
 #include "ide-internal.h"
-#include "ide-source-location.h"
-#include "ide-source-range.h"
+
+#include "files/ide-file.h"
+#include "diagnostics/ide-diagnostic.h"
+#include "diagnostics/ide-source-location.h"
+#include "diagnostics/ide-source-range.h"
 
 G_DEFINE_BOXED_TYPE (IdeDiagnostic, ide_diagnostic, ide_diagnostic_ref, ide_diagnostic_unref)
 
@@ -364,3 +366,28 @@ ide_diagnostic_compare (const IdeDiagnostic *a,
 
   return g_strcmp0 (a->text, b->text);
 }
+
+/**
+ * ide_diagnostic_get_file:
+ *
+ * This is a helper to simplify the process of determining what file
+ * the diagnostic is within. It is equivalent to getting the source
+ * location and looking at the file.
+ *
+ * Returns: (nullable) (transfer none): A #GFile or %NULL.
+ */
+GFile *
+ide_diagnostic_get_file (IdeDiagnostic *self)
+{
+  g_return_val_if_fail (self != NULL, NULL);
+
+  if (self->location != NULL)
+    {
+      IdeFile *file = ide_source_location_get_file (self->location);
+
+      if (file != NULL)
+        return ide_file_get_file (file);
+    }
+
+  return NULL;
+}
diff --git a/libide/diagnostics/ide-diagnostic.h b/libide/diagnostics/ide-diagnostic.h
index a41b31a..d8bb3c2 100644
--- a/libide/diagnostics/ide-diagnostic.h
+++ b/libide/diagnostics/ide-diagnostic.h
@@ -19,6 +19,8 @@
 #ifndef IDE_DIAGNOSTIC_H
 #define IDE_DIAGNOSTIC_H
 
+#include <gio/gio.h>
+
 #include "ide-fixit.h"
 #include "ide-types.h"
 
@@ -37,6 +39,7 @@ typedef enum
 } IdeDiagnosticSeverity;
 
 IdeSourceLocation     *ide_diagnostic_get_location         (IdeDiagnostic         *self);
+GFile                 *ide_diagnostic_get_file             (IdeDiagnostic         *self);
 guint                  ide_diagnostic_get_num_fixits       (IdeDiagnostic         *self);
 IdeFixit              *ide_diagnostic_get_fixit            (IdeDiagnostic         *self,
                                                             guint                  index);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]