Fix complicated function call tips

This commit is contained in:
Hackerpilot 2014-09-22 02:24:22 +00:00
parent 7ec5aaf65a
commit f9e93b096a
3 changed files with 29 additions and 20 deletions

View File

@ -40,6 +40,7 @@ import constants;
import modulecache;
import conversion.astconverter;
import stupidlog;
import string_interning;
/**
* Gets documentation for the symbol at the cursor
@ -805,33 +806,42 @@ void setCompletions(T)(ref AutocompleteResponse response,
}
else if (completionType == CompletionType.calltips)
{
// Log.trace("Showing call tips for ", symbols[0].name, " of type ", symbols[0].kind);
// Log.trace("Showing call tips for ", symbols[0].name, " of kind ", symbols[0].kind);
if (symbols[0].kind != CompletionKind.functionName
&& symbols[0].callTip is null)
{
if (symbols[0].kind == CompletionKind.variableName)
{
auto dumb = symbols[0].type;
if (dumb !is null)
{
if (dumb.kind == CompletionKind.functionName)
{
symbols = [dumb];
goto setCallTips;
}
if (isBracket)
{
auto index = dumb.getPartsByName("opIndex");
auto index = dumb.getPartsByName(internString("opIndex"));
if (index.length > 0)
{
symbols = index;
goto setCallTips;
}
}
auto call = dumb.getPartsByName("opCall");
auto call = dumb.getPartsByName(internString("opCall"));
if (call.length > 0)
{
symbols = call;
goto setCallTips;
}
}
}
if (symbols[0].kind == CompletionKind.structName
|| symbols[0].kind == CompletionKind.className)
{
auto constructor = symbols[0].getPartsByName("*constructor*");
auto constructor = symbols[0].getPartsByName(internString("*constructor*"));
if (constructor.length == 0)
{
// Build a call tip out of the struct fields
@ -853,7 +863,7 @@ void setCompletions(T)(ref AutocompleteResponse response,
response.completionType = CompletionType.calltips;
foreach (symbol; symbols)
{
if (symbol.kind != CompletionKind.aliasName)
if (symbol.kind != CompletionKind.aliasName && symbol.callTip !is null)
response.completions ~= symbol.callTip;
}
}
@ -1015,7 +1025,8 @@ bool shouldSwapWithType(CompletionType completionType, CompletionKind kind,
|| kind == CompletionKind.memberVariableName
|| kind == CompletionKind.enumMember
|| kind == CompletionKind.functionName;
return completionType == CompletionType.identifiers && isInteresting;
return isInteresting && (completionType == CompletionType.identifiers
|| (completionType == completionType.calltips && kind == CompletionKind.variableName)) ;
}
/**

View File

@ -470,7 +470,6 @@ final class FirstPass : ASTVisitor
withStatement.statementNoCaseNoDefault.endLocation);
SemanticSymbol* symbol = allocateSemanticSymbol(WITH_SYMBOL_NAME,
CompletionKind.withSymbol, symbolFile, s.startLocation, null);
Log.trace("WithStatement bounds: ", s.startLocation, " ", s.endLocation);
s.parent = currentScope;
currentScope.children.insert(s);
populateInitializer(symbol, withStatement.expression, false);

View File

@ -271,7 +271,7 @@ private:
}
resolveSuffixes:
foreach (suffix; t.typeSuffixes)
s = processSuffix(s, suffix);
s = processSuffix(s, suffix, t);
return s;
}
@ -291,7 +291,7 @@ private:
}
}
ACSymbol* processSuffix(ACSymbol* symbol, const TypeSuffix suffix)
ACSymbol* processSuffix(ACSymbol* symbol, const TypeSuffix suffix, const Type t)
{
import std.d.formatter;
if (suffix.star)
@ -314,10 +314,9 @@ private:
s.type = symbol;
s.qualifier = SymbolQualifier.func;
QuickAllocator!1024 q;
auto app = Appender!(char, typeof(q), 1024)(q);
auto app = Appender!(char, typeof(q), 2048)(q);
scope(exit) q.deallocate(app.mem);
app.append(suffix.delegateOrFunction.text);
app.formatNode(suffix.parameters);
app.formatNode(t);
s.callTip = internString(cast(string) app[]);
return s;
}