[gnome-builder] clang: add initialize operation to set workdir
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] clang: add initialize operation to set workdir
- Date: Fri, 20 Apr 2018 10:47:14 +0000 (UTC)
commit 9419c53109a623c7ec959a3ba95380bab2aa1f66
Author: Christian Hergert <chergert redhat com>
Date: Fri Apr 20 03:47:25 2018 -0700
clang: add initialize operation to set workdir
We'll need this to do diagnostic creation, so add an initialize operation
that matches language server.
src/plugins/clang/gnome-builder-clang.c | 36 ++++++++++++++++++++++++++++
src/plugins/clang/ide-clang.c | 26 +++++++++++++++++++-
src/plugins/clang/ide-clang.h | 2 ++
src/plugins/clang/test-daemon.c | 42 +++++++++++++++++++++++++++++++++
4 files changed, 105 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/clang/gnome-builder-clang.c b/src/plugins/clang/gnome-builder-clang.c
index 4d91a771d..5620aa10a 100644
--- a/src/plugins/clang/gnome-builder-clang.c
+++ b/src/plugins/clang/gnome-builder-clang.c
@@ -316,6 +316,37 @@ handle_diagnose (JsonrpcServer *server,
client_op_ref (op));
}
+/* Initialize {{{1 */
+
+static void
+handle_initialize (JsonrpcServer *server,
+ JsonrpcClient *client,
+ const gchar *method,
+ GVariant *id,
+ GVariant *params,
+ IdeClang *clang)
+{
+ g_autoptr(ClientOp) op = NULL;
+ const gchar *uri = NULL;
+
+ g_assert (JSONRPC_IS_SERVER (server));
+ g_assert (JSONRPC_IS_CLIENT (client));
+ g_assert (g_str_equal (method, "initialize"));
+ g_assert (id != NULL);
+ g_assert (IDE_IS_CLANG (clang));
+
+ op = client_op_new (client, id);
+
+ if (JSONRPC_MESSAGE_PARSE (params, "rootUri", JSONRPC_MESSAGE_GET_STRING (&uri)))
+ {
+ g_autoptr(GFile) file = g_file_new_for_uri (uri);
+
+ ide_clang_set_workdir (clang, file);
+ }
+
+ client_op_reply (op, NULL);
+}
+
/* Main and Server Setup {{{1 */
static void
@@ -372,6 +403,11 @@ main (gint argc,
G_CALLBACK (on_client_closed_cb),
NULL);
+ jsonrpc_server_add_handler (server,
+ "initialize",
+ (JsonrpcServerHandler)handle_initialize,
+ g_object_ref (clang),
+ g_object_unref);
jsonrpc_server_add_handler (server,
"clang/indexFile",
(JsonrpcServerHandler)handle_index_file,
diff --git a/src/plugins/clang/ide-clang.c b/src/plugins/clang/ide-clang.c
index cf7014907..af8f466ca 100644
--- a/src/plugins/clang/ide-clang.c
+++ b/src/plugins/clang/ide-clang.c
@@ -27,7 +27,8 @@
struct _IdeClang
{
- GObject parent;
+ GObject parent;
+ GFile *workdir;
};
G_DEFINE_TYPE (IdeClang, ide_clang, G_TYPE_OBJECT)
@@ -84,9 +85,22 @@ ide_clang_cook_flags (const gchar * const *flags)
return (gchar **)g_ptr_array_free (cooked, FALSE);
}
+static void
+ide_clang_finalize (GObject *object)
+{
+ IdeClang *self = (IdeClang *)object;
+
+ g_clear_object (&self->workdir);
+
+ G_OBJECT_CLASS (ide_clang_parent_class)->finalize (object);
+}
+
static void
ide_clang_class_init (IdeClangClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ide_clang_finalize;
}
static void
@@ -100,6 +114,16 @@ ide_clang_new (void)
return g_object_new (IDE_TYPE_CLANG, NULL);
}
+void
+ide_clang_set_workdir (IdeClang *self,
+ GFile *workdir)
+{
+ g_return_if_fail (IDE_IS_CLANG (self));
+ g_return_if_fail (!workdir || G_IS_FILE (workdir));
+
+ g_set_object (&self->workdir, workdir);
+}
+
/* Index File {{{1 */
typedef struct
diff --git a/src/plugins/clang/ide-clang.h b/src/plugins/clang/ide-clang.h
index 739be0114..d30e7f6be 100644
--- a/src/plugins/clang/ide-clang.h
+++ b/src/plugins/clang/ide-clang.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeClang, ide_clang, IDE, CLANG, GObject)
IdeClang *ide_clang_new (void);
+void ide_clang_set_workdir (IdeClang *self,
+ GFile *workdir);
void ide_clang_index_file_async (IdeClang *self,
const gchar *path,
const gchar * const *argv,
diff --git a/src/plugins/clang/test-daemon.c b/src/plugins/clang/test-daemon.c
index d9b3b54a0..5285e2687 100644
--- a/src/plugins/clang/test-daemon.c
+++ b/src/plugins/clang/test-daemon.c
@@ -8,6 +8,8 @@ typedef void (*TestFunc) (JsonrpcClient *client,
GTask *task);
static void tick_tests (JsonrpcClient *client);
+static void test_initialize (JsonrpcClient *client,
+ GTask *task);
static void test_diagnose (JsonrpcClient *client,
GTask *task);
static void test_index_file (JsonrpcClient *client,
@@ -17,6 +19,7 @@ static gchar **flags;
static const gchar *path;
static GMainLoop *main_loop;
static TestFunc test_funcs[] = {
+ test_initialize,
test_diagnose,
test_index_file,
};
@@ -99,6 +102,45 @@ test_diagnose (JsonrpcClient *client,
g_object_ref (task));
}
+static void
+test_initialize_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ JsonrpcClient *client = (JsonrpcClient *)object;
+ g_autoptr(GTask) task = user_data;
+ g_autoptr(GVariant) reply = NULL;
+ g_autoptr(GError) error = NULL;
+
+ g_assert (G_IS_TASK (task));
+
+ if (!jsonrpc_client_call_finish (client, result, &reply, &error))
+ g_error ("initialize: %s", error->message);
+
+ g_printerr ("initialize: %s\n", g_variant_print (reply, TRUE));
+
+ g_task_return_boolean (task, TRUE);
+}
+
+static void
+test_initialize (JsonrpcClient *client,
+ GTask *task)
+{
+ g_autoptr(GVariant) params = NULL;
+ g_autofree gchar *root = NULL;
+
+ root = g_path_get_dirname (path);
+
+ params = JSONRPC_MESSAGE_NEW ("rootUri", JSONRPC_MESSAGE_PUT_STRING (root));
+
+ jsonrpc_client_call_async (client,
+ "initialize",
+ params,
+ NULL,
+ test_initialize_cb,
+ g_object_ref (task));
+}
+
static void
finished_cb (GObject *object,
GAsyncResult *result,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]