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. Dscanner is a tool used to analyze D source code.
### Options ### 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 insertion of the dot operator. The cursor position is the character position in
the **file**, not the position in the line. 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 * **--sloc** _sourceFiles_ - count the number of logical lines of code in the given
source files. source files.
* **--json** _sourceFile_ - Generate a JSON summary of the given source file * **--json** _sourceFile_ - Generate a JSON summary of the given source file
@ -38,6 +39,9 @@ present.
foo v foo v
bar f bar f
With the extended completion syntax:
bar f : [#void#]bar(<#int x#>, <#int y#>)
##### Supported kinds ##### Supported kinds
* c -- class names * c -- class names
* i -- interface names * i -- interface names

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

29
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,25 @@ private:
} }
return app.data; 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;
}
} }