[gnome-builder] libide: add ide_diagnostic_get_text_for_display()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add ide_diagnostic_get_text_for_display()
- Date: Mon, 23 Mar 2015 23:43:29 +0000 (UTC)
commit cf7ba719362c0946fbd3b6a3d58b32368c131cdd
Author: Christian Hergert <christian hergert me>
Date: Wed Feb 25 19:13:59 2015 -0800
libide: add ide_diagnostic_get_text_for_display()
This helper will return a formatted string suitable for display. It
includes various information about the diagnostic including its location,
severity, and message text.
This is suitable for use as a tooltip.
libide/ide-diagnostic.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-diagnostic.c b/libide/ide-diagnostic.c
index b385afd..b09803b 100644
--- a/libide/ide-diagnostic.c
+++ b/libide/ide-diagnostic.c
@@ -74,6 +74,37 @@ ide_diagnostic_get_text (IdeDiagnostic *self)
return self->text;
}
+/**
+ * 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);
+}
+
guint
ide_diagnostic_get_num_ranges (IdeDiagnostic *self)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]