Skip to content
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

Merged
merged 28 commits into from Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f61a64b
Remove the TagEntrySetArglistFunction hook
techee Jan 11, 2016
7be40f5
Initialize ctags at a single place instead of four
techee Mar 11, 2016
1de1398
Improve ctags callback API
techee Jan 11, 2016
75c5cb6
Use G_BEGIN_DECLS/G_END_DECLS
techee Mar 9, 2016
4dcc829
Remove unused tm_tagmanager.h
techee Mar 9, 2016
103d2c5
Move code related to various tag file formats into tm_source_file.c
techee Mar 10, 2016
1c4aaa0
Add an API-like ctags layer
techee Mar 9, 2016
b72b859
Clean up messy tm_workspace_create_global_tags()
techee Mar 11, 2016
aea7d78
Remove some unused return values and unnecessary checks
techee Mar 10, 2016
5d9376e
Add explicit mapping of ctags tag types to Geany tag types
techee Mar 22, 2016
2bdc967
Use proper C prototypes
b4n May 4, 2016
7411f9b
Remove an unused variable
b4n May 4, 2016
056e53c
Make our convenience libraries more self-contained
b4n May 4, 2016
fdc4510
Don't use char array subscript as it may be signed
b4n May 4, 2016
4036d7d
Remove not useless tm_source_file_ctags_init() indirection
b4n May 4, 2016
0833974
Convert parser map size check to a static assertion
b4n May 4, 2016
f147f36
Reduce some repetitions in tag type mapping code
b4n May 5, 2016
9b188a2
Use g_error() instead of g_warning() in parser type verification
techee May 6, 2016
c05e3ea
Split tm_ctags_callback into two
techee May 6, 2016
8c27ea1
Remove invalid part of a comment
techee May 6, 2016
9ae93e3
Check return value of write_tag()
techee May 6, 2016
bd9d26a
Fix crash in lookup_includes()
techee May 6, 2016
084c23b
Use g_strdup() instead of strdup()
techee May 6, 2016
7fe549d
Make sure not to leak tmp_errfile if only outf creation fails
techee May 6, 2016
b959801
Rename append_to_temp_file() to combine_include_files()
techee May 6, 2016
6e89ee5
Check for fclose() success
techee May 6, 2016
379eefa
Use '\0' for non-existent tag kind instead of '-'
techee Jun 9, 2016
27e4455
Drop g_list_reverse()
techee Jun 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions tagmanager/ctags/entry.c
Expand Up @@ -400,12 +400,6 @@ extern void makeTagEntry (const tagEntryInfo *const tag)
}
}

extern void setTagArglistByName (const char *tag_name, const char *arglist)
{
if (NULL != TagEntrySetArglistFunction)
TagEntrySetArglistFunction(tag_name, arglist);
}

extern void initTagEntry (tagEntryInfo *const e, const char *const name)
{
Assert (File.source.name != NULL);
Expand Down
1 change: 0 additions & 1 deletion tagmanager/ctags/entry.h
Expand Up @@ -95,7 +95,6 @@ extern void closeTagFile (const boolean resize);
extern void beginEtagsFile (void);
extern void endEtagsFile (const char *const name);
extern void makeTagEntry (const tagEntryInfo *const tag);
extern void setTagArglistByName (const char *tag_name, const char *arglist);
extern void initTagEntry (tagEntryInfo *const e, const char *const name);

#endif /* _ENTRY_H */
Expand Down
1 change: 0 additions & 1 deletion tagmanager/ctags/parse.c
Expand Up @@ -33,7 +33,6 @@ static parserDefinitionFunc* BuiltInParsers[] = { PARSER_LIST };
parserDefinition** LanguageTable = NULL;
static unsigned int LanguageCount = 0;
tagEntryFunction TagEntryFunction = NULL;
tagEntrySetArglistFunction TagEntrySetArglistFunction = NULL;

/*
* FUNCTION DEFINITIONS
Expand Down
2 changes: 0 additions & 2 deletions tagmanager/ctags/parse.h
Expand Up @@ -37,7 +37,6 @@ typedef void (*simpleParser) (void);
typedef boolean (*rescanParser) (const unsigned int passCount);
typedef void (*parserInitialize) (langType language);
typedef int (*tagEntryFunction) (const tagEntryInfo *const tag);
typedef void (*tagEntrySetArglistFunction) (const char *tag_name, const char *arglist);

typedef struct sKindOption {
boolean enabled; /* are tags for kind enabled? */
Expand Down Expand Up @@ -129,7 +128,6 @@ extern void checkRegex (void);

/* Extra stuff for Tag Manager */
extern tagEntryFunction TagEntryFunction;
extern tagEntrySetArglistFunction TagEntrySetArglistFunction;
extern void setTagEntryFunction(tagEntryFunction entry_function);

#endif /* _PARSE_H */
Expand Down
30 changes: 0 additions & 30 deletions tagmanager/ctags/python.c
Expand Up @@ -63,29 +63,6 @@ static boolean isIdentifierCharacter (int c)
return (boolean) (isalnum (c) || c == '_');
}

static const char *get_class_name_from_parent (const char *parent)
{
const char *result;

if (parent == NULL)
return NULL;

result = strrchr (parent, '.');
if (result != NULL)
{
result++;
parent = result;
}

result = strrchr (parent, '/');
if (result != NULL)
result++;
else
result = parent;

return result;
}

/* follows PEP-8, and always reports single-underscores as protected
* See:
* - http://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables
Expand Down Expand Up @@ -140,13 +117,6 @@ static void makeFunctionTag (vString *const function,
tag.kindName = PythonKinds[K_FUNCTION].name;
tag.kind = PythonKinds[K_FUNCTION].letter;
tag.extensionFields.arglist = arglist;
/* add argument list of __init__() methods to the class tag */
if (strcmp (vStringValue (function), "__init__") == 0 && parent != NULL)
{
const char *parent_tag_name = get_class_name_from_parent (vStringValue (parent));
if (parent_tag_name != NULL)
setTagArglistByName (parent_tag_name, arglist);
}

if (vStringLength (parent) > 0)
{
Expand Down
68 changes: 35 additions & 33 deletions tagmanager/src/tm_source_file.c
Expand Up @@ -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)
Copy link
Member

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.

Copy link
Member Author

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.

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).

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.

I haven't checked what the cork thing in uctags does so not sure either.

Copy link
Member

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".

Copy link
Member Author

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).

Copy link
Member

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?

Copy link
Member Author

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:

class Foo:
    def __init__(self, bar, baz):
        pass

to use the tag for its init() and copy its argument list to the tag of Foo so when you type

a = Foo(

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().

{
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, '.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: doesn't support the / separator previous code did, but our parser doesn't have it anyway.
Also, it would only concern classes defined inside a function or method, which is less common.

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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. */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down