Added --ctags option to generate tags file
This commit is contained in:
parent
066b298b99
commit
79f59bb6f4
|
@ -217,6 +217,10 @@ is transformed into the following JSON markup:
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Ctags output
|
||||||
|
Dscanner can create a tags file from the specified file. Output is formatted as
|
||||||
|
specified at http://ctags.sourceforge.net/FORMAT
|
||||||
|
|
||||||
# Line of Code count
|
# Line of Code count
|
||||||
This option counts the logical lines of code in the given source files, not
|
This option counts the logical lines of code in the given source files, not
|
||||||
simply the physical lines. More specifically, it counts the number of
|
simply the physical lines. More specifically, it counts the number of
|
||||||
|
|
|
@ -28,6 +28,14 @@ immutable string[] versions = ["AIX", "all", "Alpha", "ARM", "BigEndian", "BSD",
|
||||||
"Win64", "Windows", "X86", "X86_64"
|
"Win64", "Windows", "X86", "X86_64"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/+/**
|
||||||
|
* Returns: indicies into the token array
|
||||||
|
*/
|
||||||
|
Tuple!(size_t, size_t) findEndOfStatement(const Token[] tokens, size_t index, out size_t)
|
||||||
|
{
|
||||||
|
|
||||||
|
}+/
|
||||||
|
|
||||||
string[] callChainBackwards(const Token[] tokens, size_t index)
|
string[] callChainBackwards(const Token[] tokens, size_t index)
|
||||||
{
|
{
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
|
@ -220,12 +228,21 @@ struct AutoComplete
|
||||||
auto index = assumeSorted(tokens).lowerBound(cursor).length - 2;
|
auto index = assumeSorted(tokens).lowerBound(cursor).length - 2;
|
||||||
Token t = tokens[index];
|
Token t = tokens[index];
|
||||||
if (t.startIndex + t.value.length + 1 != cursor)
|
if (t.startIndex + t.value.length + 1 != cursor)
|
||||||
return [];
|
return "";
|
||||||
if (tokens[index] == TokenType.tVersion)
|
switch (tokens[index].type)
|
||||||
{
|
{
|
||||||
|
case TokenType.tVersion:
|
||||||
return to!string(array(join(map!`a ~ "?1"`(versions), " ")));
|
return to!string(array(join(map!`a ~ "?1"`(versions), " ")));
|
||||||
|
case TokenType.tIf:
|
||||||
|
case TokenType.tCast:
|
||||||
|
case TokenType.tWhile:
|
||||||
|
case TokenType.tFor:
|
||||||
|
case TokenType.tForeach:
|
||||||
|
case TokenType.tSwitch:
|
||||||
|
return "";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string dotComplete(size_t cursor)
|
string dotComplete(size_t cursor)
|
||||||
|
|
11
main.d
11
main.d
|
@ -136,8 +136,10 @@ void main(string[] args)
|
||||||
bool json;
|
bool json;
|
||||||
bool parenComplete;
|
bool parenComplete;
|
||||||
bool highlight;
|
bool highlight;
|
||||||
|
bool ctags;
|
||||||
getopt(args, "I", &importDirs, "dotComplete", &dotComplete, "sloc", &sloc,
|
getopt(args, "I", &importDirs, "dotComplete", &dotComplete, "sloc", &sloc,
|
||||||
"json", &json, "parenComplete", &parenComplete, "highlight", &highlight);
|
"json", &json, "parenComplete", &parenComplete, "highlight", &highlight,
|
||||||
|
"ctags", &ctags);
|
||||||
|
|
||||||
importDirs ~= loadConfig();
|
importDirs ~= loadConfig();
|
||||||
|
|
||||||
|
@ -174,11 +176,14 @@ void main(string[] args)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json)
|
if (json || ctags)
|
||||||
{
|
{
|
||||||
auto tokens = tokenize(readText(args[1]));
|
auto tokens = tokenize(readText(args[1]));
|
||||||
auto mod = parseModule(tokens);
|
auto mod = parseModule(tokens);
|
||||||
mod.writeJSONTo(stdout);
|
if (json)
|
||||||
|
mod.writeJSONTo(stdout);
|
||||||
|
else
|
||||||
|
mod.writeCtagsTo(stdout, args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ string lexDelimitedString(S)(ref S inputString, ref size_t endIndex,
|
||||||
{
|
{
|
||||||
auto startIndex = endIndex;
|
auto startIndex = endIndex;
|
||||||
++endIndex;
|
++endIndex;
|
||||||
string open = to!string(inputString[endIndex]);
|
string open = inputString[endIndex .. endIndex + 1];
|
||||||
string close;
|
string close;
|
||||||
bool nesting = false;
|
bool nesting = false;
|
||||||
switch (open)
|
switch (open)
|
||||||
|
|
91
types.d
91
types.d
|
@ -11,6 +11,7 @@ import std.array;
|
||||||
import std.range;
|
import std.range;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
import std.typecons;
|
import std.typecons;
|
||||||
|
import std.string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns: s with any quote characters backslash-escaped
|
* Returns: s with any quote characters backslash-escaped
|
||||||
|
@ -172,6 +173,23 @@ public:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string[] getCtags(string fileName)
|
||||||
|
{
|
||||||
|
auto app = appender!(string[])();
|
||||||
|
app.put(format("%s\t%s\t%d;\"\ts", name, fileName, line));
|
||||||
|
foreach (Function f; functions)
|
||||||
|
{
|
||||||
|
app.put(format("%s\t%s\t%d;\"\tf\tarity:%d\tstruct:", f.name, fileName,
|
||||||
|
f.line, f.parameters.length, name));
|
||||||
|
}
|
||||||
|
foreach (Variable v; variables)
|
||||||
|
{
|
||||||
|
app.put(format("%s\t%s\t%d;\"\tm\tstruct:%s", v.name, fileName,
|
||||||
|
v.line, name));
|
||||||
|
}
|
||||||
|
return app.data();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
override void printMembers(File f, uint indent = 0) const
|
override void printMembers(File f, uint indent = 0) const
|
||||||
|
@ -245,6 +263,24 @@ public:
|
||||||
*/
|
*/
|
||||||
string[] baseClasses;
|
string[] baseClasses;
|
||||||
|
|
||||||
|
override string[] getCtags(string fileName)
|
||||||
|
{
|
||||||
|
auto app = appender!(string[])();
|
||||||
|
app.put(format("%s\t%s\t%d;\"\tc\tinherits:%s", name, fileName, line,
|
||||||
|
array(baseClasses.joiner(","))));
|
||||||
|
foreach (Function f; functions)
|
||||||
|
{
|
||||||
|
app.put(format("%s\t%s\t%d;\"\tf\tarity:%d\tstruct:", f.name, fileName,
|
||||||
|
f.line, f.parameters.length, name));
|
||||||
|
}
|
||||||
|
foreach (Variable v; variables)
|
||||||
|
{
|
||||||
|
app.put(format("%s\t%s\t%d;\"\tm\tstruct:%s", v.name, fileName,
|
||||||
|
v.line, name));
|
||||||
|
}
|
||||||
|
return app.data();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
override void printMembers(File f, uint indent = 0) const
|
override void printMembers(File f, uint indent = 0) const
|
||||||
|
@ -277,6 +313,17 @@ public:
|
||||||
/// Enum members; may be empty
|
/// Enum members; may be empty
|
||||||
EnumMember[] members;
|
EnumMember[] members;
|
||||||
|
|
||||||
|
string[] getCtags(string fileName) const
|
||||||
|
{
|
||||||
|
auto app = appender!(string[])();
|
||||||
|
app.put(format("%s\t%s\t%d;\"\tg", name, fileName, line));
|
||||||
|
foreach (EnumMember member; members)
|
||||||
|
{
|
||||||
|
app.put(format("%s\t%s\t%d;\"\te\tenum:%s", member.name, fileName, member.line, name));
|
||||||
|
}
|
||||||
|
return app.data;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
override void printMembers(File f, uint indent = 0) const
|
override void printMembers(File f, uint indent = 0) const
|
||||||
|
@ -299,6 +346,7 @@ protected:
|
||||||
}
|
}
|
||||||
f.write(std.array.replicate(" ", indent), "]");
|
f.write(std.array.replicate(" ", indent), "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -423,6 +471,49 @@ public:
|
||||||
}
|
}
|
||||||
f.writeln(" ]\n}");
|
f.writeln(" ]\n}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standards: http://ctags.sourceforge.net/FORMAT
|
||||||
|
*/
|
||||||
|
void writeCtagsTo(File file, string fileName)
|
||||||
|
{
|
||||||
|
string[] tags;
|
||||||
|
foreach (Enum e; enums)
|
||||||
|
{
|
||||||
|
tags ~= e.getCtags(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Variable v; variables)
|
||||||
|
{
|
||||||
|
tags ~= format("%s\t%s\t%d;\"\tv", v.name, fileName, v.line);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Function f; functions)
|
||||||
|
{
|
||||||
|
tags ~= format("%s\t%s\t%d;\"\tf\tarity:%d", f.name, fileName,
|
||||||
|
f.line, f.parameters.length);
|
||||||
|
}
|
||||||
|
foreach (Inherits c; classes)
|
||||||
|
{
|
||||||
|
tags ~= c.getCtags(fileName);
|
||||||
|
}
|
||||||
|
foreach (Inherits i; interfaces)
|
||||||
|
{
|
||||||
|
tags ~= i.getCtags(fileName);
|
||||||
|
}
|
||||||
|
foreach (Struct s; structs)
|
||||||
|
{
|
||||||
|
tags ~= s.getCtags(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(tags);
|
||||||
|
file.writeln("{!_TAG_FILE_FORMAT 2}");
|
||||||
|
file.writeln("{!_TAG_FILE_SORTED 1}");
|
||||||
|
foreach (tag; tags)
|
||||||
|
{
|
||||||
|
file.writeln(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
immutable(string[][string]) typeProperties;
|
immutable(string[][string]) typeProperties;
|
||||||
|
|
Loading…
Reference in New Issue