[gnome-builder/wip/slaf/xml-pack: 8/56] xmp-pack: add (line, line_offset) for end of node loacation
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/slaf/xml-pack: 8/56] xmp-pack: add (line, line_offset) for end of node loacation
- Date: Thu, 13 Jul 2017 12:19:42 +0000 (UTC)
commit 406adaec47a38b42b093d460cb0edcd2286f625f
Author: Sebastien Lafargue <slafargue gnome org>
Date: Fri Apr 7 21:38:54 2017 +0200
xmp-pack: add (line,line_offset) for end of node loacation
Having the start of a tag and its size is sometime not
enough to work with because we don't know where the end-oof-line is
without inspecting the source file.
So we now use the following form:
(start_line, start_line_offset, end_line, end_line_offset, size)
plugins/xml-pack/ide-xml-parser-generic.c | 6 +-
plugins/xml-pack/ide-xml-parser-ui.c | 24 +++---
plugins/xml-pack/ide-xml-parser.c | 29 +++++--
plugins/xml-pack/ide-xml-symbol-node.c | 105 ++++++++++++++++---------
plugins/xml-pack/ide-xml-symbol-node.h | 26 ++++--
plugins/xml-pack/ide-xml-tree-builder-utils.c | 19 +++--
6 files changed, 135 insertions(+), 74 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-parser-generic.c b/plugins/xml-pack/ide-xml-parser-generic.c
index 2dea869..4526901 100644
--- a/plugins/xml-pack/ide-xml-parser-generic.c
+++ b/plugins/xml-pack/ide-xml-parser-generic.c
@@ -67,7 +67,7 @@ ide_xml_parser_generic_start_element_sax_cb (ParserState *state,
attr = collect_attributes (self, (const gchar **)attributes);
label = g_strconcat ((const gchar *)name, attr, NULL);
- node = ide_xml_symbol_node_new (label, NULL, NULL, IDE_SYMBOL_XML_ELEMENT, NULL, 0, 0, 0);
+ node = ide_xml_symbol_node_new (label, NULL, NULL, IDE_SYMBOL_XML_ELEMENT, NULL, 0, 0, 0, 0, 0);
g_object_set (node, "use-markup", TRUE, NULL);
ide_xml_parser_state_processing (self, state, (const gchar *)name, node,
IDE_XML_SAX_CALLBACK_TYPE_START_ELEMENT, FALSE);
@@ -84,7 +84,7 @@ ide_xml_parser_generic_comment_sax_cb (ParserState *state,
g_assert (IDE_IS_XML_PARSER (self));
strip_name = g_strstrip (g_strdup ((const gchar *)name));
- node = ide_xml_symbol_node_new (strip_name, NULL, NULL, IDE_SYMBOL_XML_COMMENT, NULL, 0, 0, 0);
+ node = ide_xml_symbol_node_new (strip_name, NULL, NULL, IDE_SYMBOL_XML_COMMENT, NULL, 0, 0, 0, 0, 0);
ide_xml_parser_state_processing (self, state, "comment", node, IDE_XML_SAX_CALLBACK_TYPE_COMMENT, FALSE);
}
@@ -98,7 +98,7 @@ ide_xml_parser_generic_cdata_sax_cb (ParserState *state,
g_assert (IDE_IS_XML_PARSER (self));
- node = ide_xml_symbol_node_new ("cdata", NULL, NULL, IDE_SYMBOL_XML_CDATA, NULL, 0, 0, 0);
+ node = ide_xml_symbol_node_new ("cdata", NULL, NULL, IDE_SYMBOL_XML_CDATA, NULL, 0, 0, 0, 0, 0);
ide_xml_parser_state_processing (self, state, "cdata", node, IDE_XML_SAX_CALLBACK_TYPE_CDATA, FALSE);
}
diff --git a/plugins/xml-pack/ide-xml-parser-ui.c b/plugins/xml-pack/ide-xml-parser-ui.c
index 12549cb..7993110 100644
--- a/plugins/xml-pack/ide-xml-parser-ui.c
+++ b/plugins/xml-pack/ide-xml-parser-ui.c
@@ -66,7 +66,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
{
value = get_attribute (attributes, "name", NULL);
node = ide_xml_symbol_node_new (value, NULL, "property",
- IDE_SYMBOL_UI_PROPERTY, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_PROPERTY, NULL, 0, 0, 0, 0, 0);
is_internal = TRUE;
state->build_state = BUILD_STATE_GET_CONTENT;
}
@@ -79,7 +79,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
{
value = get_attribute (attributes, "name", NULL);
node = ide_xml_symbol_node_new (value, NULL, "attribute",
- IDE_SYMBOL_UI_MENU_ATTRIBUTE, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_MENU_ATTRIBUTE, NULL, 0, 0, 0, 0, 0);
is_internal = TRUE;
state->build_state = BUILD_STATE_GET_CONTENT;
}
@@ -88,7 +88,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
{
value = get_attribute (attributes, "name", NULL);
node = ide_xml_symbol_node_new (value, NULL, "class",
- IDE_SYMBOL_UI_STYLE_CLASS, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_STYLE_CLASS, NULL, 0, 0, 0, 0, 0);
is_internal = TRUE;
}
else if (ide_str_equal0 (name, "child"))
@@ -110,7 +110,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
}
node = ide_xml_symbol_node_new (string->str, NULL, "child",
- IDE_SYMBOL_UI_CHILD, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_CHILD, NULL, 0, 0, 0, 0, 0);
g_object_set (node, "use-markup", TRUE, NULL);
}
else if (ide_str_equal0 (name, "object"))
@@ -129,7 +129,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
}
node = ide_xml_symbol_node_new (string->str, NULL, "object",
- IDE_SYMBOL_UI_OBJECT, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_OBJECT, NULL, 0, 0, 0, 0, 0);
g_object_set (node, "use-markup", TRUE, NULL);
}
else if (ide_str_equal0 (name, "template"))
@@ -146,18 +146,18 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
g_string_append (string, value);
node = ide_xml_symbol_node_new (string->str, NULL, (const gchar *)name,
- IDE_SYMBOL_UI_TEMPLATE, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_TEMPLATE, NULL, 0, 0, 0, 0, 0);
g_object_set (node, "use-markup", TRUE, NULL);
}
else if (ide_str_equal0 (name, "packing"))
{
node = ide_xml_symbol_node_new ("packing", NULL, "packing",
- IDE_SYMBOL_UI_PACKING, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_PACKING, NULL, 0, 0, 0, 0, 0);
}
else if (ide_str_equal0 (name, "style"))
{
node = ide_xml_symbol_node_new ("style", NULL, "style",
- IDE_SYMBOL_UI_STYLE, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_STYLE, NULL, 0, 0, 0, 0, 0);
}
else if (ide_str_equal0 (name, "menu"))
{
@@ -167,7 +167,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
g_string_append (string, value);
node = ide_xml_symbol_node_new (string->str, NULL, "menu",
- IDE_SYMBOL_UI_MENU, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_MENU, NULL, 0, 0, 0, 0, 0);
g_object_set (node, "use-markup", TRUE, NULL);
}
else if (ide_str_equal0 (name, "submenu"))
@@ -178,7 +178,7 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
g_string_append (string, value);
node = ide_xml_symbol_node_new (string->str, NULL, "submenu",
- IDE_SYMBOL_UI_SUBMENU, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_SUBMENU, NULL, 0, 0, 0, 0, 0);
g_object_set (node, "use-markup", TRUE, NULL);
}
else if (ide_str_equal0 (name, "section"))
@@ -189,13 +189,13 @@ ide_xml_parser_ui_start_element_sax_cb (ParserState *state,
g_string_append (string, value);
node = ide_xml_symbol_node_new (string->str, NULL, "section",
- IDE_SYMBOL_UI_SECTION, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_SECTION, NULL, 0, 0, 0, 0, 0);
g_object_set (node, "use-markup", TRUE, NULL);
}
else if (ide_str_equal0 (name, "item"))
{
node = ide_xml_symbol_node_new ("item", NULL, "item",
- IDE_SYMBOL_UI_ITEM, NULL, 0, 0, 0);
+ IDE_SYMBOL_UI_ITEM, NULL, 0, 0, 0, 00, 0);
}
ide_xml_parser_state_processing (self, state, (const gchar *)name, node,
IDE_XML_SAX_CALLBACK_TYPE_START_ELEMENT, is_internal);
diff --git a/plugins/xml-pack/ide-xml-parser.c b/plugins/xml-pack/ide-xml-parser.c
index 6611c59..755bb6c 100644
--- a/plugins/xml-pack/ide-xml-parser.c
+++ b/plugins/xml-pack/ide-xml-parser.c
@@ -158,8 +158,10 @@ ide_xml_parser_state_processing (IdeXmlParser *self,
IdeXmlSymbolNode *parent_node;
G_GNUC_UNUSED IdeXmlSymbolNode *popped_node;
g_autofree gchar *popped_element_name = NULL;
- gint line;
- gint line_offset;
+ gint start_line;
+ gint start_line_offset;
+ gint end_line;
+ gint end_line_offset;
gsize size;
gint depth;
@@ -172,14 +174,17 @@ ide_xml_parser_state_processing (IdeXmlParser *self,
}
depth = ide_xml_sax_get_depth (self->sax_parser);
- ide_xml_sax_get_location (self->sax_parser, &line, &line_offset, NULL, NULL, &size);
+ ide_xml_sax_get_location (self->sax_parser, &start_line, &start_line_offset, &end_line, &end_line_offset,
&size);
if (node == NULL)
{
if (callback_type == IDE_XML_SAX_CALLBACK_TYPE_START_ELEMENT)
{
- node = ide_xml_symbol_node_new ("internal", NULL, element_name, IDE_SYMBOL_XML_ELEMENT, NULL, 0,
0, 0);
- ide_xml_symbol_node_set_location (node, g_object_ref (state->file), line, line_offset, size);
+ node = ide_xml_symbol_node_new ("internal", NULL, element_name, IDE_SYMBOL_XML_ELEMENT,
+ g_object_ref (state->file),
+ start_line, start_line_offset,
+ end_line, end_line_offset,
+ size);
ide_xml_stack_push (self->stack, element_name, node, state->parent_node, depth);
ide_xml_symbol_node_take_internal_child (state->parent_node, node);
@@ -198,7 +203,10 @@ ide_xml_parser_state_processing (IdeXmlParser *self,
popped_node = ide_xml_stack_pop (self->stack, &popped_element_name, &parent_node, &depth);
if (ide_str_equal0 (popped_element_name, element_name))
{
- ide_xml_symbol_node_set_end_tag_location (popped_node, line, line_offset, size);
+ ide_xml_symbol_node_set_end_tag_location (popped_node,
+ start_line, start_line_offset,
+ end_line, end_line_offset,
+ size);
state->parent_node = parent_node;
g_assert (state->parent_node != NULL);
@@ -212,8 +220,11 @@ ide_xml_parser_state_processing (IdeXmlParser *self,
return;
}
-
- ide_xml_symbol_node_set_location (node, g_object_ref (state->file), line, line_offset, size);
+ ide_xml_symbol_node_set_location (node,
+ g_object_ref (state->file),
+ start_line, start_line_offset,
+ end_line, end_line_offset,
+ size);
/* TODO: take end elements into account and use:
* || ABS (depth - current_depth) > 1
@@ -536,7 +547,7 @@ ide_xml_parser_get_analysis_async (IdeXmlParser *self,
state->build_state = BUILD_STATE_NORMAL;
state->analysis = ide_xml_analysis_new (-1);
- state->root_node = ide_xml_symbol_node_new ("root", NULL, "root", IDE_SYMBOL_NONE, NULL, 0, 0, 0);
+ state->root_node = ide_xml_symbol_node_new ("root", NULL, "root", IDE_SYMBOL_NONE, NULL, 0, 0, 0, 0, 0);
ide_xml_analysis_set_root_node (state->analysis, state->root_node);
state->parent_node = state->root_node;
diff --git a/plugins/xml-pack/ide-xml-symbol-node.c b/plugins/xml-pack/ide-xml-symbol-node.c
index f64ccb6..7b2b2f2 100644
--- a/plugins/xml-pack/ide-xml-symbol-node.c
+++ b/plugins/xml-pack/ide-xml-symbol-node.c
@@ -27,6 +27,15 @@ typedef struct _NodeEntry
guint is_internal : 1;
} NodeEntry;
+typedef struct _NodeRange
+{
+ gint start_line;
+ gint start_line_offset;
+ gint end_line;
+ gint end_line_offset;
+ gsize size;
+} NodeRange;
+
struct _IdeXmlSymbolNode
{
IdeSymbolNode parent_instance;
@@ -36,13 +45,8 @@ struct _IdeXmlSymbolNode
gint nb_children;
gint nb_internal_children;
GFile *file;
- gint line;
- gint line_offset;
- gsize size;
-
- gint end_line;
- gint end_line_offset;
- gsize end_size;
+ NodeRange start_tag;
+ NodeRange end_tag;
guint has_end_tag : 1;
};
@@ -74,10 +78,10 @@ ide_xml_symbol_node_get_location_async (IdeSymbolNode *node,
"context", context,
NULL);
- /* TODO: libxml2 give us the end of a tag, we need to walk back
- * in the file content to get the start
- */
- ret = ide_source_location_new (ifile, self->line - 1, self->line_offset - 1, 0);
+ ret = ide_source_location_new (ifile,
+ self->start_tag.start_line - 1,
+ self->start_tag.start_line_offset - 1,
+ 0);
g_task_return_pointer (task, ret, (GDestroyNotify)ide_source_location_unref);
}
@@ -131,8 +135,10 @@ ide_xml_symbol_node_new (const gchar *name,
const gchar *element_name,
IdeSymbolKind kind,
GFile *file,
- gint line,
- gint line_offset,
+ gint start_line,
+ gint start_line_offset,
+ gint end_line,
+ gint end_line_offset,
gsize size)
{
IdeXmlSymbolNode *self;
@@ -158,8 +164,11 @@ ide_xml_symbol_node_new (const gchar *name,
if (file != NULL)
self->file = g_object_ref (file);
- self->line = line;
- self->line_offset = line_offset;
+ self->start_tag.start_line = start_line;
+ self->start_tag.start_line_offset = start_line_offset;
+ self->start_tag.end_line = end_line;
+ self->start_tag.end_line_offset = end_line_offset;
+ self->start_tag.size = size;
return self;
}
@@ -353,8 +362,10 @@ ide_xml_symbol_node_take_internal_child (IdeXmlSymbolNode *self,
void
ide_xml_symbol_node_set_location (IdeXmlSymbolNode *self,
GFile *file,
- gint line,
- gint line_offset,
+ gint start_line,
+ gint start_line_offset,
+ gint end_line,
+ gint end_line_offset,
gsize size)
{
g_return_if_fail (IDE_IS_XML_SYMBOL_NODE (self));
@@ -364,9 +375,11 @@ ide_xml_symbol_node_set_location (IdeXmlSymbolNode *self,
if (file != NULL)
self->file = g_object_ref (file);
- self->line = line;
- self->line_offset = line_offset;
- self->size = size;
+ self->start_tag.start_line = start_line;
+ self->start_tag.start_line_offset = start_line_offset;
+ self->start_tag.end_line = end_line;
+ self->start_tag.end_line_offset = end_line_offset;
+ self->start_tag.size = size;
}
/**
@@ -379,53 +392,73 @@ ide_xml_symbol_node_set_location (IdeXmlSymbolNode *self,
*/
GFile *
ide_xml_symbol_node_get_location (IdeXmlSymbolNode *self,
- gint *line,
- gint *line_offset,
+ gint *start_line,
+ gint *start_line_offset,
+ gint *end_line,
+ gint *end_line_offset,
gsize *size)
{
g_return_val_if_fail (IDE_IS_XML_SYMBOL_NODE (self), NULL);
- if (line != NULL)
- *line = self->line;
+ if (start_line != NULL)
+ *start_line = self->start_tag.start_line;
+
+ if (start_line_offset != NULL)
+ *start_line_offset = self->start_tag.start_line_offset;
+
+ if (end_line != NULL)
+ *end_line = self->start_tag.end_line;
- if (line_offset != NULL)
- *line_offset = self->line_offset;
+ if (end_line_offset != NULL)
+ *end_line_offset = self->start_tag.end_line_offset;
if (size != NULL)
- *size = self->size;
+ *size = self->start_tag.size;
return self->file;
}
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 *end_size)
+ gsize *size)
{
g_return_if_fail (IDE_IS_XML_SYMBOL_NODE (self));
+ if (start_line != NULL)
+ *start_line = self->end_tag.start_line;
+
+ if (start_line_offset != NULL)
+ *start_line_offset = self->end_tag.start_line_offset;
+
if (end_line != NULL)
- *end_line = self->end_line;
+ *end_line = self->end_tag.end_line;
if (end_line_offset != NULL)
- *end_line_offset = self->end_line_offset;
+ *end_line_offset = self->end_tag.end_line_offset;
- if (end_size != NULL)
- *end_size = self->end_size;
+ if (size != NULL)
+ *size = self->end_tag.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 end_size)
+ gsize size)
{
g_return_if_fail (IDE_IS_XML_SYMBOL_NODE (self));
- self->end_line = end_line;
- self->end_line_offset = end_line_offset;
- self->end_size = end_size;
+ self->end_tag.start_line = start_line;
+ self->end_tag.start_line_offset = start_line_offset;
+ self->end_tag.end_line = end_line;
+ self->end_tag.end_line_offset = end_line_offset;
+ self->end_tag.size = size;
self->has_end_tag = TRUE;
}
diff --git a/plugins/xml-pack/ide-xml-symbol-node.h b/plugins/xml-pack/ide-xml-symbol-node.h
index fedd3a4..42bc5fe 100644
--- a/plugins/xml-pack/ide-xml-symbol-node.h
+++ b/plugins/xml-pack/ide-xml-symbol-node.h
@@ -34,8 +34,10 @@ IdeXmlSymbolNode *ide_xml_symbol_node_new (con
const gchar
*element_name,
IdeSymbolKind kind,
GFile *file,
- gint line,
- gint
line_offset,
+ gint
start_line,
+ gint
start_line_offset,
+ gint
end_line,
+ gint
end_line_offset,
gsize size);
void ide_xml_symbol_node_take_child (IdeXmlSymbolNode *self,
IdeXmlSymbolNode *child);
@@ -43,13 +45,17 @@ void ide_xml_symbol_node_take_internal_child (Ide
IdeXmlSymbolNode *child);
const gchar *ide_xml_symbol_node_get_element_name (IdeXmlSymbolNode *self);
GFile * ide_xml_symbol_node_get_location (IdeXmlSymbolNode *self,
- gint *line,
- gint
*line_offset,
+ 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
*end_size);
+ gsize *size);
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,
@@ -63,13 +69,17 @@ const gchar *ide_xml_symbol_node_get_value (Ide
gboolean ide_xml_symbol_node_has_end_tag (IdeXmlSymbolNode *self);
void ide_xml_symbol_node_set_location (IdeXmlSymbolNode *self,
GFile *file,
- gint line,
- gint
line_offset,
+ 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
end_size);
+ 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,
diff --git a/plugins/xml-pack/ide-xml-tree-builder-utils.c b/plugins/xml-pack/ide-xml-tree-builder-utils.c
index 02de297..607de2c 100644
--- a/plugins/xml-pack/ide-xml-tree-builder-utils.c
+++ b/plugins/xml-pack/ide-xml-tree-builder-utils.c
@@ -27,8 +27,10 @@ print_node (IdeXmlSymbolNode *node,
guint depth)
{
g_autofree gchar *spacer;
- gint line;
- gint line_offset;
+ gint start_line;
+ gint start_line_offset;
+ gint end_line;
+ gint end_line_offset;
gsize size;
g_return_if_fail (IDE_IS_XML_SYMBOL_NODE (node) || node == NULL);
@@ -40,14 +42,19 @@ print_node (IdeXmlSymbolNode *node,
}
spacer = g_strnfill (depth, '\t');
- ide_xml_symbol_node_get_location (node, &line, &line_offset, &size);
+ ide_xml_symbol_node_get_location (node,
+ &start_line, &start_line_offset,
+ &end_line, &end_line_offset,
+ &size);
- printf ("%s%s (%i) at (%i,%i) size:%li %p\n",
+ printf ("%s%s (%i) at (%i,%i)-(%i,%i) size:%li %p\n",
spacer,
ide_symbol_node_get_name (IDE_SYMBOL_NODE (node)),
depth,
- line,
- line_offset,
+ start_line,
+ start_line_offset,
+ end_line,
+ end_line_offset,
size,
node);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]