Skip to content

Commit

Permalink
Merge pull request #165 from techee/tm
Browse files Browse the repository at this point in the history
Tm
  • Loading branch information
techee committed Nov 8, 2014
2 parents 8802193 + c466fba commit 28edfa8
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 110 deletions.
4 changes: 2 additions & 2 deletions geanygendoc/src/ggd-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GeanyData *geany_data;
GeanyFunctions *geany_functions;

/* TODO check minimum requierment */
PLUGIN_VERSION_CHECK (188)
PLUGIN_VERSION_CHECK (221)

PLUGIN_SET_TRANSLATABLE_INFO (
LOCALEDIR, GETTEXT_PACKAGE,
Expand Down Expand Up @@ -114,7 +114,7 @@ ggd_plugin_get_doctype (filetype_id id)
/* FIXME: tm_source_file_buffer_update() is not found in symbols table */
/* (tries to) refresh the tag list to the file's current state */
static void
refresh_tag_list (TMWorkObject *tm_wo,
refresh_tag_list (TMSourceFile *tm_wo,
ScintillaObject *sci,
GeanyDocument *doc)
{
Expand Down
22 changes: 11 additions & 11 deletions geanygendoc/src/ggd-tag-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ tag_cmp_by_line (gconstpointer a,
if (t1->type & tm_tag_file_t || t2->type & tm_tag_file_t) {
rv = 0;
} else {
if (t1->atts.entry.line > t2->atts.entry.line) {
if (t1->line > t2->line) {
rv = +direction;
} else if (t1->atts.entry.line < t2->atts.entry.line) {
} else if (t1->line < t2->line) {
rv = -direction;
} else {
rv = 0;
Expand Down Expand Up @@ -159,8 +159,8 @@ ggd_tag_find_from_line (const GPtrArray *tags,

GGD_PTR_ARRAY_FOR (tags, i, el) {
if (! (el->type & tm_tag_file_t)) {
if (el->atts.entry.line <= line &&
(! tag || el->atts.entry.line > tag->atts.entry.line)) {
if (el->line <= line &&
(! tag || el->line > tag->line)) {
tag = el;
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ ggd_tag_find_parent (const GPtrArray *tags,
g_return_val_if_fail (tags != NULL, NULL);
g_return_val_if_fail (child != NULL, NULL);

if (! child->atts.entry.scope) {
if (! child->scope) {
/* tag has no parent, we're done */
} else {
gchar *parent_scope = NULL;
Expand All @@ -223,26 +223,26 @@ ggd_tag_find_parent (const GPtrArray *tags,
gsize separator_len;

/* scope is of the form a<sep>b<sep>c */
parent_name = child->atts.entry.scope;
parent_name = child->scope;
separator = symbols_get_context_separator (geany_ft);
separator_len = strlen (separator);
while ((tmp = strstr (parent_name, separator)) != NULL) {
parent_name = &tmp[separator_len];
}
/* if parent have scope */
if (parent_name != child->atts.entry.scope) {
if (parent_name != child->scope) {
/* the parent scope is the "dirname" of the child's scope */
parent_scope = g_strndup (child->atts.entry.scope,
parent_name - child->atts.entry.scope -
parent_scope = g_strndup (child->scope,
parent_name - child->scope -
separator_len);
}
/*g_debug ("%s: parent_name = %s", G_STRFUNC, parent_name);
g_debug ("%s: parent_scope = %s", G_STRFUNC, parent_scope);*/
GGD_PTR_ARRAY_FOR (tags, i, el) {
if (! (el->type & tm_tag_file_t) &&
(utils_str_equal (el->name, parent_name) &&
utils_str_equal (el->atts.entry.scope, parent_scope) &&
el->atts.entry.line <= child->atts.entry.line)) {
utils_str_equal (el->scope, parent_scope) &&
el->line <= child->line)) {
tag = el;
}
}
Expand Down
14 changes: 7 additions & 7 deletions geanygendoc/src/ggd.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,20 @@ get_env_for_tag (GgdFileType *ft,
ctpl_environ_push_string (env, "cursor", GGD_CURSOR_IDENTIFIER);
ctpl_environ_push_string (env, "symbol", tag->name);
/* get argument list it it exists */
if (tag->atts.entry.arglist) {
if (tag->arglist) {
CtplValue *v;

v = get_arg_list_from_string (ft, tag->atts.entry.arglist);
v = get_arg_list_from_string (ft, tag->arglist);
if (v) {
ctpl_environ_push (env, "argument_list", v);
ctpl_value_free (v);
}
}
/* get return type -- no matter if the return concept is pointless for that
* particular tag, it's up to the rule to use it when it makes sense */
returns = ! (tag->atts.entry.var_type != NULL &&
returns = ! (tag->var_type != NULL &&
/* C-style none return type hack */
strcmp ("void", tag->atts.entry.var_type) == 0);
strcmp ("void", tag->var_type) == 0);
ctpl_environ_push_int (env, "returns", returns);
/* get direct children tags */
children = ggd_tag_find_children (tag_array, tag,
Expand Down Expand Up @@ -344,13 +344,13 @@ do_insert_comment (GeanyDocument *doc,

switch (setting->position) {
case GGD_POS_AFTER:
pos = sci_get_line_end_position (sci, tag->atts.entry.line - 1);
pos = sci_get_line_end_position (sci, tag->line - 1);
break;

case GGD_POS_BEFORE: {
gint line;

line = tag->atts.entry.line - 1;
line = tag->line - 1;
line = adjust_start_line (sci, tag_array, tag, line);
pos = sci_get_position_from_line (sci, line);
if (GGD_OPT_indent) {
Expand Down Expand Up @@ -487,7 +487,7 @@ insert_multiple_comments (GeanyDocument *doc,
msgwin_status_add (_("No setting applies to symbol \"%s\" of type \"%s\" "
"at line %lu."),
tag->name, ggd_tag_get_type_name (tag),
tag->atts.entry.line);
tag->line);
}
}
sci_end_undo_action (sci);
Expand Down
2 changes: 1 addition & 1 deletion geanyprj/src/geanyprj.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#include "geanyprj.h"

PLUGIN_VERSION_CHECK(147)
PLUGIN_VERSION_CHECK(221)
PLUGIN_SET_INFO(_("Project"), _("Alternative project support."), VERSION,
"Yura Siamashka <yurand2@gmail.com>")

Expand Down
68 changes: 45 additions & 23 deletions geanyprj/src/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ gboolean (*project_type_filter[NEW_PROJECT_TYPE_SIZE]) (const gchar *) = {

static void free_tag_object(gpointer obj)
{
tm_workspace_remove_object((TMWorkObject *) obj, TRUE, FALSE);
if (obj != NULL)
{
tm_workspace_remove_source_file((TMSourceFile *) obj);
tm_source_file_free((TMSourceFile *) obj);
}
}


Expand All @@ -101,7 +105,7 @@ struct GeanyPrj *geany_project_new(void)
struct GeanyPrj *geany_project_load(const gchar *path)
{
struct GeanyPrj *ret;
TMWorkObject *tm_obj = NULL;
TMSourceFile *tm_obj = NULL;
GKeyFile *config;
gint i = 0;
gchar *file;
Expand Down Expand Up @@ -153,20 +157,22 @@ struct GeanyPrj *geany_project_load(const gchar *path)
}
else
{
GPtrArray *to_add = g_ptr_array_new();

/* Create tag files */
key = g_strdup_printf("file%d", i);
while ((file = g_key_file_get_string(config, "files", key, NULL)))
{
filename = get_full_path(path, file);

locale_filename = utils_get_locale_from_utf8(filename);
tm_obj = tm_source_file_new(locale_filename, FALSE,
tm_obj = tm_source_file_new(locale_filename,
filetypes_detect_from_file(filename)->name);
g_free(locale_filename);
if (tm_obj)
{
g_hash_table_insert(ret->tags, filename, tm_obj);
tm_source_file_update(tm_obj, TRUE, FALSE, TRUE);
g_ptr_array_add(to_add, tm_obj);
}
else
g_free(filename);
Expand All @@ -175,33 +181,45 @@ struct GeanyPrj *geany_project_load(const gchar *path)
g_free(file);
key = g_strdup_printf("file%d", i);
}
tm_workspace_add_source_files(to_add);
g_ptr_array_free(to_add, TRUE);
g_free(key);
}
g_key_file_free(config);
return ret;
}


#if !GLIB_CHECK_VERSION(2, 12, 0)
static gboolean get_true(gpointer key, gpointer value, gpointer user_data)
{
return TRUE;
}


static void g_hash_table_remove_all(GHashTable *hash_table)
static void remove_all_tags(struct GeanyPrj *prj)
{
g_hash_table_foreach_remove(hash_table, get_true, NULL);
GPtrArray *to_remove, *keys;
GHashTableIter iter;
gpointer key, value;

/* instead of relatively slow removal of source files by one from the tag manager,
* use the bulk operations - this requires that the normal destroy function
* of GHashTable is skipped - steal the keys and values and handle them manually */
to_remove = g_ptr_array_new_with_free_func((GFreeFunc)tm_source_file_free);
keys = g_ptr_array_new_with_free_func(g_free);
g_hash_table_iter_init(&iter, prj->tags);
while (g_hash_table_iter_next(&iter, &key, &value))
{
g_ptr_array_add(to_remove, value);
g_ptr_array_add(keys, key);
}
tm_workspace_remove_source_files(to_remove);
g_hash_table_steal_all(prj->tags);
g_ptr_array_free(to_remove, TRUE);
g_ptr_array_free(keys, TRUE);
}
#endif


void geany_project_regenerate_file_list(struct GeanyPrj *prj)
{
GSList *lst;

debug("%s path=%s\n", __FUNCTION__, prj->base_path);
g_hash_table_remove_all(prj->tags);
remove_all_tags(prj);

lst = get_file_list(prj->base_path, NULL, project_type_filter[prj->type], NULL);
geany_project_set_tags_from_list(prj, lst);
Expand Down Expand Up @@ -298,24 +316,25 @@ void geany_project_set_tags_from_list(struct GeanyPrj *prj, GSList *files)
{
GSList *tmp;
gchar *locale_filename;
TMWorkObject *tm_obj = NULL;
TMSourceFile *tm_obj = NULL;
GPtrArray *to_add = g_ptr_array_new();

if (prj->tags)
g_hash_table_destroy(prj->tags);
prj->tags = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_tag_object);

for (tmp = files; tmp != NULL; tmp = g_slist_next(tmp))
{
locale_filename = utils_get_locale_from_utf8(tmp->data);
tm_obj = tm_source_file_new(locale_filename, FALSE,
tm_obj = tm_source_file_new(locale_filename,
filetypes_detect_from_file(tmp->data)->name);
g_free(locale_filename);
if (tm_obj)
{
g_hash_table_insert(prj->tags, g_strdup(tmp->data), tm_obj);
tm_source_file_update(tm_obj, TRUE, FALSE, TRUE);
g_ptr_array_add(to_add, tm_obj);
}
}
tm_workspace_add_source_files(to_add);
g_ptr_array_free(to_add, TRUE);
}


Expand All @@ -335,7 +354,10 @@ void geany_project_free(struct GeanyPrj *prj)
if (prj->run_cmd)
g_free(prj->run_cmd);
if (prj->tags)
{
remove_all_tags(prj);
g_hash_table_destroy(prj->tags);
}

g_free(prj);
}
Expand All @@ -344,7 +366,7 @@ void geany_project_free(struct GeanyPrj *prj)
gboolean geany_project_add_file(struct GeanyPrj *prj, const gchar *path)
{
gchar *filename;
TMWorkObject *tm_obj = NULL;
TMSourceFile *tm_obj = NULL;

GKeyFile *config;

Expand All @@ -363,12 +385,12 @@ gboolean geany_project_add_file(struct GeanyPrj *prj, const gchar *path)
g_key_file_free(config);

filename = utils_get_locale_from_utf8(path);
tm_obj = tm_source_file_new(filename, FALSE, filetypes_detect_from_file(path)->name);
tm_obj = tm_source_file_new(filename, filetypes_detect_from_file(path)->name);
g_free(filename);
if (tm_obj)
{
g_hash_table_insert(prj->tags, g_strdup(path), tm_obj);
tm_source_file_update(tm_obj, TRUE, FALSE, TRUE);
tm_workspace_add_source_file(tm_obj);
}
geany_project_save(prj);
return TRUE;
Expand Down
Loading

0 comments on commit 28edfa8

Please sign in to comment.