[gnome-builder/wip/libide: 109/153] libide: stub basics for clang diagnostic provider
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide: 109/153] libide: stub basics for clang diagnostic provider
- Date: Fri, 13 Feb 2015 20:09:20 +0000 (UTC)
commit d69264b0932ee2b4efa958c3d4f7a24f986a7355
Author: Christian Hergert <christian hergert me>
Date: Wed Feb 11 21:48:02 2015 -0800
libide: stub basics for clang diagnostic provider
libide/clang/ide-clang-diagnostic-provider.c | 106 ++++++++++++++-----------
libide/clang/ide-clang-translation-unit.c | 28 ++++++-
libide/clang/ide-clang-translation-unit.h | 3 +-
3 files changed, 87 insertions(+), 50 deletions(-)
---
diff --git a/libide/clang/ide-clang-diagnostic-provider.c b/libide/clang/ide-clang-diagnostic-provider.c
index 24af295..8d0b10a 100644
--- a/libide/clang/ide-clang-diagnostic-provider.c
+++ b/libide/clang/ide-clang-diagnostic-provider.c
@@ -20,76 +20,88 @@
#include "ide-clang-diagnostic-provider.h"
#include "ide-clang-service.h"
+#include "ide-clang-translation-unit.h"
+#include "ide-context.h"
+#include "ide-diagnostics.h"
-typedef struct
+G_DEFINE_TYPE (IdeClangDiagnosticProvider, ide_clang_diagnostic_provider,
+ IDE_TYPE_DIAGNOSTIC_PROVIDER)
+
+static void
+get_translation_unit_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
{
- void *foo;
-} IdeClangDiagnosticProviderPrivate;
+ IdeClangService *service = (IdeClangService *)object;
+ g_autoptr(IdeClangTranslationUnit) tu = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GTask) task = user_data;
+ IdeDiagnostics *diagnostics;
-G_DEFINE_TYPE_WITH_PRIVATE (IdeClangDiagnosticProvider,
- ide_clang_diagnostic_provider,
- IDE_TYPE_DIAGNOSTIC_PROVIDER)
+ tu = ide_clang_service_get_translation_unit_finish (service, result, &error);
-enum {
- PROP_0,
- LAST_PROP
-};
+ if (!tu)
+ {
+ g_task_return_error (task, error);
+ return;
+ }
-static GParamSpec *gParamSpecs [LAST_PROP];
+ diagnostics = ide_clang_translation_unit_get_diagnostics (tu);
-IdeClangDiagnosticProvider *
-ide_clang_diagnostic_provider_new (void)
-{
- return g_object_new (IDE_TYPE_CLANG_DIAGNOSTIC_PROVIDER, NULL);
+ g_task_return_pointer (task,
+ ide_diagnostics_ref (diagnostics),
+ (GDestroyNotify)ide_diagnostics_unref);
}
static void
-ide_clang_diagnostic_provider_finalize (GObject *object)
+ide_clang_diagnostic_provider_diagnose_async (IdeDiagnosticProvider *provider,
+ IdeFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- IdeClangDiagnosticProvider *self = (IdeClangDiagnosticProvider *)object;
- IdeClangDiagnosticProviderPrivate *priv = ide_clang_diagnostic_provider_get_instance_private (self);
+ IdeClangDiagnosticProvider *self = (IdeClangDiagnosticProvider *)provider;
+ g_autoptr(GTask) task = NULL;
+ IdeClangService *service;
+ IdeContext *context;
- G_OBJECT_CLASS (ide_clang_diagnostic_provider_parent_class)->finalize (object);
-}
+ g_return_if_fail (IDE_IS_CLANG_DIAGNOSTIC_PROVIDER (self));
-static void
-ide_clang_diagnostic_provider_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- IdeClangDiagnosticProvider *self = IDE_CLANG_DIAGNOSTIC_PROVIDER (object);
+ task = g_task_new (self, cancellable, callback, user_data);
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ context = ide_object_get_context (IDE_OBJECT (provider));
+ service = ide_context_get_service_typed (context, IDE_TYPE_CLANG_SERVICE);
+
+ ide_clang_service_get_translation_unit_async (service,
+ file,
+ 0,
+ cancellable,
+ get_translation_unit_cb,
+ g_object_ref (task));
}
-static void
-ide_clang_diagnostic_provider_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+static IdeDiagnostics *
+ide_clang_diagnostic_provider_diagnose_finish (IdeDiagnosticProvider *provider,
+ GAsyncResult *result,
+ GError **error)
{
- IdeClangDiagnosticProvider *self = IDE_CLANG_DIAGNOSTIC_PROVIDER (object);
+ IdeClangDiagnosticProvider *self = (IdeClangDiagnosticProvider *)provider;
+ GTask *task = (GTask *)result;
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ g_return_val_if_fail (IDE_IS_CLANG_DIAGNOSTIC_PROVIDER (self), NULL);
+ g_return_val_if_fail (G_IS_TASK (task), NULL);
+
+ return g_task_propagate_pointer (task, error);
}
static void
ide_clang_diagnostic_provider_class_init (IdeClangDiagnosticProviderClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ IdeDiagnosticProviderClass *provider_class;
- object_class->finalize = ide_clang_diagnostic_provider_finalize;
- object_class->get_property = ide_clang_diagnostic_provider_get_property;
- object_class->set_property = ide_clang_diagnostic_provider_set_property;
+ provider_class = IDE_DIAGNOSTIC_PROVIDER_CLASS (klass);
+ provider_class->diagnose_async = ide_clang_diagnostic_provider_diagnose_async;
+ provider_class->diagnose_finish = ide_clang_diagnostic_provider_diagnose_finish;
}
static void
diff --git a/libide/clang/ide-clang-translation-unit.c b/libide/clang/ide-clang-translation-unit.c
index 44f2f4c..c83251b 100644
--- a/libide/clang/ide-clang-translation-unit.c
+++ b/libide/clang/ide-clang-translation-unit.c
@@ -24,8 +24,9 @@
typedef struct
{
- CXTranslationUnit tu;
- gint64 sequence;
+ CXTranslationUnit tu;
+ gint64 sequence;
+ IdeDiagnostics *diagnostics;
} IdeClangTranslationUnitPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (IdeClangTranslationUnit,
@@ -63,6 +64,29 @@ _ide_clang_translation_unit_new (IdeContext *context,
return ret;
}
+/**
+ * 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)
+{
+ IdeClangTranslationUnitPrivate *priv;
+
+ g_return_val_if_fail (IDE_IS_CLANG_TRANSLATION_UNIT (self), NULL);
+
+ priv = ide_clang_translation_unit_get_instance_private (self);
+
+ if (!priv->diagnostics)
+ {
+ }
+
+ return priv->diagnostics;
+}
+
gint64
ide_clang_translation_unit_get_sequence (IdeClangTranslationUnit *self)
{
diff --git a/libide/clang/ide-clang-translation-unit.h b/libide/clang/ide-clang-translation-unit.h
index 73a1834..e55595c 100644
--- a/libide/clang/ide-clang-translation-unit.h
+++ b/libide/clang/ide-clang-translation-unit.h
@@ -32,7 +32,8 @@ struct _IdeClangTranslationUnit
GObject parent_instance;
};
-gint64 ide_clang_translation_unit_get_sequence (IdeClangTranslationUnit *self);
+gint64 ide_clang_translation_unit_get_sequence (IdeClangTranslationUnit *self);
+IdeDiagnostics *ide_clang_translation_unit_get_diagnostics (IdeClangTranslationUnit *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]