[geany/geany] 0285ec: Move tm_source_file_update() to tm_workspace.c
Jiří Techet
git-noreply at xxxxx
Thu Oct 30 21:08:17 UTC 2014
Branch: refs/heads/master
Author: Jiří Techet <techet at gmail.com>
Committer: Jiří Techet <techet at gmail.com>
Date: Thu, 30 Oct 2014 21:08:17 UTC
Commit: 0285ec28a5c813cd5c82b1ad390b584e122c1873
https://github.com/geany/geany/commit/0285ec28a5c813cd5c82b1ad390b584e122c1873
Log Message:
-----------
Move tm_source_file_update() to tm_workspace.c
The placement of this function in tm_source_file is not right - by moving
it to the workspace we can make the source file unaware of the existence
of the workspace (no inclusion of tm_workspace.h in tm_source_file any
more). Also change tm_source_file_new() so it doesn't offer the source file
update.
After this change
* TMWorkspace knows TMSourceFile and TMTag
* TMSourceFile knows TMTag
* TMTag knows TMSourceFile
Modified Paths:
--------------
plugins/geanyfunctions.h
src/document.c
src/plugindata.h
src/plugins.c
tagmanager/src/tm_source_file.c
tagmanager/src/tm_source_file.h
tagmanager/src/tm_workspace.c
tagmanager/src/tm_workspace.h
Modified: plugins/geanyfunctions.h
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -348,8 +348,8 @@
geany_functions->p_tm->tm_source_file_new
#define tm_workspace_add_source_file \
geany_functions->p_tm->tm_workspace_add_source_file
-#define tm_source_file_update \
- geany_functions->p_tm->tm_source_file_update
+#define tm_workspace_update_source_file \
+ geany_functions->p_tm->tm_workspace_update_source_file
#define tm_source_file_free \
geany_functions->p_tm->tm_source_file_free
#define tm_workspace_remove_source_file \
Modified: src/document.c
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -2483,7 +2483,7 @@ 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_source_file(doc->tm_file))
@@ -2516,7 +2516,7 @@ void document_update_tags(GeanyDocument *doc)
/* Parse Scintilla's buffer directly using TagManager
* Note: this buffer *MUST NOT* be modified */
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, TRUE);
sidebar_update_tag_list(doc, TRUE);
document_highlight_tags(doc);
Modified: src/plugindata.h
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -599,9 +599,9 @@ SearchFuncs;
typedef struct TagManagerFuncs
{
gchar* (*tm_get_real_path) (const gchar *file_name);
- TMSourceFile* (*tm_source_file_new) (const char *file_name, gboolean update, const char *name);
+ TMSourceFile* (*tm_source_file_new) (const char *file_name, const char *name);
gboolean (*tm_workspace_add_source_file) (TMSourceFile *source_file);
- void (*tm_source_file_update) (TMSourceFile *source_file, gboolean update_workspace);
+ void (*tm_workspace_update_source_file) (TMSourceFile *source_file, gboolean update_workspace);
void (*tm_source_file_free) (TMSourceFile *source_file);
gboolean (*tm_workspace_remove_source_file) (TMSourceFile *source_file, gboolean do_free, gboolean update);
void (*tm_workspace_update) (void);
Modified: src/plugins.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -291,7 +291,7 @@ static TagManagerFuncs tagmanager_funcs = {
&tm_get_real_path,
&tm_source_file_new,
&tm_workspace_add_source_file,
- &tm_source_file_update,
+ &tm_workspace_update_source_file,
&tm_source_file_free,
&tm_workspace_remove_source_file,
&tm_workspace_update
Modified: tagmanager/src/tm_source_file.c
102 lines changed, 6 insertions(+), 96 deletions(-)
===================================================================
@@ -30,9 +30,8 @@
#include "entry.h"
#include "parse.h"
#include "read.h"
-#define LIBCTAGS_DEFINED
-#include "tm_workspace.h"
+#define LIBCTAGS_DEFINED
#include "tm_source_file.h"
#include "tm_tag.h"
@@ -143,7 +142,7 @@ static void tm_source_file_set_tag_arglist(const char *tag_name, const char *arg
/* Initializes a TMSourceFile structure from a file name. */
static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_name,
- gboolean update, const char* name)
+ const char* name)
{
struct stat s;
int status;
@@ -190,21 +189,18 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_
else
source_file->lang = getNamedLanguage(name);
- if (update)
- tm_source_file_update(source_file, FALSE);
return TRUE;
}
/** Initializes a TMSourceFile structure and returns a pointer to it.
* @param file_name The file name.
- * @param update Update the tag array of the file.
* @param name Name of the used programming language, NULL for autodetection.
* @return The created TMSourceFile object.
* */
-TMSourceFile *tm_source_file_new(const char *file_name, gboolean update, const char *name)
+TMSourceFile *tm_source_file_new(const char *file_name, const char *name)
{
TMSourceFile *source_file = g_new(TMSourceFile, 1);
- if (TRUE != tm_source_file_init(source_file, file_name, update, name))
+ if (TRUE != tm_source_file_init(source_file, file_name, name))
{
g_free(source_file);
return NULL;
@@ -243,9 +239,8 @@ void tm_source_file_free(TMSourceFile *source_file)
/* Parses the source file and regenarates the tags.
@param source_file The source file to parse
@return TRUE on success, FALSE on failure
- @see tm_source_file_update()
*/
-static gboolean tm_source_file_parse(TMSourceFile *source_file)
+gboolean tm_source_file_parse(TMSourceFile *source_file)
{
const char *file_name;
gboolean status = TRUE;
@@ -306,9 +301,8 @@ static gboolean tm_source_file_parse(TMSourceFile *source_file)
@param text_buf The text buffer to parse
@param buf_size The size of text_buf.
@return TRUE on success, FALSE on failure
- @see tm_source_file_update()
*/
-static gboolean tm_source_file_buffer_parse(TMSourceFile *source_file, guchar* text_buf, gint buf_size)
+gboolean tm_source_file_buffer_parse(TMSourceFile *source_file, guchar* text_buf, gint buf_size)
{
const char *file_name;
gboolean status = TRUE;
@@ -380,90 +374,6 @@ static gboolean tm_source_file_buffer_parse(TMSourceFile *source_file, guchar* t
return status;
}
-/** Updates the source file by reparsing. The tags array and
- the tags themselves are destroyed and re-created, hence any other tag arrays
- pointing to these tags should be rebuilt as well. All sorting information is
- also lost. The language parameter is automatically set the first time the file
- is parsed.
- @param source_file The source file to update.
- @param update_workspace If set to TRUE, sends an update signal to the workspace if required. You should
- always set this to TRUE if you are calling this function directly.
-*/
-void tm_source_file_update(TMSourceFile *source_file, gboolean update_workspace)
-{
-#ifdef TM_DEBUG
- g_message("Source file updating based on source file %s", source_file->file_name);
-#endif
-
- if (update_workspace)
- {
- /* tm_source_file_parse() deletes the tag objects - remove the tags from
- * workspace while they exist and can be scanned */
- tm_workspace_remove_file_tags(source_file);
- }
- tm_source_file_parse(source_file);
- tm_tags_sort(source_file->tags_array, NULL, FALSE);
- if (update_workspace)
- {
-#ifdef TM_DEBUG
- g_message("Updating workspace from source file");
-#endif
- tm_workspace_merge_file_tags(source_file);
- }
-#ifdef TM_DEBUG
- else
- g_message("Skipping workspace update because update_workspace is %s",
- update_workspace?"TRUE":"FALSE");
-
-#endif
-}
-
-
-/* Updates the source file by reparsing the text-buffer passed as parameter.
- Ctags will use a parsing based on buffer instead of on files.
- You should call this function when you don't want a previous saving of the file
- you're editing. It's useful for a "real-time" updating of the tags.
- The tags array and the tags themselves are destroyed and re-created, hence any
- other tag arrays pointing to these tags should be rebuilt as well. All sorting
- information is also lost. The language parameter is automatically set the first
- time the file is parsed.
- @param source_file The source file to update with a buffer.
- @param text_buf A text buffer. The user should take care of allocate and free it after
- the use here.
- @param buf_size The size of text_buf.
- @param update_workspace If set to TRUE, sends an update signal to the workspace if required. You should
- always set this to TRUE if you are calling this function directly.
- @return TRUE if the file was parsed, FALSE otherwise.
-*/
-void tm_source_file_buffer_update(TMSourceFile *source_file, guchar* text_buf,
- gint buf_size, gboolean update_workspace)
-{
-#ifdef TM_DEBUG
- g_message("Buffer updating based on source file %s", source_file->file_name);
-#endif
-
- if (update_workspace)
- {
- /* tm_source_file_parse() deletes the tag objects - remove the tags from
- * workspace while they exist and can be scanned */
- tm_workspace_remove_file_tags(source_file);
- }
- tm_source_file_buffer_parse (source_file, text_buf, buf_size);
- tm_tags_sort(source_file->tags_array, NULL, FALSE);
- if (update_workspace)
- {
-#ifdef TM_DEBUG
- g_message("Updating workspace from buffer..");
-#endif
- tm_workspace_merge_file_tags(source_file);
- }
-#ifdef TM_DEBUG
- else
- g_message("Skipping workspace update because update_workspace is %s",
- update_workspace?"TRUE":"FALSE");
-
-#endif
-}
/* Gets the name associated with the language index.
@param lang The language index.
Modified: tagmanager/src/tm_source_file.h
11 lines changed, 5 insertions(+), 6 deletions(-)
===================================================================
@@ -44,9 +44,7 @@ typedef struct
GPtrArray *tags_array; /**< Tags obtained by parsing the object */
} TMSourceFile;
-TMSourceFile *tm_source_file_new(const char *file_name, gboolean update, const char *name);
-
-void tm_source_file_update(TMSourceFile *source_file, gboolean update_workspace);
+TMSourceFile *tm_source_file_new(const char *file_name, const char *name);
void tm_source_file_free(TMSourceFile *source_file);
@@ -55,13 +53,14 @@ gchar *tm_get_real_path(const gchar *file_name);
#ifdef GEANY_PRIVATE
-void tm_source_file_buffer_update(TMSourceFile *source_file, guchar* text_buf,
- gint buf_size, gboolean update_workspace);
-
const gchar *tm_source_file_get_lang_name(gint lang);
gint tm_source_file_get_named_lang(const gchar *name);
+gboolean tm_source_file_parse(TMSourceFile *source_file);
+
+gboolean tm_source_file_buffer_parse(TMSourceFile *source_file, guchar* text_buf, gint buf_size);
+
#endif /* GEANY_PRIVATE */
#ifdef __cplusplus
Modified: tagmanager/src/tm_workspace.c
102 lines changed, 94 insertions(+), 8 deletions(-)
===================================================================
@@ -107,6 +107,12 @@ gboolean tm_workspace_add_source_file(TMSourceFile *source_file)
return TRUE;
}
+static void tm_workspace_remove_file_tags(TMSourceFile *source_file)
+{
+ if (theWorkspace->tags_array != NULL)
+ tm_tags_remove_file_tags(source_file, theWorkspace->tags_array);
+}
+
/** Removes a member object from the workspace if it exists.
@param source_file Pointer to the source file to be removed.
@param do_free Whether the source file is to be freed as well.
@@ -447,7 +453,8 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i
temp_file2 = temp_file;
temp_file = NULL;
}
- source_file = tm_source_file_new(temp_file2, TRUE, tm_source_file_get_lang_name(lang));
+ source_file = tm_source_file_new(temp_file2, tm_source_file_get_lang_name(lang));
+ tm_workspace_update_source_file(source_file, FALSE);
if (NULL == source_file)
{
g_unlink(temp_file2);
@@ -537,13 +544,7 @@ static void tm_workspace_recreate_tags_array(void)
tm_tags_sort(theWorkspace->tags_array, sort_attrs, TRUE);
}
-void tm_workspace_remove_file_tags(TMSourceFile *source_file)
-{
- if (theWorkspace->tags_array != NULL)
- tm_tags_remove_file_tags(source_file, theWorkspace->tags_array);
-}
-
-void tm_workspace_merge_file_tags(TMSourceFile *source_file)
+static void tm_workspace_merge_file_tags(TMSourceFile *source_file)
{
TMTagAttrType sort_attrs[] = { tm_tag_attr_name_t, tm_tag_attr_file_t,
tm_tag_attr_scope_t, tm_tag_attr_type_t, tm_tag_attr_arglist_t, 0};
@@ -561,6 +562,91 @@ void tm_workspace_merge_file_tags(TMSourceFile *source_file)
}
}
+/** Updates the source file by reparsing. The tags array and
+ the tags themselves are destroyed and re-created, hence any other tag arrays
+ pointing to these tags should be rebuilt as well. All sorting information is
+ also lost. The language parameter is automatically set the first time the file
+ is parsed.
+ @param source_file The source file to update.
+ @param update_workspace If set to TRUE, sends an update signal to the workspace if required. You should
+ always set this to TRUE if you are calling this function directly.
+*/
+void tm_workspace_update_source_file(TMSourceFile *source_file, gboolean update_workspace)
+{
+#ifdef TM_DEBUG
+ g_message("Source file updating based on source file %s", source_file->file_name);
+#endif
+
+ if (update_workspace)
+ {
+ /* tm_source_file_parse() deletes the tag objects - remove the tags from
+ * workspace while they exist and can be scanned */
+ tm_workspace_remove_file_tags(source_file);
+ }
+ tm_source_file_parse(source_file);
+ tm_tags_sort(source_file->tags_array, NULL, FALSE);
+ if (update_workspace)
+ {
+#ifdef TM_DEBUG
+ g_message("Updating workspace from source file");
+#endif
+ tm_workspace_merge_file_tags(source_file);
+ }
+#ifdef TM_DEBUG
+ else
+ g_message("Skipping workspace update because update_workspace is %s",
+ update_workspace?"TRUE":"FALSE");
+
+#endif
+}
+
+
+/* Updates the source file by reparsing the text-buffer passed as parameter.
+ Ctags will use a parsing based on buffer instead of on files.
+ You should call this function when you don't want a previous saving of the file
+ you're editing. It's useful for a "real-time" updating of the tags.
+ The tags array and the tags themselves are destroyed and re-created, hence any
+ other tag arrays pointing to these tags should be rebuilt as well. All sorting
+ information is also lost. The language parameter is automatically set the first
+ time the file is parsed.
+ @param source_file The source file to update with a buffer.
+ @param text_buf A text buffer. The user should take care of allocate and free it after
+ the use here.
+ @param buf_size The size of text_buf.
+ @param update_workspace If set to TRUE, sends an update signal to the workspace if required. You should
+ always set this to TRUE if you are calling this function directly.
+ @return TRUE if the file was parsed, FALSE otherwise.
+*/
+void tm_workspace_update_source_file_buffer(TMSourceFile *source_file, guchar* text_buf,
+ gint buf_size, gboolean update_workspace)
+{
+#ifdef TM_DEBUG
+ g_message("Buffer updating based on source file %s", source_file->file_name);
+#endif
+
+ if (update_workspace)
+ {
+ /* tm_source_file_parse() deletes the tag objects - remove the tags from
+ * workspace while they exist and can be scanned */
+ tm_workspace_remove_file_tags(source_file);
+ }
+ tm_source_file_buffer_parse (source_file, text_buf, buf_size);
+ tm_tags_sort(source_file->tags_array, NULL, FALSE);
+ if (update_workspace)
+ {
+#ifdef TM_DEBUG
+ g_message("Updating workspace from buffer..");
+#endif
+ tm_workspace_merge_file_tags(source_file);
+ }
+#ifdef TM_DEBUG
+ else
+ g_message("Skipping workspace update because update_workspace is %s",
+ update_workspace?"TRUE":"FALSE");
+
+#endif
+}
+
/** Calls tm_source_file_update() for all workspace member source files and creates
workspace tag array. Use if you want to globally refresh the workspace.
*/
Modified: tagmanager/src/tm_workspace.h
9 lines changed, 5 insertions(+), 4 deletions(-)
===================================================================
@@ -38,6 +38,8 @@ gboolean tm_workspace_add_source_file(TMSourceFile *source_file);
gboolean tm_workspace_remove_source_file(TMSourceFile *source_file, gboolean do_free, gboolean update);
+void tm_workspace_update_source_file(TMSourceFile *source_file, gboolean update_workspace);
+
void tm_workspace_update(void);
@@ -64,11 +66,10 @@ const GPtrArray *tm_workspace_find_scope_members(const GPtrArray *file_tags,
const TMTag *tm_get_current_tag(GPtrArray *file_tags, const gulong line, const guint tag_types);
-void tm_workspace_free(void);
-
-void tm_workspace_merge_file_tags(TMSourceFile *source_file);
+void tm_workspace_update_source_file_buffer(TMSourceFile *source_file, guchar* text_buf,
+ gint buf_size, gboolean update_workspace);
-void tm_workspace_remove_file_tags(TMSourceFile *source_file);
+void tm_workspace_free(void);
#ifdef TM_DEBUG
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list