[gnome-builder] buffer: check if diagnostics are for the current file



commit 24ab802b8ac93bc4989b7363fbb64b6ea5c69ffa
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 25 23:51:19 2016 -0700

    buffer: check if diagnostics are for the current file
    
    We might get diagnostics back for files that are not visible (such as
    included files). So check them in get_has_diagnostics().

 libide/ide-buffer.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index 7db2864..5ec6574 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -142,13 +142,34 @@ gboolean
 ide_buffer_get_has_diagnostics (IdeBuffer *self)
 {
   IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
+  guint size;
+  guint i;
 
   g_return_val_if_fail (IDE_IS_BUFFER (self), FALSE);
 
   if (priv->diagnostics == NULL)
     return FALSE;
 
-  return (ide_diagnostics_get_size (priv->diagnostics) > 0);
+  /*
+   * The diagnostics set might include warnings for files other than
+   * our own. So we need to verify they are for this file. As long as
+   * this is usually just used via bindings, its not expensive enough
+   * to matter much.
+   */
+
+  size = ide_diagnostics_get_size (priv->diagnostics);
+
+  for (i = 0; i < size; i++)
+    {
+      IdeDiagnostic *diag = ide_diagnostics_index (priv->diagnostics, i);
+      IdeSourceLocation *loc = ide_diagnostic_get_location (diag);
+      IdeFile *file = ide_source_location_get_file (loc);
+
+      if (priv->file && file && ide_file_equal (priv->file, file))
+        return TRUE;
+    }
+
+  return FALSE;
 }
 
 /**


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