New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TM cleanups #957
TM cleanups #957
Changes from 1 commit
f61a64b
7be40f5
1de1398
75c5cb6
4dcc829
103d2c5
1c4aaa0
b72b859
aea7d78
5d9376e
2bdc967
7411f9b
056e53c
fdc4510
4036d7d
0833974
f147f36
9b188a2
c05e3ea
8c27ea1
9ae93e3
bd9d26a
084c23b
7fe549d
b959801
6e89ee5
379eefa
27e4455
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,35 @@ gchar *tm_get_real_path(const gchar *file_name) | |
return NULL; | ||
} | ||
|
||
/* add argument list of __init__() Python methods to the class tag */ | ||
static void update_python_arglist(const TMTag *tag) | ||
{ | ||
guint i; | ||
const char *parent_tag_name; | ||
|
||
if (tag->type != tm_tag_method_t || tag->scope == NULL || | ||
g_strcmp0(tag->name, "__init__") != 0) | ||
return; | ||
|
||
parent_tag_name = strrchr(tag->scope, '.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: doesn't support the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, it seemed unused so I dropped it. |
||
if (parent_tag_name) | ||
parent_tag_name++; | ||
else | ||
parent_tag_name = tag->scope; | ||
|
||
/* going in reverse order because the tag was added recently */ | ||
for (i = current_source_file->tags_array->len; i > 0; i--) | ||
{ | ||
TMTag *prev_tag = (TMTag *) current_source_file->tags_array->pdata[i - 1]; | ||
if (g_strcmp0(prev_tag->name, parent_tag_name) == 0) | ||
{ | ||
g_free(prev_tag->arglist); | ||
prev_tag->arglist = g_strdup(tag->arglist); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
/* | ||
This function is registered into the ctags parser when a file is parsed for | ||
the first time. The function is then called by the ctags parser each time | ||
|
@@ -119,34 +148,15 @@ static int tm_source_file_tags(const tagEntryInfo *tag) | |
{ | ||
if (NULL == current_source_file) | ||
return 0; | ||
g_ptr_array_add(current_source_file->tags_array, | ||
tm_tag_new(current_source_file, tag)); | ||
return TRUE; | ||
} | ||
|
||
/* Set the argument list of tag identified by its name */ | ||
static void tm_source_file_set_tag_arglist(const char *tag_name, const char *arglist) | ||
{ | ||
guint i; | ||
TMTag *tm_tag = tm_tag_new(current_source_file, tag); | ||
|
||
if (NULL == arglist || | ||
NULL == tag_name || | ||
NULL == current_source_file) | ||
{ | ||
return; | ||
} | ||
if (tm_tag->lang == TM_PARSER_PYTHON) | ||
update_python_arglist(tm_tag); | ||
|
||
/* going in reverse order because the tag was added recently */ | ||
for (i = current_source_file->tags_array->len; i > 0; i--) | ||
{ | ||
TMTag *tag = (TMTag *) current_source_file->tags_array->pdata[i - 1]; | ||
if (g_strcmp0(tag->name, tag_name) == 0) | ||
{ | ||
g_free(tag->arglist); | ||
tag->arglist = g_strdup(arglist); | ||
break; | ||
} | ||
} | ||
g_ptr_array_add(current_source_file->tags_array, tm_tag); | ||
|
||
return TRUE; | ||
} | ||
|
||
/* Initializes a TMSourceFile structure from a file name. */ | ||
|
@@ -189,8 +199,6 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_ | |
installLanguageMapDefaults(); | ||
if (NULL == TagEntryFunction) | ||
TagEntryFunction = tm_source_file_tags; | ||
if (NULL == TagEntrySetArglistFunction) | ||
TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; | ||
} | ||
|
||
if (name == NULL) | ||
|
@@ -339,8 +347,6 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize | |
installLanguageMapDefaults(); | ||
if (NULL == TagEntryFunction) | ||
TagEntryFunction = tm_source_file_tags; | ||
if (NULL == TagEntrySetArglistFunction) | ||
TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; | ||
} | ||
current_source_file = source_file; | ||
if (! LanguageTable [source_file->lang]->enabled) | ||
|
@@ -407,8 +413,6 @@ const gchar *tm_source_file_get_lang_name(TMParserType lang) | |
installLanguageMapDefaults(); | ||
if (NULL == TagEntryFunction) | ||
TagEntryFunction = tm_source_file_tags; | ||
if (NULL == TagEntrySetArglistFunction) | ||
TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; | ||
} | ||
return getLanguageName(lang); | ||
} | ||
|
@@ -425,8 +429,6 @@ TMParserType tm_source_file_get_named_lang(const gchar *name) | |
installLanguageMapDefaults(); | ||
if (NULL == TagEntryFunction) | ||
TagEntryFunction = tm_source_file_tags; | ||
if (NULL == TagEntrySetArglistFunction) | ||
TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; | ||
} | ||
return getNamedLanguage(name); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmwell, this is pretty specific to the Python parser and not well-contained, but well, probably still better than a whole new hook indeed.
BTW, this might be fixable in the parser side using the U-CTags' new Cork thingie? Not sure and not tested, but that would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find it a big problem - Geany is full of if (language) {do stuff} things and this is just one more (and IMO much cleaner than the direct parser->TM callback).
I haven't checked what the cork thing in uctags does so not sure either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Geany will become un-maintainable if its filled with
if(language){do stuff }
sections. The attention should be removing them not adding "just one more".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you have a look how it's done now, it's much worse and much more unmaintainable than this - it introduces diff to the python parser compared to universal-ctags and worse, it makes a very strange direct path python_parser->TM (no other parser does this, all of them generate tags the standard way).
Such a strange callback would definitely not become part of ctags API if it's ever turned into a library so we'd have to maintain our own version. The "just one more" is very well justified in this case IMO (other option is not to add the constructor parameters to the class type and drop this feature).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then how does u-ctags do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uctags doesn't do (and in fact cannot do) anything - it was added by Enrico in 1932d3f. The purpose of it is for:
to use the tag for its init() and copy its argument list to the tag of Foo so when you type
you get completion based on the Foo's init(). Thing like that cannot be done in uctags because at the time init() is parsed, the Foo tag is already written to disk and cannot be modified to include the arguments of init().