Call tips for member functons
This commit is contained in:
parent
93915f4998
commit
9c8295e013
|
@ -142,7 +142,6 @@ unittest
|
||||||
assert (splitCallChain(tokens) == ["a", "b", "c", "x"]);
|
assert (splitCallChain(tokens) == ["a", "b", "c", "x"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct AutoComplete
|
struct AutoComplete
|
||||||
{
|
{
|
||||||
this(const (Token)[] tokens, CompletionContext context)
|
this(const (Token)[] tokens, CompletionContext context)
|
||||||
|
@ -285,7 +284,8 @@ struct AutoComplete
|
||||||
auto callChain = splitCallChain(tokens[startIndex .. index + 1]);
|
auto callChain = splitCallChain(tokens[startIndex .. index + 1]);
|
||||||
auto expressionType = getTypeOfExpression(
|
auto expressionType = getTypeOfExpression(
|
||||||
callChain[0 .. $ - 1], tokens, cursor);
|
callChain[0 .. $ - 1], tokens, cursor);
|
||||||
return to!string(context.getCallTipsFor(expressionType, callChain[$ - 1].value).join("\n").array());
|
return to!string(context.getCallTipsFor(expressionType,
|
||||||
|
callChain[$ - 1].value, cursor).join("\n").array());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
41
types.d
41
types.d
|
@ -627,14 +627,33 @@ public:
|
||||||
{
|
{
|
||||||
foreach (m; chain(modules, [currentModule]))
|
foreach (m; chain(modules, [currentModule]))
|
||||||
{
|
{
|
||||||
foreach (s; chain(m.structs, m.interfaces, m.classes, m.unions))
|
foreach (inherits; chain(m.interfaces, m.classes))
|
||||||
|
{
|
||||||
|
if (inherits.name != name)
|
||||||
|
continue;
|
||||||
|
Tuple!(string, string)[string] typeMap;
|
||||||
|
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");
|
||||||
|
foreach (parent; inherits.baseClasses)
|
||||||
|
{
|
||||||
|
foreach (k, v; getMembersOfType(parent))
|
||||||
|
{
|
||||||
|
typeMap[k] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return typeMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (s; chain(m.structs, m.unions))
|
||||||
{
|
{
|
||||||
if (s.name != name)
|
if (s.name != name)
|
||||||
continue;
|
continue;
|
||||||
Tuple!(string, string)[string] typeMap;
|
Tuple!(string, string)[string] typeMap;
|
||||||
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, "f");
|
||||||
return typeMap;
|
return typeMap;
|
||||||
}
|
}
|
||||||
|
@ -665,11 +684,23 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string[] getCallTipsFor(string container, string functionName)
|
string[] getCallTipsFor(string container, string functionName,
|
||||||
|
size_t cursorPosition)
|
||||||
{
|
{
|
||||||
stderr.writeln("getCallTipsFor ", container, " ", functionName);
|
|
||||||
if (container == null || container.length == 0 || container == "void")
|
if (container == null || container.length == 0 || container == "void")
|
||||||
|
{
|
||||||
|
// Try member functions first if the cursor is inside of a class
|
||||||
|
// or structure definiton
|
||||||
|
Struct[] structs = getStructsContaining(cursorPosition);
|
||||||
|
foreach (s; structs)
|
||||||
|
{
|
||||||
|
auto docs = s.getFunctionDocs(functionName);
|
||||||
|
if (docs.length > 0)
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
|
// Try global functions if the above failed.
|
||||||
return getCallTipsFor(functionName);
|
return getCallTipsFor(functionName);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (m; chain(modules, [currentModule]))
|
foreach (m; chain(modules, [currentModule]))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue