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 modulecache;
import conversion.astconverter; import conversion.astconverter;
import stupidlog; import stupidlog;
import string_interning;
/** /**
* Gets documentation for the symbol at the cursor * Gets documentation for the symbol at the cursor
@ -805,33 +806,42 @@ void setCompletions(T)(ref AutocompleteResponse response,
} }
else if (completionType == CompletionType.calltips) 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 if (symbols[0].kind != CompletionKind.functionName
&& symbols[0].callTip is null) && symbols[0].callTip is null)
{ {
if (symbols[0].kind == CompletionKind.variableName) if (symbols[0].kind == CompletionKind.variableName)
{ {
auto dumb = symbols[0].type; auto dumb = symbols[0].type;
if (isBracket) if (dumb !is null)
{ {
auto index = dumb.getPartsByName("opIndex"); if (dumb.kind == CompletionKind.functionName)
if (index.length > 0)
{ {
symbols = index; symbols = [dumb];
goto setCallTips;
}
if (isBracket)
{
auto index = dumb.getPartsByName(internString("opIndex"));
if (index.length > 0)
{
symbols = index;
goto setCallTips;
}
}
auto call = dumb.getPartsByName(internString("opCall"));
if (call.length > 0)
{
symbols = call;
goto setCallTips; goto setCallTips;
} }
} }
auto call = dumb.getPartsByName("opCall");
if (call.length > 0)
{
symbols = call;
goto setCallTips;
}
} }
if (symbols[0].kind == CompletionKind.structName if (symbols[0].kind == CompletionKind.structName
|| symbols[0].kind == CompletionKind.className) || symbols[0].kind == CompletionKind.className)
{ {
auto constructor = symbols[0].getPartsByName("*constructor*"); auto constructor = symbols[0].getPartsByName(internString("*constructor*"));
if (constructor.length == 0) if (constructor.length == 0)
{ {
// Build a call tip out of the struct fields // Build a call tip out of the struct fields
@ -853,7 +863,7 @@ void setCompletions(T)(ref AutocompleteResponse response,
response.completionType = CompletionType.calltips; response.completionType = CompletionType.calltips;
foreach (symbol; symbols) foreach (symbol; symbols)
{ {
if (symbol.kind != CompletionKind.aliasName) if (symbol.kind != CompletionKind.aliasName && symbol.callTip !is null)
response.completions ~= symbol.callTip; response.completions ~= symbol.callTip;
} }
} }
@ -1015,7 +1025,8 @@ bool shouldSwapWithType(CompletionType completionType, CompletionKind kind,
|| kind == CompletionKind.memberVariableName || kind == CompletionKind.memberVariableName
|| kind == CompletionKind.enumMember || kind == CompletionKind.enumMember
|| kind == CompletionKind.functionName; || 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); withStatement.statementNoCaseNoDefault.endLocation);
SemanticSymbol* symbol = allocateSemanticSymbol(WITH_SYMBOL_NAME, SemanticSymbol* symbol = allocateSemanticSymbol(WITH_SYMBOL_NAME,
CompletionKind.withSymbol, symbolFile, s.startLocation, null); CompletionKind.withSymbol, symbolFile, s.startLocation, null);
Log.trace("WithStatement bounds: ", s.startLocation, " ", s.endLocation);
s.parent = currentScope; s.parent = currentScope;
currentScope.children.insert(s); currentScope.children.insert(s);
populateInitializer(symbol, withStatement.expression, false); populateInitializer(symbol, withStatement.expression, false);

View File

@ -271,7 +271,7 @@ private:
} }
resolveSuffixes: resolveSuffixes:
foreach (suffix; t.typeSuffixes) foreach (suffix; t.typeSuffixes)
s = processSuffix(s, suffix); s = processSuffix(s, suffix, t);
return s; 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; import std.d.formatter;
if (suffix.star) if (suffix.star)
@ -314,10 +314,9 @@ private:
s.type = symbol; s.type = symbol;
s.qualifier = SymbolQualifier.func; s.qualifier = SymbolQualifier.func;
QuickAllocator!1024 q; 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); scope(exit) q.deallocate(app.mem);
app.append(suffix.delegateOrFunction.text); app.formatNode(t);
app.formatNode(suffix.parameters);
s.callTip = internString(cast(string) app[]); s.callTip = internString(cast(string) app[]);
return s; return s;
} }