Skip to content

Commit

Permalink
Merge PR#356 from 'b4n/techee/tm'
Browse files Browse the repository at this point in the history
Huge TagManager improvements
  • Loading branch information
b4n committed Nov 8, 2014
2 parents ba8ff71 + fd4f31c commit 8c77acc
Show file tree
Hide file tree
Showing 35 changed files with 1,575 additions and 2,495 deletions.
2 changes: 0 additions & 2 deletions doc/Doxyfile.in
Expand Up @@ -778,8 +778,6 @@ INPUT = @top_srcdir@/src/ \
@top_srcdir@/plugins/geanyfunctions.h \
@top_srcdir@/tagmanager/src/tm_source_file.c \
@top_srcdir@/tagmanager/src/tm_source_file.h \
@top_srcdir@/tagmanager/src/tm_work_object.c \
@top_srcdir@/tagmanager/src/tm_work_object.h \
@top_srcdir@/tagmanager/src/tm_workspace.c \
@top_srcdir@/tagmanager/src/tm_workspace.h

Expand Down
1 change: 0 additions & 1 deletion doc/Makefile.am
Expand Up @@ -98,7 +98,6 @@ doxygen_sources = \
$(top_srcdir)/plugins/geanyplugin.h \
$(top_srcdir)/plugins/geanyfunctions.h \
$(top_srcdir)/tagmanager/src/tm_source_file.[ch] \
$(top_srcdir)/tagmanager/src/tm_work_object.[ch] \
$(top_srcdir)/tagmanager/src/tm_workspace.[ch]

Doxyfile.stamp: Doxyfile $(doxygen_sources)
Expand Down
18 changes: 10 additions & 8 deletions plugins/geanyfunctions.h
Expand Up @@ -346,14 +346,16 @@
geany_functions->p_tm->tm_get_real_path
#define tm_source_file_new \
geany_functions->p_tm->tm_source_file_new
#define tm_workspace_add_object \
geany_functions->p_tm->tm_workspace_add_object
#define tm_source_file_update \
geany_functions->p_tm->tm_source_file_update
#define tm_work_object_free \
geany_functions->p_tm->tm_work_object_free
#define tm_workspace_remove_object \
geany_functions->p_tm->tm_workspace_remove_object
#define tm_source_file_free \
geany_functions->p_tm->tm_source_file_free
#define tm_workspace_add_source_file \
geany_functions->p_tm->tm_workspace_add_source_file
#define tm_workspace_remove_source_file \
geany_functions->p_tm->tm_workspace_remove_source_file
#define tm_workspace_add_source_files \
geany_functions->p_tm->tm_workspace_add_source_files
#define tm_workspace_remove_source_files \
geany_functions->p_tm->tm_workspace_remove_source_files
#define search_show_find_in_files_dialog \
geany_functions->p_search->search_show_find_in_files_dialog
#define highlighting_get_style \
Expand Down
10 changes: 7 additions & 3 deletions src/dialogs.c
Expand Up @@ -501,9 +501,13 @@ static gboolean handle_save_as(const gchar *utf8_filename, gboolean rename_file)
{
document_rename_file(doc, utf8_filename);
}
/* create a new tm_source_file object otherwise tagmanager won't work correctly */
tm_workspace_remove_object(doc->tm_file, TRUE, TRUE);
doc->tm_file = NULL;
if (doc->tm_file)
{
/* create a new tm_source_file object otherwise tagmanager won't work correctly */
tm_workspace_remove_source_file(doc->tm_file);
tm_source_file_free(doc->tm_file);
doc->tm_file = NULL;
}
}
success = document_save_file_as(doc, utf8_filename);

Expand Down
40 changes: 16 additions & 24 deletions src/document.c
Expand Up @@ -140,7 +140,7 @@ static GtkWidget* document_show_message(GeanyDocument *doc, GtkMessageType msgty
* string returned by @c tm_get_real_path().
*
* @return The matching document, or @c NULL.
* @note This is only really useful when passing a @c TMWorkObject::file_name.
* @note This is only really useful when passing a @c TMSourceFile::file_name.
* @see GeanyDocument::real_path.
* @see document_find_by_filename().
*
Expand Down Expand Up @@ -714,7 +714,11 @@ static gboolean remove_page(guint page_num)
g_free(doc->priv->saved_encoding.encoding);
g_free(doc->file_name);
g_free(doc->real_path);
tm_workspace_remove_object(doc->tm_file, TRUE, !main_status.quitting);
if (doc->tm_file)
{
tm_workspace_remove_source_file(doc->tm_file);
tm_source_file_free(doc->tm_file);
}

if (doc->priv->tag_tree)
gtk_widget_destroy(doc->priv->tag_tree);
Expand Down Expand Up @@ -2483,17 +2487,14 @@ void document_update_tags(GeanyDocument *doc)

/* lookup the name rather than using filetype name to support custom filetypes */
name = tm_source_file_get_lang_name(doc->file_type->lang);
doc->tm_file = tm_source_file_new(locale_filename, FALSE, name);
doc->tm_file = tm_source_file_new(locale_filename, name);
g_free(locale_filename);

if (doc->tm_file && !tm_workspace_add_object(doc->tm_file))
{
tm_work_object_free(doc->tm_file);
doc->tm_file = NULL;
}
if (doc->tm_file)
tm_workspace_add_source_file_noupdate(doc->tm_file);
}

/* early out if there's no work object and we couldn't create one */
/* early out if there's no tm source file and we couldn't create one */
if (doc->tm_file == NULL)
{
/* We must call sidebar_update_tag_list() before returning,
Expand All @@ -2503,20 +2504,11 @@ void document_update_tags(GeanyDocument *doc)
return;
}

len = sci_get_length(doc->editor->sci);
/* tm_source_file_buffer_update() below don't support 0-length data,
* so just empty the tags array and leave */
if (len < 1)
{
tm_tags_array_free(doc->tm_file->tags_array, FALSE);
sidebar_update_tag_list(doc, FALSE);
return;
}

/* Parse Scintilla's buffer directly using TagManager
* Note: this buffer *MUST NOT* be modified */
len = sci_get_length(doc->editor->sci);
buffer_ptr = (guchar *) scintilla_send_message(doc->editor->sci, SCI_GETCHARACTERPOINTER, 0, 0);
tm_source_file_buffer_update(doc->tm_file, buffer_ptr, len, TRUE);
tm_workspace_update_source_file_buffer(doc->tm_file, buffer_ptr, len);

sidebar_update_tag_list(doc, TRUE);
document_highlight_tags(doc);
Expand Down Expand Up @@ -2555,13 +2547,12 @@ void document_highlight_tags(GeanyDocument *doc)
default:
return; /* early out if type keywords are not supported */
}
if (!app->tm_workspace->work_object.tags_array)
if (!app->tm_workspace->tags_array)
return;

/* get any type keywords and tell scintilla about them
* this will cause the type keywords to be colourized in scintilla */
keywords_str = symbols_find_tags_as_string(app->tm_workspace->work_object.tags_array,
TM_GLOBAL_TYPE_MASK, doc->file_type->lang);
keywords_str = symbols_find_typenames_as_string(doc->file_type->lang, FALSE);
if (keywords_str)
{
keywords = g_string_free(keywords_str, FALSE);
Expand Down Expand Up @@ -2617,7 +2608,8 @@ static void document_load_config(GeanyDocument *doc, GeanyFiletype *type,
/* delete tm file object to force creation of a new one */
if (doc->tm_file != NULL)
{
tm_workspace_remove_object(doc->tm_file, TRUE, TRUE);
tm_workspace_remove_source_file(doc->tm_file);
tm_source_file_free(doc->tm_file);
doc->tm_file = NULL;
}
/* load tags files before highlighting (some lexers highlight global typenames) */
Expand Down
4 changes: 2 additions & 2 deletions src/document.h
Expand Up @@ -93,8 +93,8 @@ typedef struct GeanyDocument
/** The filetype for this document, it's only a reference to one of the elements of the global
* filetypes array. */
GeanyFiletype *file_type;
/** TMWorkObject object for this document, or @c NULL. */
TMWorkObject *tm_file;
/** TMSourceFile object for this document, or @c NULL. */
TMSourceFile *tm_file;
/** Whether this document is read-only. */
gboolean readonly;
/** Whether this document has been changed since it was last saved. */
Expand Down
32 changes: 16 additions & 16 deletions src/editor.c
Expand Up @@ -639,7 +639,7 @@ static void show_tags_list(GeanyEditor *editor, const GPtrArray *tags, gsize roo
g_string_append(words, tag->name);

/* for now, tag types don't all follow C, so just look at arglist */
if (!EMPTY(tag->atts.entry.arglist))
if (!EMPTY(tag->arglist))
g_string_append(words, "?2");
else
g_string_append(words, "?1");
Expand Down Expand Up @@ -732,10 +732,10 @@ static void autocomplete_scope(GeanyEditor *editor)
return;

tag = g_ptr_array_index(tags, 0);
name = tag->atts.entry.var_type;
name = tag->var_type;
if (name)
{
TMWorkObject *obj = editor->document->tm_file;
TMSourceFile *obj = editor->document->tm_file;

tags = tm_workspace_find_scope_members(obj ? obj->tags_array : NULL,
name, TRUE, FALSE);
Expand Down Expand Up @@ -1784,43 +1784,43 @@ static gint find_start_bracket(ScintillaObject *sci, gint pos)

static gboolean append_calltip(GString *str, const TMTag *tag, filetype_id ft_id)
{
if (! tag->atts.entry.arglist)
if (! tag->arglist)
return FALSE;

if (ft_id != GEANY_FILETYPES_PASCAL)
{ /* usual calltips: "retval tagname (arglist)" */
if (tag->atts.entry.var_type)
if (tag->var_type)
{
guint i;

g_string_append(str, tag->atts.entry.var_type);
for (i = 0; i < tag->atts.entry.pointerOrder; i++)
g_string_append(str, tag->var_type);
for (i = 0; i < tag->pointerOrder; i++)
{
g_string_append_c(str, '*');
}
g_string_append_c(str, ' ');
}
if (tag->atts.entry.scope)
if (tag->scope)
{
const gchar *cosep = symbols_get_context_separator(ft_id);

g_string_append(str, tag->atts.entry.scope);
g_string_append(str, tag->scope);
g_string_append(str, cosep);
}
g_string_append(str, tag->name);
g_string_append_c(str, ' ');
g_string_append(str, tag->atts.entry.arglist);
g_string_append(str, tag->arglist);
}
else
{ /* special case Pascal calltips: "tagname (arglist) : retval" */
g_string_append(str, tag->name);
g_string_append_c(str, ' ');
g_string_append(str, tag->atts.entry.arglist);
g_string_append(str, tag->arglist);

if (!EMPTY(tag->atts.entry.var_type))
if (!EMPTY(tag->var_type))
{
g_string_append(str, " : ");
g_string_append(str, tag->atts.entry.var_type);
g_string_append(str, tag->var_type);
}
}

Expand All @@ -1831,7 +1831,7 @@ static gboolean append_calltip(GString *str, const TMTag *tag, filetype_id ft_id
static gchar *find_calltip(const gchar *word, GeanyFiletype *ft)
{
const GPtrArray *tags;
const gint arg_types = tm_tag_function_t | tm_tag_prototype_t |
const TMTagType arg_types = tm_tag_function_t | tm_tag_prototype_t |
tm_tag_method_t | tm_tag_macro_with_arg_t;
TMTagAttrType *attrs = NULL;
TMTag *tag;
Expand Down Expand Up @@ -1862,7 +1862,7 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft)
{
tag = TM_TAG(tags->pdata[i]);

if (! tag->atts.entry.arglist)
if (! tag->arglist)
tags->pdata[i] = NULL;
}
tm_tags_prune((GPtrArray *) tags);
Expand All @@ -1873,7 +1873,7 @@ static gchar *find_calltip(const gchar *word, GeanyFiletype *ft)
TMTagAttrType sort_attr[] = {tm_tag_attr_name_t, tm_tag_attr_scope_t,
tm_tag_attr_arglist_t, 0};

tm_tags_sort((GPtrArray *) tags, sort_attr, TRUE);
tm_tags_sort((GPtrArray *) tags, sort_attr, TRUE, FALSE);
}

/* if the current word has changed since last time, start with the first tag match */
Expand Down
19 changes: 1 addition & 18 deletions src/highlighting.c
Expand Up @@ -433,23 +433,6 @@ void highlighting_free_styles(void)
}


static GString *get_global_typenames(gint lang)
{
GString *s = NULL;

if (app->tm_workspace)
{
GPtrArray *tags_array = app->tm_workspace->global_tags;

if (tags_array)
{
s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK, lang);
}
}
return s;
}


static gchar*
get_keyfile_whitespace_chars(GKeyFile *config, GKeyFile *configh)
{
Expand Down Expand Up @@ -823,7 +806,7 @@ static void merge_type_keywords(ScintillaObject *sci, guint ft_id, guint keyword
const gchar *user_words = style_sets[ft_id].keywords[keyword_idx];
GString *s;

s = get_global_typenames(filetypes[ft_id]->lang);
s = symbols_find_typenames_as_string(filetypes[ft_id]->lang, TRUE);
if (G_UNLIKELY(s == NULL))
s = g_string_sized_new(200);
else
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Expand Up @@ -1289,7 +1289,7 @@ static void do_main_quit(void)
filetypes_free_types();
log_finalize();

tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
tm_workspace_free();
g_free(app->configdir);
g_free(app->datadir);
g_free(app->docdir);
Expand Down
16 changes: 8 additions & 8 deletions src/plugindata.h
Expand Up @@ -58,7 +58,7 @@ G_BEGIN_DECLS
* @warning You should not test for values below 200 as previously
* @c GEANY_API_VERSION was defined as an enum value, not a macro.
*/
#define GEANY_API_VERSION 220
#define GEANY_API_VERSION 221

/* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins
* with GTK3-linked Geany leads to crash */
Expand All @@ -72,7 +72,7 @@ G_BEGIN_DECLS
* Changing this forces all plugins to be recompiled before Geany can load them. */
/* This should usually stay the same if fields are only appended, assuming only pointers to
* structs and not structs themselves are declared by plugins. */
#define GEANY_ABI_VERSION (69 << GEANY_ABI_SHIFT)
#define GEANY_ABI_VERSION (70 << GEANY_ABI_SHIFT)


/** Defines a function to check the plugin is safe to load.
Expand Down Expand Up @@ -599,12 +599,12 @@ SearchFuncs;
typedef struct TagManagerFuncs
{
gchar* (*tm_get_real_path) (const gchar *file_name);
TMWorkObject* (*tm_source_file_new) (const char *file_name, gboolean update, const char *name);
gboolean (*tm_workspace_add_object) (TMWorkObject *work_object);
gboolean (*tm_source_file_update) (TMWorkObject *source_file, gboolean force,
gboolean recurse, gboolean update_parent);
void (*tm_work_object_free) (gpointer work_object);
gboolean (*tm_workspace_remove_object) (TMWorkObject *w, gboolean do_free, gboolean update);
TMSourceFile* (*tm_source_file_new) (const char *file_name, const char *name);
void (*tm_source_file_free) (TMSourceFile *source_file);
void (*tm_workspace_add_source_file) (TMSourceFile *source_file);
void (*tm_workspace_remove_source_file) (TMSourceFile *source_file);
void (*tm_workspace_add_source_files) (GPtrArray *source_files);
void (*tm_workspace_remove_source_files) (GPtrArray *source_files);
}
TagManagerFuncs;

Expand Down
9 changes: 5 additions & 4 deletions src/plugins.c
Expand Up @@ -290,10 +290,11 @@ static KeybindingFuncs keybindings_funcs = {
static TagManagerFuncs tagmanager_funcs = {
&tm_get_real_path,
&tm_source_file_new,
&tm_workspace_add_object,
&tm_source_file_update,
&tm_work_object_free,
&tm_workspace_remove_object
&tm_source_file_free,
&tm_workspace_add_source_file,
&tm_workspace_remove_source_file,
&tm_workspace_add_source_files,
&tm_workspace_remove_source_files
};

static SearchFuncs search_funcs = {
Expand Down
2 changes: 1 addition & 1 deletion src/sidebar.c
Expand Up @@ -904,7 +904,7 @@ static gboolean taglist_go_to_selection(GtkTreeSelection *selection, guint keyva
if (! tag)
return FALSE;

line = tag->atts.entry.line;
line = tag->line;
if (line > 0)
{
GeanyDocument *doc = document_get_current();
Expand Down

0 comments on commit 8c77acc

Please sign in to comment.