[gnome-builder] clang: port find-nearest-scope to use IdeClangClient
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] clang: port find-nearest-scope to use IdeClangClient
- Date: Wed, 2 May 2018 21:17:14 +0000 (UTC)
commit ee14f4af8488ef41805d80da433d605d27877eda
Author: Christian Hergert <chergert redhat com>
Date: Tue Apr 24 16:32:45 2018 -0700
clang: port find-nearest-scope to use IdeClangClient
src/plugins/clang/ide-clang-client.c | 93 +++++++++++++++++++++++++++
src/plugins/clang/ide-clang-client.h | 71 +++++++++++---------
src/plugins/clang/ide-clang-symbol-resolver.c | 78 +++++++++++++++-------
3 files changed, 187 insertions(+), 55 deletions(-)
---
diff --git a/src/plugins/clang/ide-clang-client.c b/src/plugins/clang/ide-clang-client.c
index ba0fcd329..7250570a0 100644
--- a/src/plugins/clang/ide-clang-client.c
+++ b/src/plugins/clang/ide-clang-client.c
@@ -585,3 +585,96 @@ ide_clang_client_get_index_key_finish (IdeClangClient *self,
return ide_task_propagate_pointer (IDE_TASK (result), error);
}
+
+static void
+ide_clang_client_find_nearest_scope_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeClangClient *self = (IdeClangClient *)object;
+ g_autoptr(IdeSymbol) ret = NULL;
+ 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));
+ return;
+ }
+
+ ret = ide_symbol_new_from_variant (reply);
+
+ if (ret == NULL)
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_DATA,
+ "Failed to decode symbol from IPC peer");
+ else
+ ide_task_return_pointer (task,
+ g_steal_pointer (&ret),
+ (GDestroyNotify)ide_symbol_unref);
+}
+
+void
+ide_clang_client_find_nearest_scope_async (IdeClangClient *self,
+ GFile *file,
+ const gchar * const *flags,
+ guint line,
+ guint column,
+ 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_find_nearest_scope_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),
+ "line", JSONRPC_MESSAGE_PUT_INT64 (line),
+ "column", JSONRPC_MESSAGE_PUT_INT64 (column)
+ );
+
+ ide_clang_client_call_async (self,
+ "clang/findNearestScope",
+ params,
+ cancellable,
+ ide_clang_client_find_nearest_scope_cb,
+ g_steal_pointer (&task));
+}
+
+IdeSymbol *
+ide_clang_client_find_nearest_scope_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 d2fa8718b..d3533874e 100644
--- a/src/plugins/clang/ide-clang-client.h
+++ b/src/plugins/clang/ide-clang-client.h
@@ -26,35 +26,46 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeClangClient, ide_clang_client, IDE, CLANG_CLIENT, IdeObject)
-void ide_clang_client_call_async (IdeClangClient *self,
- const gchar *method,
- GVariant *params,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean ide_clang_client_call_finish (IdeClangClient *self,
- GAsyncResult *result,
- GVariant **reply,
- GError **error);
-void ide_clang_client_index_file_async (IdeClangClient *self,
- GFile *file,
- const gchar * const *flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-GVariant *ide_clang_client_index_file_finish (IdeClangClient *self,
- GAsyncResult *result,
- GError **error);
-void ide_clang_client_get_index_key_async (IdeClangClient *self,
- GFile *file,
- const gchar * const *flags,
- guint line,
- guint column,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gchar *ide_clang_client_get_index_key_finish (IdeClangClient *self,
- GAsyncResult *result,
- GError **error);
+void ide_clang_client_call_async (IdeClangClient *self,
+ const gchar *method,
+ GVariant *params,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean ide_clang_client_call_finish (IdeClangClient *self,
+ GAsyncResult *result,
+ GVariant **reply,
+ GError **error);
+void ide_clang_client_index_file_async (IdeClangClient *self,
+ GFile *file,
+ const gchar * const *flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GVariant *ide_clang_client_index_file_finish (IdeClangClient *self,
+ GAsyncResult *result,
+ GError **error);
+void ide_clang_client_get_index_key_async (IdeClangClient *self,
+ GFile *file,
+ const gchar * const *flags,
+ guint line,
+ guint column,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gchar *ide_clang_client_get_index_key_finish (IdeClangClient *self,
+ GAsyncResult *result,
+ GError **error);
+void ide_clang_client_find_nearest_scope_async (IdeClangClient *self,
+ GFile *file,
+ const gchar * const *flags,
+ guint line,
+ guint column,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+IdeSymbol *ide_clang_client_find_nearest_scope_finish (IdeClangClient *self,
+ GAsyncResult *result,
+ GError **error);
G_END_DECLS
diff --git a/src/plugins/clang/ide-clang-symbol-resolver.c b/src/plugins/clang/ide-clang-symbol-resolver.c
index be9172f33..c182d1cca 100644
--- a/src/plugins/clang/ide-clang-symbol-resolver.c
+++ b/src/plugins/clang/ide-clang-symbol-resolver.c
@@ -18,6 +18,7 @@
#define G_LOG_DOMAIN "clang-symbol-resolver"
+#include "ide-clang-client.h"
#include "ide-clang-service.h"
#include "ide-clang-symbol-resolver.h"
@@ -239,34 +240,62 @@ ide_clang_symbol_resolver_find_scope_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- IdeClangService *service = (IdeClangService *)object;
- g_autoptr(IdeClangTranslationUnit) unit = NULL;
+ IdeClangClient *client = (IdeClangClient *)object;
g_autoptr(IdeTask) task = user_data;
g_autoptr(IdeSymbol) symbol = NULL;
g_autoptr(GError) error = NULL;
- IdeSourceLocation *location;
- g_assert (IDE_IS_CLANG_SERVICE (service));
+ g_assert (IDE_IS_CLANG_CLIENT (client));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (IDE_IS_TASK (task));
- unit = ide_clang_service_get_translation_unit_finish (service, result, &error);
-
- if (unit == NULL)
- {
- ide_task_return_error (task, g_steal_pointer (&error));
- return;
- }
-
- location = ide_task_get_task_data (task);
- symbol = ide_clang_translation_unit_find_nearest_scope (unit, location, &error);
-
- if (symbol == NULL)
+ if (!(symbol = ide_clang_client_find_nearest_scope_finish (client, result, &error)))
ide_task_return_error (task, g_steal_pointer (&error));
else
ide_task_return_pointer (task,
g_steal_pointer (&symbol),
- (GDestroyNotify) ide_symbol_unref);
+ (GDestroyNotify)ide_symbol_unref);
+}
+
+static void
+find_nearest_scope_flags_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeBuildSystem *build_system = (IdeBuildSystem *)object;
+ g_autoptr(IdeTask) task = user_data;
+ g_auto(GStrv) flags = NULL;
+ IdeSourceLocation *location;
+ IdeClangClient *client;
+ GCancellable *cancellable;
+ IdeContext *context;
+ IdeFile *file;
+ GFile *gfile;
+ guint line;
+ guint column;
+
+ g_assert (IDE_IS_BUILD_SYSTEM (build_system));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_TASK (task));
+
+ flags = ide_build_system_get_build_flags_finish (build_system, result, NULL);
+ context = ide_object_get_context (IDE_OBJECT (build_system));
+ client = ide_context_get_service_typed (context, IDE_TYPE_CLANG_CLIENT);
+ cancellable = ide_task_get_cancellable (task);
+ location = ide_task_get_task_data (task);
+ file = ide_source_location_get_file (location);
+ gfile = ide_file_get_file (file);
+ line = ide_source_location_get_line (location);
+ column = ide_source_location_get_line_offset (location);
+
+ ide_clang_client_find_nearest_scope_async (client,
+ gfile,
+ (const gchar * const *)flags,
+ line + 1,
+ column + 1,
+ cancellable,
+ ide_clang_symbol_resolver_find_scope_cb,
+ g_steal_pointer (&task));
}
static void
@@ -278,7 +307,7 @@ ide_clang_symbol_resolver_find_nearest_scope_async (IdeSymbolResolver *symbol_
{
IdeClangSymbolResolver *self = (IdeClangSymbolResolver *)symbol_resolver;
g_autoptr(IdeTask) task = NULL;
- IdeClangService *service;
+ IdeBuildSystem *build_system;
IdeContext *context;
IdeFile *file;
@@ -295,15 +324,14 @@ ide_clang_symbol_resolver_find_nearest_scope_async (IdeSymbolResolver *symbol_
(GDestroyNotify) ide_source_location_unref);
context = ide_object_get_context (IDE_OBJECT (self));
- service = ide_context_get_service_typed (context, IDE_TYPE_CLANG_SERVICE);
+ build_system = ide_context_get_build_system (context);
file = ide_source_location_get_file (location);
- ide_clang_service_get_translation_unit_async (service,
- file,
- 0,
- cancellable,
- ide_clang_symbol_resolver_find_scope_cb,
- g_steal_pointer (&task));
+ ide_build_system_get_build_flags_async (build_system,
+ file,
+ cancellable,
+ find_nearest_scope_flags_cb,
+ g_steal_pointer (&task));
IDE_EXIT;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]