static void ide_lsp_formatter_format_async (IdeFormatter *formatter, IdeBuffer *buffer, IdeFormatterOptions *options, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdeLspFormatter *self = (IdeLspFormatter *)formatter; IdeLspFormatterPrivate *priv = ide_lsp_formatter_get_instance_private (self); g_autoptr(GVariant) params = NULL; g_autoptr(IdeTask) task = NULL; g_autofree gchar *uri = NULL; g_autofree gchar *text = NULL; GtkTextIter begin; GtkTextIter end; gint64 version; gint tab_size; gboolean insert_spaces; g_assert (IDE_IS_LSP_FORMATTER (self)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); task = ide_task_new (self, cancellable, callback, user_data); ide_task_set_source_tag (task, ide_lsp_formatter_format_async); ide_task_set_task_data (task, g_object_ref (buffer), g_object_unref); gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &begin, &end); gtk_text_iter_order (&begin, &end); version = ide_buffer_get_change_count (buffer); uri = ide_buffer_dup_uri (buffer); text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), &begin, &end, TRUE); tab_size = ide_formatter_options_get_tab_width (options); insert_spaces = ide_formatter_options_get_insert_spaces (options); params = JSONRPC_MESSAGE_NEW ( "textDocument", "{", "uri", JSONRPC_MESSAGE_PUT_STRING (uri), "text", JSONRPC_MESSAGE_PUT_STRING (text), "version", JSONRPC_MESSAGE_PUT_INT64 (version), "}", "options", "{", "tabSize", JSONRPC_MESSAGE_PUT_INT32 (tab_size), "insertSpaces", JSONRPC_MESSAGE_PUT_BOOLEAN (insert_spaces), "}" ); ide_lsp_client_call_async (priv->client, "textDocument/formatting", params, cancellable, ide_lsp_formatter_format_call_cb, g_steal_pointer (&task)); }
static void ide_lsp_formatter_format_range_async (IdeFormatter *formatter, IdeBuffer *buffer, IdeFormatterOptions *options, const GtkTextIter *begin, const GtkTextIter *end, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdeLspFormatter *self = (IdeLspFormatter *)formatter; IdeLspFormatterPrivate *priv = ide_lsp_formatter_get_instance_private (self); g_autoptr(GVariant) params = NULL; g_autoptr(IdeTask) task = NULL; g_autofree gchar *uri = NULL; g_autofree gchar *text = NULL; gint64 version; gint tab_size; gboolean insert_spaces; struct { gint line; gint character; } b, e; g_assert (IDE_IS_LSP_FORMATTER (self)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); task = ide_task_new (self, cancellable, callback, user_data); ide_task_set_source_tag (task, ide_lsp_formatter_format_async); ide_task_set_task_data (task, g_object_ref (buffer), g_object_unref); if (gtk_text_iter_compare (begin, end) > 0) { const GtkTextIter *tmp = end; end = begin; begin = tmp; } version = ide_buffer_get_change_count (buffer); uri = ide_buffer_dup_uri (buffer); text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), begin, end, TRUE); tab_size = ide_formatter_options_get_tab_width (options); insert_spaces = ide_formatter_options_get_insert_spaces (options); b.line = gtk_text_iter_get_line (begin); b.character = gtk_text_iter_get_line_offset (begin); e.line = gtk_text_iter_get_line (end); e.character = gtk_text_iter_get_line_offset (begin); params = JSONRPC_MESSAGE_NEW ( "textDocument", "{", "uri", JSONRPC_MESSAGE_PUT_STRING (uri), "text", JSONRPC_MESSAGE_PUT_STRING (text), "version", JSONRPC_MESSAGE_PUT_INT64 (version), "}", "options", "{", "tabSize", JSONRPC_MESSAGE_PUT_INT32 (tab_size), "insertSpaces", JSONRPC_MESSAGE_PUT_BOOLEAN (insert_spaces), "}", "range", "{", "start", "{", "line", JSONRPC_MESSAGE_PUT_INT32 (b.line), "character", JSONRPC_MESSAGE_PUT_INT32 (b.character), "}", "end", "{", "line", JSONRPC_MESSAGE_PUT_INT32 (e.line), "character", JSONRPC_MESSAGE_PUT_INT32 (e.character), "}", "}" ); ide_lsp_client_call_async (priv->client, "textDocument/rangeFormatting", params, cancellable, ide_lsp_formatter_format_call_cb, g_steal_pointer (&task)); }
static void ide_langserv_symbol_resolver_find_references_async (IdeSymbolResolver *resolver, IdeSourceLocation *location, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdeLangservSymbolResolver *self = (IdeLangservSymbolResolver *)resolver; IdeLangservSymbolResolverPrivate *priv = ide_langserv_symbol_resolver_get_instance_private (self); g_autoptr(GTask) task = NULL; g_autoptr(GVariant) params = NULL; g_autofree gchar *uri = NULL; const gchar *language_id; IdeFile *file; GFile *gfile; guint line; guint line_offset; IDE_ENTRY; g_assert (IDE_IS_LANGSERV_SYMBOL_RESOLVER (self)); g_assert (location != NULL); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); task = g_task_new (self, cancellable, callback, user_data); g_task_set_source_tag (task, ide_langserv_symbol_resolver_find_references_async); file = ide_source_location_get_file (location); gfile = ide_file_get_file (file); uri = g_file_get_uri (gfile); line = ide_source_location_get_line (location); line_offset = ide_source_location_get_line_offset (location); language_id = ide_file_get_language_id (file); if (language_id == NULL) language_id = "plain"; params = JSONRPC_MESSAGE_NEW ( "textDocument", "{", "uri", JSONRPC_MESSAGE_PUT_STRING (uri), "languageId", JSONRPC_MESSAGE_PUT_STRING (language_id), "}", "position", "{", "line", JSONRPC_MESSAGE_PUT_INT32 (line), "character", JSONRPC_MESSAGE_PUT_INT32 (line_offset), "}", "context", "{", "includeDeclaration", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE), "}" ); ide_langserv_client_call_async (priv->client, "textDocument/references", g_steal_pointer (¶ms), cancellable, ide_langserv_symbol_resolver_find_references_cb, g_steal_pointer (&task)); IDE_EXIT; }