[gnome-builder] langserv-client: propagate buffer changes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] langserv-client: propagate buffer changes
- Date: Tue, 25 Oct 2016 22:42:11 +0000 (UTC)
commit 2b95a6a9df60e6783a7be52756576ff4f4db0220
Author: Christian Hergert <chergert redhat com>
Date: Sun Oct 23 23:24:25 2016 -0700
langserv-client: propagate buffer changes
This still needs a bunch of work. We probably want to build a piece table
to track changes (possibly even application-wide) and then coalesce updates
over a time period.
Additionally, we will want to limit changes to files that are appropriate
to the language server.
libide/langserv/ide-langserv-client.c | 126 +++++++++++++++++++++++++++++++++
1 files changed, 126 insertions(+), 0 deletions(-)
---
diff --git a/libide/langserv/ide-langserv-client.c b/libide/langserv/ide-langserv-client.c
index ae0f289..dfea0c3 100644
--- a/libide/langserv/ide-langserv-client.c
+++ b/libide/langserv/ide-langserv-client.c
@@ -127,6 +127,120 @@ ide_langserv_client_buffer_saved (IdeLangservClient *self,
IDE_EXIT;
}
+/*
+ * TODO: This should all be delayed and buffered so we coalesce multiple
+ * events into a single dispatch.
+ */
+
+static void
+ide_langserv_client_buffer_insert_text (IdeLangservClient *self,
+ GtkTextIter *location,
+ const gchar *new_text,
+ gint len,
+ IdeBuffer *buffer)
+{
+ g_autoptr(JsonNode) params = NULL;
+ g_autofree gchar *uri = NULL;
+ gint line;
+ gint column;
+ gint version;
+
+ g_assert (IDE_IS_LANGSERV_CLIENT (self));
+ g_assert (location != NULL);
+ g_assert (IDE_IS_BUFFER (buffer));
+
+ uri = ide_buffer_get_uri (buffer);
+ version = (gint)ide_buffer_get_change_count (buffer);
+
+ line = gtk_text_iter_get_line (location);
+ column = gtk_text_iter_get_line_offset (location);
+
+ params = JCON_NEW (
+ "textDocument", "{",
+ "uri", JCON_STRING (uri),
+ "version", JCON_INT (version),
+ "}",
+ "contentChanges", "[",
+ "{",
+ "range", "{",
+ "start", "{",
+ "line", JCON_INT (line),
+ "character", JCON_INT (column),
+ "}",
+ "end", "{",
+ "line", JCON_INT (line),
+ "character", JCON_INT (column),
+ "}",
+ "}",
+ "rangeLength", JCON_INT (0),
+ "text", JCON_STRING (new_text),
+ "}",
+ "]");
+
+ ide_langserv_client_notification_async (self, "textDocument/didChange",
+ g_steal_pointer (¶ms),
+ NULL, NULL, NULL);
+}
+
+static void
+ide_langserv_client_buffer_delete_range (IdeLangservClient *self,
+ GtkTextIter *begin_iter,
+ GtkTextIter *end_iter,
+ IdeBuffer *buffer)
+{
+
+ g_autoptr(JsonNode) params = NULL;
+ g_autofree gchar *uri = NULL;
+ struct {
+ gint line;
+ gint column;
+ } begin, end;
+ gint version;
+ gint length;
+
+ g_assert (IDE_IS_LANGSERV_CLIENT (self));
+ g_assert (begin_iter != NULL);
+ g_assert (end_iter != NULL);
+ g_assert (IDE_IS_BUFFER (buffer));
+
+ uri = ide_buffer_get_uri (buffer);
+ version = (gint)ide_buffer_get_change_count (buffer);
+
+ begin.line = gtk_text_iter_get_line (begin_iter);
+ begin.column = gtk_text_iter_get_line_offset (begin_iter);
+
+ end.line = gtk_text_iter_get_line (end_iter);
+ end.column = gtk_text_iter_get_line_offset (end_iter);
+
+ length = gtk_text_iter_get_offset (end_iter) - gtk_text_iter_get_offset (begin_iter);
+
+ params = JCON_NEW (
+ "textDocument", "{",
+ "uri", JCON_STRING (uri),
+ "version", JCON_INT (version),
+ "}",
+ "contentChanges", "[",
+ "{",
+ "range", "{",
+ "start", "{",
+ "line", JCON_INT (begin.line),
+ "character", JCON_INT (begin.column),
+ "}",
+ "end", "{",
+ "line", JCON_INT (end.line),
+ "character", JCON_INT (end.column),
+ "}",
+ "}",
+ "rangeLength", JCON_INT (length),
+ "text", "",
+ "}",
+ "]");
+
+ ide_langserv_client_notification_async (self, "textDocument/didChange",
+ g_steal_pointer (¶ms),
+ NULL, NULL, NULL);
+}
+
static void
ide_langserv_client_buffer_loaded (IdeLangservClient *self,
IdeBuffer *buffer,
@@ -142,6 +256,18 @@ ide_langserv_client_buffer_loaded (IdeLangservClient *self,
g_assert (IDE_IS_BUFFER (buffer));
g_assert (IDE_IS_BUFFER_MANAGER (buffer_manager));
+ g_signal_connect_object (buffer,
+ "insert-text",
+ G_CALLBACK (ide_langserv_client_buffer_insert_text),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (buffer,
+ "delete-range",
+ G_CALLBACK (ide_langserv_client_buffer_delete_range),
+ self,
+ G_CONNECT_SWAPPED);
+
uri = ide_buffer_get_uri (buffer);
params = JCON_NEW (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]