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_langserv_symbol_resolver_get_symbol_tree_async (IdeSymbolResolver *resolver, GFile *file, IdeBuffer *buffer, 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; IDE_ENTRY; g_assert (IDE_IS_LANGSERV_SYMBOL_RESOLVER (self)); g_assert (G_IS_FILE (file)); 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_get_symbol_tree_async); if (priv->client == NULL) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "Cannot query language server, not connected"); IDE_EXIT; } uri = g_file_get_uri (file); params = JSONRPC_MESSAGE_NEW ( "textDocument", "{", "uri", JSONRPC_MESSAGE_PUT_STRING (uri), "}" ); ide_langserv_client_call_async (priv->client, "textDocument/documentSymbol", g_steal_pointer (¶ms), cancellable, ide_langserv_symbol_resolver_document_symbol_cb, g_steal_pointer (&task)); IDE_EXIT; }
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_lsp_completion_provider_populate_async (IdeCompletionProvider *provider, IdeCompletionContext *context, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdeLspCompletionProvider *self = (IdeLspCompletionProvider *)provider; IdeLspCompletionProviderPrivate *priv = ide_lsp_completion_provider_get_instance_private (self); g_autoptr(IdeTask) task = NULL; g_autoptr(GVariant) params = NULL; g_autofree gchar *uri = NULL; GtkTextIter iter, end; GtkTextBuffer *buffer; gint line; gint column; IDE_ENTRY; g_assert (IDE_IS_LSP_COMPLETION_PROVIDER (self)); g_assert (IDE_IS_COMPLETION_CONTEXT (context)); task = ide_task_new (self, cancellable, callback, user_data); ide_task_set_source_tag (task, ide_lsp_completion_provider_populate_async); if (priv->client == NULL) { ide_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "No client for completion"); IDE_EXIT; } ide_completion_context_get_bounds (context, &iter, &end); g_clear_pointer (&priv->word, g_free); priv->word = ide_completion_context_get_word (context); buffer = ide_completion_context_get_buffer (context); uri = ide_buffer_dup_uri (IDE_BUFFER (buffer)); line = gtk_text_iter_get_line (&iter); column = gtk_text_iter_get_line_offset (&iter); params = JSONRPC_MESSAGE_NEW ( "textDocument", "{", "uri", JSONRPC_MESSAGE_PUT_STRING (uri), "}", "position", "{", "line", JSONRPC_MESSAGE_PUT_INT32 (line), "character", JSONRPC_MESSAGE_PUT_INT32 (column), "}" ); ide_lsp_client_call_async (priv->client, "textDocument/completion", params, cancellable, ide_lsp_completion_provider_complete_cb, g_steal_pointer (&task)); IDE_EXIT; }
static void ide_langserv_completion_provider_populate (GtkSourceCompletionProvider *provider, GtkSourceCompletionContext *context) { IdeLangservCompletionProvider *self = (IdeLangservCompletionProvider *)provider; IdeLangservCompletionProviderPrivate *priv = ide_langserv_completion_provider_get_instance_private (self); g_autoptr(GVariant) params = NULL; g_autoptr(GCancellable) cancellable = NULL; g_autoptr(CompletionState) state = NULL; g_autofree gchar *uri = NULL; GtkTextIter iter; IdeBuffer *buffer; gint line; gint column; IDE_ENTRY; g_assert (IDE_IS_LANGSERV_COMPLETION_PROVIDER (self)); g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context)); if (priv->client == NULL) { IDE_TRACE_MSG ("No client set, cannot provide proposals"); gtk_source_completion_context_add_proposals (context, provider, NULL, TRUE); IDE_EXIT; } gtk_source_completion_context_get_iter (context, &iter); buffer = IDE_BUFFER (gtk_text_iter_get_buffer (&iter)); uri = ide_buffer_get_uri (buffer); line = gtk_text_iter_get_line (&iter); column = gtk_text_iter_get_line_offset (&iter); params = JSONRPC_MESSAGE_NEW ( "textDocument", "{", "uri", JSONRPC_MESSAGE_PUT_STRING (uri), "}", "position", "{", "line", JSONRPC_MESSAGE_PUT_INT32 (line), "character", JSONRPC_MESSAGE_PUT_INT32 (column), "}" ); cancellable = g_cancellable_new (); g_signal_connect_data (context, "cancelled", G_CALLBACK (g_cancellable_cancel), g_object_ref (cancellable), (GClosureNotify)g_object_unref, G_CONNECT_SWAPPED); state = completion_state_new (self, context); ide_langserv_client_call_async (priv->client, "textDocument/completion", g_steal_pointer (¶ms), g_steal_pointer (&cancellable), ide_langserv_completion_provider_complete_cb, g_steal_pointer (&state)); IDE_EXIT; }
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; }
static void ide_langserv_symbol_resolver_lookup_symbol_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; IdeFile *ifile; GFile *gfile; gint line; gint column; 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_lookup_symbol_async); if (priv->client == NULL) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "%s requires a client to resolve symbols", G_OBJECT_TYPE_NAME (self)); IDE_EXIT; } if (NULL == (ifile = ide_source_location_get_file (location)) || NULL == (gfile = ide_file_get_file (ifile))) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Cannot resolve symbol, invalid source location"); IDE_EXIT; } uri = g_file_get_uri (gfile); line = ide_source_location_get_line (location); column = ide_source_location_get_line_offset (location); params = JSONRPC_MESSAGE_NEW ( "textDocument", "{", "uri", JSONRPC_MESSAGE_PUT_STRING (uri), "}", "position", "{", "line", JSONRPC_MESSAGE_PUT_INT32 (line), "character", JSONRPC_MESSAGE_PUT_INT32 (column), "}" ); ide_langserv_client_call_async (priv->client, "textDocument/definition", g_steal_pointer (¶ms), cancellable, ide_langserv_symbol_resolver_definition_cb, g_steal_pointer (&task)); IDE_EXIT; }