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:
parent
722f38dd68
commit
4f32e16e2b
22
main.d
22
main.d
|
@ -258,30 +258,32 @@ int main(string[] args)
|
||||||
|
|
||||||
if (ctags)
|
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)
|
if (!recursiveCtags)
|
||||||
{
|
{
|
||||||
auto tokens = tokenize(readText(args[1]));
|
auto tokens = tokenize(readText(args[1]));
|
||||||
auto mod = parseModule(tokens);
|
auto mod = parseModule(tokens);
|
||||||
mod.writeCtagsTo(stdout, args[1]);
|
//mod.writeCtagsTo(stdout, args[1]);
|
||||||
|
foreach (tag; mod.getCtags(args[1]))
|
||||||
|
stdout.writeln(tag);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Module m;
|
string[] allTags;
|
||||||
foreach (dirEntry; dirEntries(args[1], SpanMode.breadth))
|
foreach (dirEntry; dirEntries(args[1], SpanMode.breadth))
|
||||||
{
|
{
|
||||||
if (!dirEntry.name.endsWith(".d", ".di"))
|
if (!dirEntry.name.endsWith(".d", ".di"))
|
||||||
continue;
|
continue;
|
||||||
stderr.writeln("Generating tags for ", dirEntry.name);
|
stderr.writeln("Generating tags for ", dirEntry.name);
|
||||||
auto tokens = tokenize(readText(dirEntry.name));
|
auto tokens = tokenize(readText(dirEntry.name));
|
||||||
if (m is null)
|
auto mod = parseModule(tokens);
|
||||||
m = parseModule(tokens);
|
allTags ~= mod.getCtags(dirEntry.name);
|
||||||
else
|
|
||||||
{
|
|
||||||
auto mod = parseModule(tokens);
|
|
||||||
m.merge(mod);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m.writeCtagsTo(stdout, "");
|
allTags.sort();
|
||||||
|
foreach (tag; allTags)
|
||||||
|
stdout.writeln(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
12
types.d
12
types.d
|
@ -559,7 +559,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Standards: http://ctags.sourceforge.net/FORMAT
|
* Standards: http://ctags.sourceforge.net/FORMAT
|
||||||
*/
|
*/
|
||||||
void writeCtagsTo(File file, string fileName)
|
string[] getCtags(string fileName)
|
||||||
{
|
{
|
||||||
string[] tags;
|
string[] tags;
|
||||||
foreach (Enum e; enums)
|
foreach (Enum e; enums)
|
||||||
|
@ -589,15 +589,7 @@ public:
|
||||||
{
|
{
|
||||||
tags ~= s.getCtags(fileName);
|
tags ~= s.getCtags(fileName);
|
||||||
}
|
}
|
||||||
|
return tags;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue