From 4f32e16e2b5d40596bb2ccb3200d13dd7288139d Mon Sep 17 00:00:00 2001 From: Justin Whear Date: Fri, 26 Jul 2013 13:05:17 -0700 Subject: [PATCH 1/2] Fix recursive Ctags output Previously using `dscanner --ctags -R ` 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. --- main.d | 22 ++++++++++++---------- types.d | 12 ++---------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/main.d b/main.d index 473ecb2..829303a 100644 --- a/main.d +++ b/main.d @@ -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; diff --git a/types.d b/types.d index 1e5f776..9db510b 100644 --- a/types.d +++ b/types.d @@ -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; } } From 91c8be08b500ead6f3fa9d36a16b9f6a201205a6 Mon Sep 17 00:00:00 2001 From: Justin Whear Date: Fri, 26 Jul 2013 13:32:14 -0700 Subject: [PATCH 2/2] cleanup --- main.d | 1 - 1 file changed, 1 deletion(-) diff --git a/main.d b/main.d index 829303a..c62a4fd 100644 --- a/main.d +++ b/main.d @@ -265,7 +265,6 @@ int main(string[] args) { auto tokens = tokenize(readText(args[1])); auto mod = parseModule(tokens); - //mod.writeCtagsTo(stdout, args[1]); foreach (tag; mod.getCtags(args[1])) stdout.writeln(tag); }