Commit 46edf030 authored by Christian Hergert's avatar Christian Hergert
Browse files

diagnostics: add helpers to compare diagnostics

parent ecb00d0e
......@@ -322,3 +322,24 @@ ide_diagnostic_get_fixit (IdeDiagnostic *self,
return g_ptr_array_index (self->fixits, index);
}
gint
ide_diagnostic_compare (const IdeDiagnostic *a,
const IdeDiagnostic *b)
{
gint ret;
g_assert (a != NULL);
g_assert (b != NULL);
if (0 != (ret = (gint)a->severity - (gint)b->severity))
return ret;
if (a->location && b->location)
{
if (0 != (ret = ide_source_location_compare (a->location, b->location)))
return ret;
}
return g_strcmp0 (a->text, b->text);
}
......@@ -58,6 +58,8 @@ void ide_diagnostic_take_fixit (IdeDiagnostic
IdeFixit *fixit);
void ide_diagnostic_take_range (IdeDiagnostic *self,
IdeSourceRange *range);
gint ide_diagnostic_compare (const IdeDiagnostic *a,
const IdeDiagnostic *b);
const gchar *ide_diagnostic_severity_to_string (IdeDiagnosticSeverity severity);
......
......@@ -190,3 +190,24 @@ ide_source_location_get_uri (IdeSourceLocation *self)
return ret;
}
gint
ide_source_location_compare (const IdeSourceLocation *a,
const IdeSourceLocation *b)
{
gint ret;
g_assert (a != NULL);
g_assert (b != NULL);
if (a->file && b->file)
{
if (0 != (ret = ide_file_compare (a->file, b->file)))
return ret;
}
if (0 != (ret = (gint)a->line - (gint)b->line))
return ret;
return (gint)a->line_offset - (gint)b->line_offset;
}
......@@ -28,17 +28,19 @@ G_BEGIN_DECLS
#define IDE_TYPE_SOURCE_LOCATION (ide_source_location_get_type())
GType ide_source_location_get_type (void);
IdeSourceLocation *ide_source_location_ref (IdeSourceLocation *self);
void ide_source_location_unref (IdeSourceLocation *self);
IdeSourceLocation *ide_source_location_new (IdeFile *file,
guint line,
guint line_offset,
guint offset);
guint ide_source_location_get_line (IdeSourceLocation *self);
guint ide_source_location_get_line_offset (IdeSourceLocation *self);
guint ide_source_location_get_offset (IdeSourceLocation *self);
IdeFile *ide_source_location_get_file (IdeSourceLocation *self);
IdeUri *ide_source_location_get_uri (IdeSourceLocation *self);
IdeSourceLocation *ide_source_location_ref (IdeSourceLocation *self);
void ide_source_location_unref (IdeSourceLocation *self);
IdeSourceLocation *ide_source_location_new (IdeFile *file,
guint line,
guint line_offset,
guint offset);
guint ide_source_location_get_line (IdeSourceLocation *self);
guint ide_source_location_get_line_offset (IdeSourceLocation *self);
guint ide_source_location_get_offset (IdeSourceLocation *self);
IdeFile *ide_source_location_get_file (IdeSourceLocation *self);
IdeUri *ide_source_location_get_uri (IdeSourceLocation *self);
gint ide_source_location_compare (const IdeSourceLocation *a,
const IdeSourceLocation *b);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeSourceLocation, ide_source_location_unref)
......
......@@ -689,3 +689,19 @@ ide_file_new_for_path (IdeContext *context,
return ret;
}
gint
ide_file_compare (const IdeFile *a,
const IdeFile *b)
{
g_autofree gchar *filea = NULL;
g_autofree gchar *fileb = NULL;
g_assert (a != NULL);
g_assert (b != NULL);
filea = g_file_get_uri (a->file);
fileb = g_file_get_uri (b->file);
return g_strcmp0 (filea, fileb);
}
......@@ -55,6 +55,8 @@ void ide_file_find_other_async (IdeFile *self,
IdeFile *ide_file_find_other_finish (IdeFile *self,
GAsyncResult *result,
GError **error);
gint ide_file_compare (const IdeFile *a,
const IdeFile *b);
G_END_DECLS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment