This commit is contained in:
jmaschme 2012-10-22 17:12:08 -07:00
commit 6616913965
3 changed files with 34 additions and 6 deletions

View File

@ -2,9 +2,10 @@
Dscanner is a tool used to analyze D source code.
### Options
* **--dotComplete** _sourceFile_ _cursorPosition_ - Provide autocompletion for the
* **--dotComplete** [--extended] _sourceFile_ _cursorPosition_ - Provide autocompletion for the
insertion of the dot operator. The cursor position is the character position in
the **file**, not the position in the line.
When the extended option is included, display function completions with their full signature.
* **--sloc** _sourceFiles_ - count the number of logical lines of code in the given
source files.
* **--json** _sourceFile_ - Generate a JSON summary of the given source file
@ -38,6 +39,9 @@ present.
foo v
bar f
With the extended completion syntax:
bar f : [#void#]bar(<#int x#>, <#int y#>)
##### Supported kinds
* c -- class names
* i -- interface names

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))
{

29
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,25 @@ private:
}
return app.data;
}
string getFunctionType(Function f) {
string result = "f";
if (extendedFunctionTypes) {
result ~= " : ";
result ~= "[#" ~ f.returnType ~ "#]";
result ~= f.name ~ "(";
bool first = true;
foreach (param; f.parameters) {
if (first) {
first = false;
}
else {
result ~= ",";
}
result ~= "<#" ~ param.type ~ " " ~ param.name ~ "#>";
}
result ~= ")";
}
return result;
}
}