Added a new option to include function parameters in dotComplete

This commit is contained in:
John Maschmeyer 2012-10-16 20:24:11 -05:00
parent c25944e85e
commit 327f5f5af2
2 changed files with 27 additions and 5 deletions

5
main.d
View File

@ -139,12 +139,13 @@ void main(string[] args)
bool ctags;
bool recursiveCtags;
bool format;
bool extendedFunctionTypes;
try
{
getopt(args, "I", &importDirs, "dotComplete", &dotComplete, "sloc", &sloc,
"json", &json, "parenComplete", &parenComplete, "highlight", &highlight,
"ctags", &ctags, "recursive|r|R", &recursiveCtags);
"ctags", &ctags, "recursive|r|R", &recursiveCtags, "extended|e", &extendedFunctionTypes);
}
catch (Exception e)
{
@ -174,7 +175,7 @@ void main(string[] args)
importDirs ~= getcwd();
auto tokens = args[1].readText().tokenize();
auto mod = parseModule(tokens);
CompletionContext context = new CompletionContext(mod);
CompletionContext context = new CompletionContext(mod, extendedFunctionTypes);
context.importDirectories = importDirs;
foreach (im; parallel(mod.imports))
{

27
types.d
View File

@ -618,9 +618,10 @@ class CompletionContext
{
public:
this(Module mod)
this(Module mod, bool extendedFunctionTypes = false)
{
this.currentModule = mod;
this.extendedFunctionTypes = extendedFunctionTypes;
}
Tuple!(string, string)[string] getMembersOfType(string name)
@ -635,7 +636,7 @@ public:
foreach (var; inherits.variables)
typeMap[var.name] = Tuple!(string, string)(var.type, "m");
foreach (fun; inherits.functions)
typeMap[fun.name] = Tuple!(string, string)(fun.returnType, "f");
typeMap[fun.name] = Tuple!(string, string)(fun.returnType, getFunctionType(fun));
foreach (parent; inherits.baseClasses)
{
foreach (k, v; getMembersOfType(parent))
@ -654,7 +655,7 @@ public:
foreach (var; s.variables)
typeMap[var.name] = Tuple!(string, string)(var.type, "m");
foreach (fun; s.functions)
typeMap[fun.name] = Tuple!(string, string)(fun.returnType, "f");
typeMap[fun.name] = Tuple!(string, string)(fun.returnType, getFunctionType(fun));
return typeMap;
}
foreach (Enum e; m.enums)
@ -722,6 +723,7 @@ public:
Module currentModule;
Module[] modules;
string[] importDirectories;
bool extendedFunctionTypes;
private:
@ -739,4 +741,23 @@ private:
}
return app.data;
}
string getFunctionType(Function f) {
string result = "f";
if (extendedFunctionTypes) {
result ~= "::";
bool first = true;
foreach (param; f.parameters) {
if (first) {
first = false;
}
else {
result ~= "::";
}
result ~= param.type ~ " " ~ param.name;
}
result ~= "::";
}
return result;
}
}