[gnome-builder] clang: allow specifying the file you want diagnostics for
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] clang: allow specifying the file you want diagnostics for
- Date: Wed, 1 Apr 2015 07:56:36 +0000 (UTC)
commit 3ea853872e336af0fc744b7c8898c0c6f989aa5a
Author: Christian Hergert <christian hergert me>
Date: Wed Apr 1 00:54:11 2015 -0700
clang: allow specifying the file you want diagnostics for
This will allow us to ask for the diagnostics in a .h file while having
compiled the .c for the translation unit.
libide/clang/ide-clang-translation-unit.c | 41 ++++++++++++++++++++++-------
libide/clang/ide-clang-translation-unit.h | 37 +++++++++++++------------
2 files changed, 50 insertions(+), 28 deletions(-)
---
diff --git a/libide/clang/ide-clang-translation-unit.c b/libide/clang/ide-clang-translation-unit.c
index 5cf87c3..bb8da11 100644
--- a/libide/clang/ide-clang-translation-unit.c
+++ b/libide/clang/ide-clang-translation-unit.c
@@ -44,9 +44,9 @@ struct _IdeClangTranslationUnit
CXTranslationUnit tu;
gint64 sequence;
- IdeDiagnostics *diagnostics;
GFile *file;
IdeHighlightIndex *index;
+ GHashTable *diagnostics;
};
typedef struct
@@ -303,6 +303,7 @@ static IdeDiagnostic *
create_diagnostic (IdeClangTranslationUnit *self,
IdeProject *project,
const gchar *workpath,
+ GFile *target,
CXDiagnostic *cxdiag)
{
enum CXDiagnosticSeverity cxseverity;
@@ -322,7 +323,7 @@ create_diagnostic (IdeClangTranslationUnit *self,
cxloc = clang_getDiagnosticLocation (cxdiag);
clang_getExpansionLocation (cxloc, &cxfile, NULL, NULL, NULL);
- if (cxfile && !cxfile_equal (cxfile, self->file))
+ if (cxfile && !cxfile_equal (cxfile, target))
return NULL;
cxseverity = clang_getDiagnosticSeverity (cxdiag);
@@ -353,19 +354,19 @@ create_diagnostic (IdeClangTranslationUnit *self,
}
/**
- * ide_clang_translation_unit_get_diagnostics:
+ * ide_clang_translation_unit_get_diagnostics_for_file:
*
- * Retrieves the diagnostics for the translation unit.
+ * Retrieves the diagnostics for the translation unit for a specific file.
*
* Returns: (transfer none) (nullable): An #IdeDiagnostics or %NULL.
*/
IdeDiagnostics *
-ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self)
+ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *self,
+ GFile *file)
{
-
g_return_val_if_fail (IDE_IS_CLANG_TRANSLATION_UNIT (self), NULL);
- if (!self->diagnostics)
+ if (!g_hash_table_contains (self->diagnostics, file))
{
IdeContext *context;
IdeProject *project;
@@ -400,7 +401,7 @@ ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self)
IdeDiagnostic *diag;
cxdiag = clang_getDiagnostic (self->tu, i);
- diag = create_diagnostic (self, project, workpath, cxdiag);
+ diag = create_diagnostic (self, project, workpath, file, cxdiag);
if (diag != NULL)
{
@@ -433,10 +434,25 @@ ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self)
ide_project_reader_unlock (project);
- self->diagnostics = _ide_diagnostics_new (diags);
+ g_hash_table_insert (self->diagnostics,
+ g_object_ref (file),
+ _ide_diagnostics_new (diags));
}
- return self->diagnostics;
+ return g_hash_table_lookup (self->diagnostics, file);
+}
+
+/**
+ * ide_clang_translation_unit_get_diagnostics:
+ *
+ * Retrieves the diagnostics for the translation unit.
+ *
+ * Returns: (transfer none) (nullable): An #IdeDiagnostics or %NULL.
+ */
+IdeDiagnostics *
+ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self)
+{
+ return ide_clang_translation_unit_get_diagnostics_for_file (self, self->file);
}
gint64
@@ -458,6 +474,7 @@ ide_clang_translation_unit_finalize (GObject *object)
g_clear_pointer (&self->diagnostics, ide_diagnostics_unref);
g_clear_object (&self->file);
g_clear_pointer (&self->index, ide_highlight_index_unref);
+ g_clear_pointer (&self->diagnostics, g_hash_table_unref);
G_OBJECT_CLASS (ide_clang_translation_unit_parent_class)->finalize (object);
@@ -553,6 +570,10 @@ ide_clang_translation_unit_class_init (IdeClangTranslationUnitClass *klass)
static void
ide_clang_translation_unit_init (IdeClangTranslationUnit *self)
{
+ self->diagnostics = g_hash_table_new_full ((GHashFunc)g_file_hash,
+ (GEqualFunc)g_file_equal,
+ g_object_unref,
+ (GDestroyNotify)ide_diagnostics_unref);
}
static void
diff --git a/libide/clang/ide-clang-translation-unit.h b/libide/clang/ide-clang-translation-unit.h
index 4d9dede..1604dd0 100644
--- a/libide/clang/ide-clang-translation-unit.h
+++ b/libide/clang/ide-clang-translation-unit.h
@@ -30,24 +30,25 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeClangTranslationUnit, ide_clang_translation_unit, IDE, CLANG_TRANSLATION_UNIT,
IdeObject)
-gint64 ide_clang_translation_unit_get_sequence (IdeClangTranslationUnit *self);
-IdeDiagnostics *ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self);
-void ide_clang_translation_unit_code_complete_async (IdeClangTranslationUnit *self,
- GFile *file,
- const GtkTextIter *location,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-GPtrArray *ide_clang_translation_unit_code_complete_finish (IdeClangTranslationUnit *self,
- GAsyncResult *result,
- GError **error);
-IdeHighlightIndex *
- ide_clang_translation_unit_get_index (IdeClangTranslationUnit *self);
-IdeSymbol *ide_clang_translation_unit_lookup_symbol (IdeClangTranslationUnit *self,
- IdeSourceLocation *location,
- GError **error);
-GPtrArray *ide_clang_translation_unit_get_symbols (IdeClangTranslationUnit *self,
- IdeFile *file);
+gint64 ide_clang_translation_unit_get_sequence (IdeClangTranslationUnit *self);
+IdeDiagnostics *ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self);
+IdeDiagnostics *ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *self,
+ GFile *file);
+void ide_clang_translation_unit_code_complete_async (IdeClangTranslationUnit *self,
+ GFile *file,
+ const GtkTextIter *location,
+ GCancellable
*cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GPtrArray *ide_clang_translation_unit_code_complete_finish (IdeClangTranslationUnit *self,
+ GAsyncResult *result,
+ GError **error);
+IdeHighlightIndex *ide_clang_translation_unit_get_index (IdeClangTranslationUnit *self);
+IdeSymbol *ide_clang_translation_unit_lookup_symbol (IdeClangTranslationUnit *self,
+ IdeSourceLocation *location,
+ GError **error);
+GPtrArray *ide_clang_translation_unit_get_symbols (IdeClangTranslationUnit *self,
+ IdeFile *file);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]