Fix recursive Ctags output

Previously using `dscanner --ctags -R <dir>` would output tags without
any filenames, making it pretty useless for navigating in a project.
This was due to all the syntax objects being merged into a single generic
Module, then outputting that module without a filename specified.

This fix does the following:
 * Moves the CTag header output from the Module class to the proper spot in
    main.d
 * Renames `Module.writeCtagsTo` to `getCtags` and now returns string[]
    with the prepared tag lines.
 * The CTag printing functionality in main.d now gathers all tag lines
    from each module, sorts, then outputs.

Note that a more optimal implementation would be fairly straightforward.
Instead of simply returning a string[], `Module.toCtags` could take a
sorted container and insert in sorted order.  main.d could pass this
container to each module in turn, then output the results.
This commit is contained in:
Justin Whear 2013-07-26 13:05:17 -07:00
parent 722f38dd68
commit 4f32e16e2b
2 changed files with 14 additions and 20 deletions

22
main.d
View File

@ -258,30 +258,32 @@ int main(string[] args)
if (ctags)
{
stdout.writeln("!_TAG_FILE_FORMAT 2");
stdout.writeln("!_TAG_FILE_SORTED 1");
stdout.writeln("!_TAG_PROGRAM_URL https://github.com/Hackerpilot/Dscanner/");
if (!recursiveCtags)
{
auto tokens = tokenize(readText(args[1]));
auto mod = parseModule(tokens);
mod.writeCtagsTo(stdout, args[1]);
//mod.writeCtagsTo(stdout, args[1]);
foreach (tag; mod.getCtags(args[1]))
stdout.writeln(tag);
}
else
{
Module m;
string[] allTags;
foreach (dirEntry; dirEntries(args[1], SpanMode.breadth))
{
if (!dirEntry.name.endsWith(".d", ".di"))
continue;
stderr.writeln("Generating tags for ", dirEntry.name);
auto tokens = tokenize(readText(dirEntry.name));
if (m is null)
m = parseModule(tokens);
else
{
auto mod = parseModule(tokens);
m.merge(mod);
}
auto mod = parseModule(tokens);
allTags ~= mod.getCtags(dirEntry.name);
}
m.writeCtagsTo(stdout, "");
allTags.sort();
foreach (tag; allTags)
stdout.writeln(tag);
}
}
return 0;

12
types.d
View File

@ -559,7 +559,7 @@ public:
/**
* Standards: http://ctags.sourceforge.net/FORMAT
*/
void writeCtagsTo(File file, string fileName)
string[] getCtags(string fileName)
{
string[] tags;
foreach (Enum e; enums)
@ -589,15 +589,7 @@ public:
{
tags ~= s.getCtags(fileName);
}
sort(tags);
file.writeln("!_TAG_FILE_FORMAT 2");
file.writeln("!_TAG_FILE_SORTED 1");
file.writeln("!_TAG_PROGRAM_URL https://github.com/Hackerpilot/Dscanner/");
foreach (tag; tags)
{
file.writeln(tag);
}
return tags;
}
}