From f9e93b096a3dd8618106d7f872207df2390b07ee Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Mon, 22 Sep 2014 02:24:22 +0000 Subject: [PATCH] Fix complicated function call tips --- src/autocomplete.d | 39 +++++++++++++++++++++++++-------------- src/conversion/first.d | 1 - src/conversion/third.d | 9 ++++----- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/autocomplete.d b/src/autocomplete.d index 56e77d4..940605f 100644 --- a/src/autocomplete.d +++ b/src/autocomplete.d @@ -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 (isBracket) + if (dumb !is null) { - auto index = dumb.getPartsByName("opIndex"); - if (index.length > 0) + if (dumb.kind == CompletionKind.functionName) { - 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; } } - auto call = dumb.getPartsByName("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)) ; } /** diff --git a/src/conversion/first.d b/src/conversion/first.d index f73766a..4560b30 100644 --- a/src/conversion/first.d +++ b/src/conversion/first.d @@ -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); diff --git a/src/conversion/third.d b/src/conversion/third.d index 06720bd..33864b9 100644 --- a/src/conversion/third.d +++ b/src/conversion/third.d @@ -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; }