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 ctags;
bool recursiveCtags; bool recursiveCtags;
bool format; bool format;
bool extendedFunctionTypes;
try try
{ {
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, "recursive|r|R", &recursiveCtags); "ctags", &ctags, "recursive|r|R", &recursiveCtags, "extended|e", &extendedFunctionTypes);
} }
catch (Exception e) catch (Exception e)
{ {
@ -174,7 +175,7 @@ void main(string[] args)
importDirs ~= getcwd(); importDirs ~= getcwd();
auto tokens = args[1].readText().tokenize(); auto tokens = args[1].readText().tokenize();
auto mod = parseModule(tokens); auto mod = parseModule(tokens);
CompletionContext context = new CompletionContext(mod); CompletionContext context = new CompletionContext(mod, extendedFunctionTypes);
context.importDirectories = importDirs; context.importDirectories = importDirs;
foreach (im; parallel(mod.imports)) foreach (im; parallel(mod.imports))
{ {

27
types.d
View File

@ -618,9 +618,10 @@ class CompletionContext
{ {
public: public:
this(Module mod) this(Module mod, bool extendedFunctionTypes = false)
{ {
this.currentModule = mod; this.currentModule = mod;
this.extendedFunctionTypes = extendedFunctionTypes;
} }
Tuple!(string, string)[string] getMembersOfType(string name) Tuple!(string, string)[string] getMembersOfType(string name)
@ -635,7 +636,7 @@ public:
foreach (var; inherits.variables) foreach (var; inherits.variables)
typeMap[var.name] = Tuple!(string, string)(var.type, "m"); typeMap[var.name] = Tuple!(string, string)(var.type, "m");
foreach (fun; inherits.functions) 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 (parent; inherits.baseClasses)
{ {
foreach (k, v; getMembersOfType(parent)) foreach (k, v; getMembersOfType(parent))
@ -654,7 +655,7 @@ public:
foreach (var; s.variables) foreach (var; s.variables)
typeMap[var.name] = Tuple!(string, string)(var.type, "m"); typeMap[var.name] = Tuple!(string, string)(var.type, "m");
foreach (fun; s.functions) 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; return typeMap;
} }
foreach (Enum e; m.enums) foreach (Enum e; m.enums)
@ -722,6 +723,7 @@ public:
Module currentModule; Module currentModule;
Module[] modules; Module[] modules;
string[] importDirectories; string[] importDirectories;
bool extendedFunctionTypes;
private: private:
@ -739,4 +741,23 @@ private:
} }
return app.data; 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;
}
} }