[gnome-builder] fixit: add plumbing for fixits to IdeDiagnostic
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] fixit: add plumbing for fixits to IdeDiagnostic
- Date: Wed, 25 Mar 2015 07:26:08 +0000 (UTC)
commit d0729b490d7a4d8b1bd92c2dc43368963f9580fd
Author: Christian Hergert <christian hergert me>
Date: Wed Mar 25 00:25:07 2015 -0700
fixit: add plumbing for fixits to IdeDiagnostic
libide/Makefile.am | 2 +
libide/ide-diagnostic.c | 25 ++++++++---
libide/ide-diagnostic.h | 4 ++
libide/ide-fixit.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++
libide/ide-fixit.h | 37 ++++++++++++++++
libide/ide-internal.h | 4 ++
libide/ide-types.h | 2 +
7 files changed, 178 insertions(+), 7 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index a016868..f329ccc 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -92,6 +92,8 @@ libide_1_0_la_public_sources = \
libide/ide-file-settings.h \
libide/ide-file.c \
libide/ide-file.h \
+ libide/ide-fixit.c \
+ libide/ide-fixit.h \
libide/ide-global.h \
libide/ide-highlighter.c \
libide/ide-highlighter.h \
diff --git a/libide/ide-diagnostic.c b/libide/ide-diagnostic.c
index e352ddd..7c06ce0 100644
--- a/libide/ide-diagnostic.c
+++ b/libide/ide-diagnostic.c
@@ -29,6 +29,7 @@ struct _IdeDiagnostic
IdeDiagnosticSeverity severity;
gchar *text;
IdeSourceLocation *location;
+ GPtrArray *fixits;
GPtrArray *ranges;
};
@@ -54,7 +55,8 @@ ide_diagnostic_unref (IdeDiagnostic *self)
g_clear_pointer (&self->location, ide_source_location_unref);
g_clear_pointer (&self->text, g_free);
g_clear_pointer (&self->ranges, g_ptr_array_unref);
- g_slice_free (IdeDiagnostic, self);
+ g_clear_pointer (&self->fixits, g_ptr_array_unref);
+ g_free (self);
}
}
@@ -170,7 +172,7 @@ _ide_diagnostic_new (IdeDiagnosticSeverity severity,
{
IdeDiagnostic *ret;
- ret = g_slice_new0 (IdeDiagnostic);
+ ret = g_new0 (IdeDiagnostic, 1);
ret->ref_count = 1;
ret->severity = severity;
ret->text = g_strdup (text);
@@ -180,6 +182,19 @@ _ide_diagnostic_new (IdeDiagnosticSeverity severity,
}
void
+_ide_diagnostic_take_fixit (IdeDiagnostic *self,
+ IdeFixit *fixit)
+{
+ g_return_if_fail (self);
+ g_return_if_fail (fixit);
+
+ if (!self->fixits)
+ self->ranges = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_fixit_unref);
+
+ g_ptr_array_add (self->fixits, fixit);
+}
+
+void
_ide_diagnostic_take_range (IdeDiagnostic *self,
IdeSourceRange *range)
{
@@ -187,11 +202,7 @@ _ide_diagnostic_take_range (IdeDiagnostic *self,
g_return_if_fail (range);
if (!self->ranges)
- {
- self->ranges = g_ptr_array_new ();
- g_ptr_array_set_free_func (self->ranges,
- (GDestroyNotify)ide_source_range_unref);
- }
+ self->ranges = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_source_range_unref);
g_ptr_array_add (self->ranges, range);
}
diff --git a/libide/ide-diagnostic.h b/libide/ide-diagnostic.h
index 5384dc5..6385283 100644
--- a/libide/ide-diagnostic.h
+++ b/libide/ide-diagnostic.h
@@ -19,6 +19,7 @@
#ifndef IDE_DIAGNOSTIC_H
#define IDE_DIAGNOSTIC_H
+#include "ide-fixit.h"
#include "ide-types.h"
G_BEGIN_DECLS
@@ -35,6 +36,9 @@ typedef enum
} IdeDiagnosticSeverity;
IdeSourceLocation *ide_diagnostic_get_location (IdeDiagnostic *self);
+guint ide_diagnostic_get_num_fixits (IdeDiagnostic *self);
+IdeFixit *ide_diagnostic_get_fixit (IdeDiagnostic *self,
+ guint index);
guint ide_diagnostic_get_num_ranges (IdeDiagnostic *self);
IdeSourceRange *ide_diagnostic_get_range (IdeDiagnostic *self,
guint index);
diff --git a/libide/ide-fixit.c b/libide/ide-fixit.c
new file mode 100644
index 0000000..f2ceffa
--- /dev/null
+++ b/libide/ide-fixit.c
@@ -0,0 +1,111 @@
+/* ide-fixit.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-fixit.h"
+#include "ide-source-range.h"
+
+G_DEFINE_BOXED_TYPE (IdeFixit, ide_fixit, ide_fixit_ref, ide_fixit_unref)
+
+struct _IdeFixit
+{
+ volatile gint ref_count;
+ IdeSourceRange *range;
+ const gchar *text;
+};
+
+IdeFixit *
+_ide_fixit_new (IdeSourceRange *source_range,
+ const gchar *replacement_text)
+{
+ IdeFixit *self;
+
+ g_return_val_if_fail (source_range, NULL);
+ g_return_val_if_fail (replacement_text, NULL);
+
+ self = g_new0 (IdeFixit, 1);
+ self->ref_count = 1;
+ self->range = ide_source_range_ref (source_range);
+ self->text = g_strdup (replacement_text);
+
+ return self;
+}
+
+static void
+ide_fixit_destroy (IdeFixit *self)
+{
+ g_free (self);
+}
+
+IdeFixit *
+ide_fixit_ref (IdeFixit *self)
+{
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (self->ref_count > 0, NULL);
+
+ g_atomic_int_inc (&self->ref_count);
+
+ return self;
+}
+
+void
+ide_fixit_unref (IdeFixit *self)
+{
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (self->ref_count > 0, NULL);
+
+ if (g_atomic_int_dec_and_test (&self->ref_count))
+ ide_fixit_destroy (self);
+}
+
+void
+ide_fixit_apply (IdeFixit *self)
+{
+}
+
+/**
+ * ide_fixit_get_text:
+ * @self: A #IdeFixit.
+ *
+ * Gets the text to replace the source range with.
+ *
+ * Returns: A string with the replacement text.
+ */
+const gchar *
+ide_fixit_get_text (IdeFixit *self)
+{
+ g_return_val_if_fail (self, NULL);
+
+ return self->text;
+}
+
+/**
+ * ide_fixit_get_range:
+ * @self: A #IdeFixit.
+ *
+ * Gets the range for the replacement text. The range is non inclusive of the
+ * end location. [a,b)
+ *
+ * Returns: (transfer none): An #IdeSourceRange.
+ */
+IdeSourceRange *
+ide_fixit_get_range (IdeFixit *self)
+{
+ g_return_val_if_fail (self, NULL);
+
+ return self->range;
+}
diff --git a/libide/ide-fixit.h b/libide/ide-fixit.h
new file mode 100644
index 0000000..89b0204
--- /dev/null
+++ b/libide/ide-fixit.h
@@ -0,0 +1,37 @@
+/* ide-fixit.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_FIXIT_H
+#define IDE_FIXIT_H
+
+#include "ide-types.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_FIXIT (ide_fixit_get_type())
+
+GType ide_fixit_get_type (void);
+IdeFixit *ide_fixit_ref (IdeFixit *self);
+void ide_fixit_unref (IdeFixit *self);
+void ide_fixit_apply (IdeFixit *self);
+const gchar *ide_fixit_get_text (IdeFixit *self);
+IdeSourceRange *ide_fixit_get_range (IdeFixit *self);
+
+G_END_DECLS
+
+#endif /* IDE_FIXIT_H */
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index 6889e4c..b4f473e 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -66,6 +66,8 @@ void _ide_diagnostic_add_range (IdeDiagnostic *s
IdeDiagnostic *_ide_diagnostic_new (IdeDiagnosticSeverity severity,
const gchar *text,
IdeSourceLocation *location);
+void _ide_diagnostic_take_fixit (IdeDiagnostic *diagnostic,
+ IdeFixit *fixit);
void _ide_diagnostic_take_range (IdeDiagnostic *self,
IdeSourceRange *range);
void _ide_diagnostician_add_provider (IdeDiagnostician *self,
@@ -76,6 +78,8 @@ IdeDiagnostics *_ide_diagnostics_new (GPtrArray *a
GtkSourceFile *_ide_file_set_content_type (IdeFile *self,
const gchar *content_type);
GtkSourceFile *_ide_file_get_source_file (IdeFile *self);
+IdeFixit *_ide_fixit_new (IdeSourceRange *source_range,
+ const gchar *replacement_text);
void _ide_project_set_name (IdeProject *project,
const gchar *name);
void _ide_search_context_add_provider (IdeSearchContext *context,
diff --git a/libide/ide-types.h b/libide/ide-types.h
index 2392c91..0f3d7e0 100644
--- a/libide/ide-types.h
+++ b/libide/ide-types.h
@@ -84,6 +84,8 @@ typedef struct _IdeFile IdeFile;
typedef struct _IdeFileSettings IdeFileSettings;
+typedef struct _IdeFixit IdeFixit;
+
typedef struct _IdeHighlighter IdeHighlighter;
typedef struct _IdeIndenter IdeIndenter;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]