[gnome-builder/wip/slaf/xml-pack: 37/56] xml-pack: fix end tag range
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/slaf/xml-pack: 37/56] xml-pack: fix end tag range
- Date: Thu, 13 Jul 2017 12:22:08 +0000 (UTC)
commit 0f12b3df29ae85fc7e1005306c7491858d797017
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sat Jun 3 12:37:33 2017 +0200
xml-pack: fix end tag range
plugins/xml-pack/ide-xml-sax.c | 27 +++++-
plugins/xml-pack/ide-xml-symbol-node.c | 22 +++--
plugins/xml-pack/ide-xml-symbol-node.h | 136 +++++++++++++++++---------------
plugins/xml-pack/ide-xml-types.h | 2 -
4 files changed, 108 insertions(+), 79 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-sax.c b/plugins/xml-pack/ide-xml-sax.c
index c49c072..22194f1 100644
--- a/plugins/xml-pack/ide-xml-sax.c
+++ b/plugins/xml-pack/ide-xml-sax.c
@@ -184,16 +184,21 @@ static void
get_tag_location (IdeXmlSax *self,
gint *line,
gint *line_offset,
+ gint *end_line_offset,
const gchar **content,
gsize *size)
{
xmlParserInput *input;
const gchar *base;
const gchar *current;
+ const gchar *end_current;
const gchar *line_start;
+ const gchar *end_line_start;
gint start_line_number;
+ gint end_line_number;
gint size_offset = 1;
gunichar ch;
+ gboolean end_line_found = FALSE;
g_assert (IDE_IS_XML_SAX (self));
g_assert (line != NULL);
@@ -206,7 +211,7 @@ get_tag_location (IdeXmlSax *self,
input = self->context->input;
base = (const gchar *)input->base;
current = (const gchar *)input->cur;
- start_line_number = xmlSAX2GetLineNumber (self->context);
+ end_line_number = start_line_number = xmlSAX2GetLineNumber (self->context);
/* Adjust the element size, can be a start, a end or an auto-closed one */
if (g_utf8_get_char (current) != '>')
@@ -225,10 +230,11 @@ get_tag_location (IdeXmlSax *self,
}
}
+ end_current = current;
if (g_utf8_get_char (current) != '>')
{
*line = start_line_number;
- *line_offset = xmlSAX2GetColumnNumber (self->context);
+ *line_offset = *end_line_offset = xmlSAX2GetColumnNumber (self->context);
*content = NULL;
*size = 0;
@@ -242,7 +248,14 @@ get_tag_location (IdeXmlSax *self,
break;
if (ch == '\n')
- --start_line_number;
+ {
+ --start_line_number;
+ if (!end_line_found )
+ {
+ end_line_start = current + 1;
+ end_line_found = TRUE;
+ }
+ }
current = g_utf8_prev_char (current);
}
@@ -254,6 +267,9 @@ get_tag_location (IdeXmlSax *self,
if (ch == '\n')
{
++line_start;
+ if (!end_line_found )
+ end_line_start = line_start;
+
break;
}
@@ -262,6 +278,7 @@ get_tag_location (IdeXmlSax *self,
*line = start_line_number;
*line_offset = (current - line_start) + 1;
+ *end_line_offset = (end_current - end_line_start) + 1;
*content = current;
*size = (const gchar *)input->cur - current + size_offset;
}
@@ -285,7 +302,7 @@ ide_xml_sax_get_location (IdeXmlSax *self,
g_return_val_if_fail (IDE_IS_XML_SAX (self), FALSE);
g_return_val_if_fail (self->context != NULL, FALSE);
- get_tag_location (self, &tmp_line, &tmp_line_offset, &tmp_content, &tmp_size);
+ get_tag_location (self, &tmp_line, &tmp_line_offset, &tmp_end_line_offset, &tmp_content, &tmp_size);
if (start_line != NULL)
*start_line = tmp_line;
@@ -300,7 +317,7 @@ ide_xml_sax_get_location (IdeXmlSax *self,
*size = tmp_size;
tmp_end_line = xmlSAX2GetLineNumber (self->context);
- tmp_end_line_offset = xmlSAX2GetColumnNumber (self->context);
+ //tmp_end_line_offset = xmlSAX2GetColumnNumber (self->context);
if (end_line != NULL)
*end_line = tmp_end_line;
diff --git a/plugins/xml-pack/ide-xml-symbol-node.c b/plugins/xml-pack/ide-xml-symbol-node.c
index 43a758f..07bf349 100644
--- a/plugins/xml-pack/ide-xml-symbol-node.c
+++ b/plugins/xml-pack/ide-xml-symbol-node.c
@@ -431,6 +431,7 @@ ide_xml_symbol_node_set_location (IdeXmlSymbolNode *self,
{
g_return_if_fail (IDE_IS_XML_SYMBOL_NODE (self));
g_return_if_fail (G_IS_FILE (file) || file == NULL);
+ g_return_if_fail (size >= 2);
g_clear_object (&self->file);
if (file != NULL)
@@ -514,6 +515,7 @@ ide_xml_symbol_node_set_end_tag_location (IdeXmlSymbolNode *self,
gsize size)
{
g_return_if_fail (IDE_IS_XML_SYMBOL_NODE (self));
+ g_return_if_fail (size >= 2);
self->end_tag.start_line = start_line;
self->end_tag.start_line_offset = start_line_offset;
@@ -588,7 +590,7 @@ is_in_range (NodeRange range,
gint line_offset)
{
if (line < range.start_line ||
- (line == range.start_line && line_offset < range.start_line_offset))
+ (line == range.start_line && line_offset <= range.start_line_offset))
return -1;
if (line > range.end_line ||
@@ -616,7 +618,7 @@ print_node_ranges (IdeXmlSymbolNode *node)
/* Find the relative position of the (line, line_offset) cursor
* according to the reference node ref_node
*/
-IdeXmlPositionKind
+IdeXmlSymbolNodeRelativePosition
ide_xml_symbol_node_compare_location (IdeXmlSymbolNode *ref_node,
gint line,
gint line_offset)
@@ -627,20 +629,20 @@ ide_xml_symbol_node_compare_location (IdeXmlSymbolNode *ref_node,
pos = is_in_range(ref_node->start_tag, line, line_offset);
if (pos == -1)
- return IDE_XML_POSITION_KIND_BEFORE;
+ return IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_BEFORE;
else if (pos == 0)
- return IDE_XML_POSITION_KIND_IN_START_TAG;
+ return IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_IN_START_TAG;
if (ref_node->has_end_tag)
{
pos = is_in_range(ref_node->end_tag, line, line_offset);
if (pos == -1)
- return IDE_XML_POSITION_KIND_IN_CONTENT;
+ return IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_IN_CONTENT;
else if (pos == 0)
- return IDE_XML_POSITION_KIND_IN_END_TAG;
+ return IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_IN_END_TAG;
}
- return IDE_XML_POSITION_KIND_AFTER;
+ return IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_AFTER;
}
void
@@ -672,10 +674,12 @@ ide_xml_symbol_node_print (IdeXmlSymbolNode *self,
g_return_if_fail (IDE_IS_XML_SYMBOL_NODE (self));
- printf ("%s(%d:%d->%d:%d)\n",
+ printf ("%s(%d:%d->%d:%d)-(%d:%d->%d:%d)\n",
self->element_name,
self->start_tag.start_line, self->start_tag.start_line_offset,
- self->end_tag.start_line, self->end_tag.start_line_offset);
+ self->start_tag.end_line, self->start_tag.end_line_offset,
+ self->end_tag.start_line, self->end_tag.start_line_offset,
+ self->end_tag.end_line, self->end_tag.end_line_offset);
if (show_attributes && self->attributes_names != NULL)
while (*attributes != NULL)
diff --git a/plugins/xml-pack/ide-xml-symbol-node.h b/plugins/xml-pack/ide-xml-symbol-node.h
index cdb5cd3..b169ad7 100644
--- a/plugins/xml-pack/ide-xml-symbol-node.h
+++ b/plugins/xml-pack/ide-xml-symbol-node.h
@@ -30,69 +30,79 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeXmlSymbolNode, ide_xml_symbol_node, IDE, XML_SYMBOL_NODE, IdeSymbolNode)
-IdeXmlSymbolNode *ide_xml_symbol_node_new (const gchar *name,
- const gchar *value,
- const gchar
*element_name,
- IdeSymbolKind kind);
-IdeXmlPositionKind ide_xml_symbol_node_compare_location (IdeXmlSymbolNode
*ref_node,
- gint line,
- gint
line_offset);
-void ide_xml_symbol_node_take_child (IdeXmlSymbolNode *self,
- IdeXmlSymbolNode *child);
-void ide_xml_symbol_node_take_internal_child (IdeXmlSymbolNode *self,
- IdeXmlSymbolNode *child);
-const gchar *ide_xml_symbol_node_get_element_name (IdeXmlSymbolNode *self);
-GFile * ide_xml_symbol_node_get_location (IdeXmlSymbolNode *self,
- gint
*start_line,
- gint
*start_line_offset,
- gint
*end_line,
- gint
*end_line_offset,
- gsize *size);
-void ide_xml_symbol_node_get_end_tag_location (IdeXmlSymbolNode *self,
- gint
*start_line,
- gint
*start_line_offset,
- gint
*end_line,
- gint
*end_line_offset,
- gsize *size);
-const gchar *ide_xml_symbol_node_get_namespace (IdeXmlSymbolNode *self);
-guint ide_xml_symbol_node_get_n_children (IdeXmlSymbolNode *self);
-guint ide_xml_symbol_node_get_n_internal_children (IdeXmlSymbolNode *self);
-IdeSymbolNode *ide_xml_symbol_node_get_nth_child (IdeXmlSymbolNode *self,
- guint
nth_child);
-IdeSymbolNode *ide_xml_symbol_node_get_nth_child_deep (IdeXmlSymbolNode *self,
- guint
nth_child,
- guint
*current_pos);
-guint ide_xml_symbol_node_get_n_direct_children (IdeXmlSymbolNode *self);
-IdeSymbolNode *ide_xml_symbol_node_get_nth_direct_child (IdeXmlSymbolNode *self,
- guint
nth_child);
-IdeSymbolNode *ide_xml_symbol_node_get_nth_internal_child (IdeXmlSymbolNode *self,
- guint
nth_child);
-IdeXmlSymbolNode *ide_xml_symbol_node_get_parent (IdeXmlSymbolNode *self);
-const gchar *ide_xml_symbol_node_get_value (IdeXmlSymbolNode *self);
-gboolean ide_xml_symbol_node_has_end_tag (IdeXmlSymbolNode *self);
-void ide_xml_symbol_node_print (IdeXmlSymbolNode *self,
- gboolean
show_value,
- gboolean
show_attributes);
-void ide_xml_symbol_node_set_location (IdeXmlSymbolNode *self,
- GFile *file,
- gint
start_line,
- gint
start_line_offset,
- gint
end_line,
- gint
end_line_offset,
- gsize size);
-void ide_xml_symbol_node_set_end_tag_location (IdeXmlSymbolNode *self,
- gint
start_line,
- gint
start_line_offset,
- gint
end_line,
- gint
end_line_offset,
- gsize size);
-void ide_xml_symbol_node_set_element_name (IdeXmlSymbolNode *self,
- const gchar
*element_name);
-void ide_xml_symbol_node_set_value (IdeXmlSymbolNode *self,
- const gchar *value);
-const gchar **ide_xml_symbol_node_get_attributes_names (IdeXmlSymbolNode *self);
-void ide_xml_symbol_node_take_attributes_names (IdeXmlSymbolNode *self,
- gchar
**attributes_names);
+typedef enum
+{
+ IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_UNKNOW,
+ IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_BEFORE,
+ IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_AFTER,
+ IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_IN_START_TAG,
+ IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_IN_END_TAG,
+ IDE_XML_SYMBOL_NODE_RELATIVE_POSITION_IN_CONTENT
+} IdeXmlSymbolNodeRelativePosition;
+
+IdeXmlSymbolNode *ide_xml_symbol_node_new (const gchar
*name,
+ const gchar
*value,
+ const gchar
*element_name,
+ IdeSymbolKind
kind);
+IdeXmlSymbolNodeRelativePosition ide_xml_symbol_node_compare_location (IdeXmlSymbolNode
*ref_node,
+ gint
line,
+ gint
line_offset);
+void ide_xml_symbol_node_take_child (IdeXmlSymbolNode
*self,
+ IdeXmlSymbolNode
*child);
+void ide_xml_symbol_node_take_internal_child (IdeXmlSymbolNode
*self,
+ IdeXmlSymbolNode
*child);
+const gchar *ide_xml_symbol_node_get_element_name (IdeXmlSymbolNode
*self);
+GFile * ide_xml_symbol_node_get_location (IdeXmlSymbolNode
*self,
+ gint
*start_line,
+ gint
*start_line_offset,
+ gint
*end_line,
+ gint
*end_line_offset,
+ gsize
*size);
+void ide_xml_symbol_node_get_end_tag_location (IdeXmlSymbolNode
*self,
+ gint
*start_line,
+ gint
*start_line_offset,
+ gint
*end_line,
+ gint
*end_line_offset,
+ gsize
*size);
+const gchar *ide_xml_symbol_node_get_namespace (IdeXmlSymbolNode
*self);
+guint ide_xml_symbol_node_get_n_children (IdeXmlSymbolNode
*self);
+guint ide_xml_symbol_node_get_n_internal_children (IdeXmlSymbolNode
*self);
+IdeSymbolNode *ide_xml_symbol_node_get_nth_child (IdeXmlSymbolNode
*self,
+ guint
nth_child);
+IdeSymbolNode *ide_xml_symbol_node_get_nth_child_deep (IdeXmlSymbolNode
*self,
+ guint
nth_child,
+ guint
*current_pos);
+guint ide_xml_symbol_node_get_n_direct_children (IdeXmlSymbolNode
*self);
+IdeSymbolNode *ide_xml_symbol_node_get_nth_direct_child (IdeXmlSymbolNode
*self,
+ guint
nth_child);
+IdeSymbolNode *ide_xml_symbol_node_get_nth_internal_child (IdeXmlSymbolNode
*self,
+ guint
nth_child);
+IdeXmlSymbolNode *ide_xml_symbol_node_get_parent (IdeXmlSymbolNode
*self);
+const gchar *ide_xml_symbol_node_get_value (IdeXmlSymbolNode
*self);
+gboolean ide_xml_symbol_node_has_end_tag (IdeXmlSymbolNode
*self);
+void ide_xml_symbol_node_print (IdeXmlSymbolNode
*self,
+ gboolean
show_value,
+ gboolean
show_attributes);
+void ide_xml_symbol_node_set_location (IdeXmlSymbolNode
*self,
+ GFile
*file,
+ gint
start_line,
+ gint
start_line_offset,
+ gint
end_line,
+ gint
end_line_offset,
+ gsize
size);
+void ide_xml_symbol_node_set_end_tag_location (IdeXmlSymbolNode
*self,
+ gint
start_line,
+ gint
start_line_offset,
+ gint
end_line,
+ gint
end_line_offset,
+ gsize
size);
+void ide_xml_symbol_node_set_element_name (IdeXmlSymbolNode
*self,
+ const gchar
*element_name);
+void ide_xml_symbol_node_set_value (IdeXmlSymbolNode
*self,
+ const gchar
*value);
+const gchar **ide_xml_symbol_node_get_attributes_names (IdeXmlSymbolNode
*self);
+void ide_xml_symbol_node_take_attributes_names (IdeXmlSymbolNode
*self,
+ gchar
**attributes_names);
G_END_DECLS
diff --git a/plugins/xml-pack/ide-xml-types.h b/plugins/xml-pack/ide-xml-types.h
index 12b9954..b42889b 100644
--- a/plugins/xml-pack/ide-xml-types.h
+++ b/plugins/xml-pack/ide-xml-types.h
@@ -26,8 +26,6 @@ G_BEGIN_DECLS
typedef enum
{
IDE_XML_POSITION_KIND_UNKNOW,
- IDE_XML_POSITION_KIND_BEFORE,
- IDE_XML_POSITION_KIND_AFTER,
IDE_XML_POSITION_KIND_IN_START_TAG,
IDE_XML_POSITION_KIND_IN_END_TAG,
IDE_XML_POSITION_KIND_IN_CONTENT
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]