[gnome-builder/wip/chergert/clang] clang: add IPC wrapper for getting highlight index



commit c36bcc83fdad07133c919179d072e7ecf4617d31
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 25 13:50:26 2018 -0700

    clang: add IPC wrapper for getting highlight index

 src/plugins/clang/ide-clang-client.c | 77 ++++++++++++++++++++++++++++++++++++
 src/plugins/clang/ide-clang-client.h |  9 +++++
 2 files changed, 86 insertions(+)
---
diff --git a/src/plugins/clang/ide-clang-client.c b/src/plugins/clang/ide-clang-client.c
index 60cb0c0a8..3ce782cab 100644
--- a/src/plugins/clang/ide-clang-client.c
+++ b/src/plugins/clang/ide-clang-client.c
@@ -948,3 +948,80 @@ ide_clang_client_diagnose_finish (IdeClangClient  *self,
 
   return ide_task_propagate_pointer (IDE_TASK (result), error);
 }
+
+static void
+ide_clang_client_get_highlight_index_cb (GObject      *object,
+                                         GAsyncResult *result,
+                                         gpointer      user_data)
+{
+  IdeClangClient *self = (IdeClangClient *)object;
+  g_autoptr(GVariant) reply = NULL;
+  g_autoptr(IdeTask) task = user_data;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_CLANG_CLIENT (self));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_TASK (task));
+
+  if (!ide_clang_client_call_finish (self, result, &reply, &error))
+    ide_task_return_error (task, g_steal_pointer (&error));
+  else
+    ide_task_return_pointer (task,
+                             ide_highlight_index_new_from_variant (reply),
+                             (GDestroyNotify)ide_highlight_index_unref);
+}
+
+void
+ide_clang_client_get_highlight_index_async (IdeClangClient      *self,
+                                            GFile               *file,
+                                            const gchar * const *flags,
+                                            GCancellable        *cancellable,
+                                            GAsyncReadyCallback  callback,
+                                            gpointer             user_data)
+{
+  g_autoptr(IdeTask) task = NULL;
+  g_autoptr(GVariant) params = NULL;
+  g_autofree gchar *path = NULL;
+
+  g_return_if_fail (IDE_IS_CLANG_CLIENT (self));
+  g_return_if_fail (G_IS_FILE (file));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = ide_task_new (self, cancellable, callback, user_data);
+  ide_task_set_source_tag (task, ide_clang_client_get_highlight_index_async);
+  ide_task_set_kind (task, IDE_TASK_KIND_COMPILER);
+
+  if (!g_file_is_native (file))
+    {
+      ide_task_return_new_error (task,
+                                 G_IO_ERROR,
+                                 G_IO_ERROR_NOT_SUPPORTED,
+                                 "File must be a local file");
+      return;
+    }
+
+  path = g_file_get_path (file);
+
+  params = JSONRPC_MESSAGE_NEW (
+    "path", JSONRPC_MESSAGE_PUT_STRING (path),
+    "flags", JSONRPC_MESSAGE_PUT_STRV (flags)
+  );
+
+  ide_clang_client_call_async (self,
+                               "clang/getHighlightIndex",
+                               params,
+                               cancellable,
+                               ide_clang_client_get_highlight_index_cb,
+                               g_steal_pointer (&task));
+}
+
+IdeHighlightIndex *
+ide_clang_client_get_highlight_index_finish (IdeClangClient  *self,
+                                             GAsyncResult    *result,
+                                             GError         **error)
+{
+  g_return_val_if_fail (IDE_IS_CLANG_CLIENT (self), NULL);
+  g_return_val_if_fail (IDE_IS_TASK (result), NULL);
+
+  return ide_task_propagate_pointer (IDE_TASK (result), error);
+}
diff --git a/src/plugins/clang/ide-clang-client.h b/src/plugins/clang/ide-clang-client.h
index 2cdd74a85..50f7f9628 100644
--- a/src/plugins/clang/ide-clang-client.h
+++ b/src/plugins/clang/ide-clang-client.h
@@ -96,5 +96,14 @@ void            ide_clang_client_diagnose_async            (IdeClangClient
 IdeDiagnostics *ide_clang_client_diagnose_finish           (IdeClangClient       *self,
                                                             GAsyncResult         *result,
                                                             GError              **error);
+void               ide_clang_client_get_highlight_index_async  (IdeClangClient       *self,
+                                                                GFile                *file,
+                                                                const gchar * const  *flags,
+                                                                GCancellable         *cancellable,
+                                                                GAsyncReadyCallback   callback,
+                                                                gpointer              user_data);
+IdeHighlightIndex *ide_clang_client_get_highlight_index_finish (IdeClangClient       *self,
+                                                                GAsyncResult         *result,
+                                                                GError              **error);
 
 G_END_DECLS


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