/** * ide_diagnostic_get_text_for_display: * * This creates a new string that is formatted using the diagnostics line number, column, severity, * and message text in the format "line:column: severity: message". * * This can be convenient when wanting to quickly display a diagnostic such as in a tooltip. * * Returns: (transfer full): A string containing the text formatted for display. */ gchar * ide_diagnostic_get_text_for_display (IdeDiagnostic *self) { IdeSourceLocation *location; const gchar *severity; guint line = 0; guint column = 0; g_return_val_if_fail (self, NULL); severity = ide_diagnostic_severity_to_string (self->severity); location = ide_diagnostic_get_location (self); if (location) { line = ide_source_location_get_line (location) + 1; column = ide_source_location_get_line_offset (location) + 1; } return g_strdup_printf ("%u:%u: %s: %s", line, column, severity, self->text); }
static void gb_editor_view_navigate_to (GbView *view, IdeSourceLocation *location) { GbEditorView *self = (GbEditorView *)view; GbEditorFrame *frame; GtkTextMark *insert; GtkTextBuffer *buffer; GtkTextIter iter; guint line; guint line_offset; IDE_ENTRY; g_assert (GB_IS_EDITOR_VIEW (self)); g_assert (location != NULL); frame = gb_editor_view_get_last_focused (self); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->source_view)); line = ide_source_location_get_line (location); line_offset = ide_source_location_get_line_offset (location); gtk_text_buffer_get_iter_at_line (buffer, &iter, line); for (; line_offset; line_offset--) if (gtk_text_iter_ends_line (&iter) || !gtk_text_iter_forward_char (&iter)) break; gtk_text_buffer_select_range (buffer, &iter, &iter); insert = gtk_text_buffer_get_insert (buffer); gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (frame->source_view), insert, 0.0, TRUE, 1.0, 0.5); g_signal_emit_by_name (frame->source_view, "save-insert-mark"); IDE_EXIT; }
static void ide_editor_perspective_focus_location_full (IdeEditorPerspective *self, IdeSourceLocation *location, gboolean open_if_not_found) { struct { IdeFile *file; IdeEditorView *view; } lookup = { 0 }; GtkWidget *stack; guint line; guint line_offset; IDE_ENTRY; g_assert (IDE_IS_EDITOR_PERSPECTIVE (self)); g_assert (location != NULL); lookup.file = ide_source_location_get_file (location); lookup.view = NULL; if (lookup.file == NULL) { g_warning ("IdeSourceLocation does not contain a file"); IDE_EXIT; } #ifdef IDE_ENABLE_TRACE { const gchar *path = ide_file_get_path (lookup.file); IDE_TRACE_MSG ("Locating %s, open_if_not_found=%d", path, open_if_not_found); } #endif ide_perspective_views_foreach (IDE_PERSPECTIVE (self), ide_editor_perspective_find_source_location, &lookup); if (!open_if_not_found && lookup.view == NULL) IDE_EXIT; if (lookup.view == NULL) { FocusLocation *state; IdeBufferManager *bufmgr; IdeWorkbench *workbench; IdeContext *context; workbench = ide_widget_get_workbench (GTK_WIDGET (self)); context = ide_workbench_get_context (workbench); bufmgr = ide_context_get_buffer_manager (context); state = g_slice_new0 (FocusLocation); state->self = g_object_ref (self); state->location = ide_source_location_ref (location); ide_buffer_manager_load_file_async (bufmgr, lookup.file, FALSE, IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, ide_editor_perspective_focus_location_cb, state); IDE_EXIT; } line = ide_source_location_get_line (location); line_offset = ide_source_location_get_line_offset (location); stack = gtk_widget_get_ancestor (GTK_WIDGET (lookup.view), IDE_TYPE_LAYOUT_STACK); ide_layout_stack_set_visible_child (IDE_LAYOUT_STACK (stack), IDE_LAYOUT_VIEW (lookup.view)); ide_editor_view_scroll_to_line_offset (lookup.view, line, line_offset); IDE_EXIT; }
static void ide_langserv_rename_provider_rename_async (IdeRenameProvider *provider, IdeSourceLocation *location, const gchar *new_name, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdeLangservRenameProvider *self = (IdeLangservRenameProvider *)provider; IdeLangservRenameProviderPrivate *priv = ide_langserv_rename_provider_get_instance_private (self); g_autoptr(GTask) task = NULL; g_autoptr(JsonNode) params = NULL; g_autofree gchar *uri = NULL; IdeFile *ifile; GFile *gfile; gint line; gint column; IDE_ENTRY; g_assert (IDE_IS_LANGSERV_RENAME_PROVIDER (self)); g_assert (location != NULL); g_assert (new_name != 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_rename_provider_rename_async); if (priv->client == NULL) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED, "No client set, cannot rename symbol"); IDE_EXIT; } ifile = ide_source_location_get_file (location); gfile = ide_file_get_file (ifile); uri = g_file_get_uri (gfile); line = ide_source_location_get_line (location); column = ide_source_location_get_line_offset (location); params = JCON_NEW ( "textDocument", "{", "uri", JCON_STRING (uri), "}", "position", "{", "line", JCON_INT (line), "character", JCON_INT (column), "}", "newName", JCON_STRING (new_name) ); ide_langserv_client_call_async (priv->client, "textDocument/rename", g_steal_pointer (¶ms), cancellable, ide_langserv_rename_provider_rename_cb, g_steal_pointer (&task)); 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; }