Skip to content

Commit f9e93b0

Browse files
committed
Fix complicated function call tips
1 parent 7ec5aaf commit f9e93b0

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

src/autocomplete.d

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import constants;
4040
import modulecache;
4141
import conversion.astconverter;
4242
import stupidlog;
43+
import string_interning;
4344

4445
/**
4546
* Gets documentation for the symbol at the cursor
@@ -805,33 +806,42 @@ void setCompletions(T)(ref AutocompleteResponse response,
805806
}
806807
else if (completionType == CompletionType.calltips)
807808
{
808-
// Log.trace("Showing call tips for ", symbols[0].name, " of type ", symbols[0].kind);
809+
// Log.trace("Showing call tips for ", symbols[0].name, " of kind ", symbols[0].kind);
809810
if (symbols[0].kind != CompletionKind.functionName
810811
&& symbols[0].callTip is null)
811812
{
812813
if (symbols[0].kind == CompletionKind.variableName)
813814
{
814815
auto dumb = symbols[0].type;
815-
if (isBracket)
816+
if (dumb !is null)
816817
{
817-
auto index = dumb.getPartsByName("opIndex");
818-
if (index.length > 0)
818+
if (dumb.kind == CompletionKind.functionName)
819819
{
820-
symbols = index;
820+
symbols = [dumb];
821+
goto setCallTips;
822+
}
823+
if (isBracket)
824+
{
825+
auto index = dumb.getPartsByName(internString("opIndex"));
826+
if (index.length > 0)
827+
{
828+
symbols = index;
829+
goto setCallTips;
830+
}
831+
}
832+
auto call = dumb.getPartsByName(internString("opCall"));
833+
if (call.length > 0)
834+
{
835+
symbols = call;
821836
goto setCallTips;
822837
}
823838
}
824-
auto call = dumb.getPartsByName("opCall");
825-
if (call.length > 0)
826-
{
827-
symbols = call;
828-
goto setCallTips;
829-
}
839+
830840
}
831841
if (symbols[0].kind == CompletionKind.structName
832842
|| symbols[0].kind == CompletionKind.className)
833843
{
834-
auto constructor = symbols[0].getPartsByName("*constructor*");
844+
auto constructor = symbols[0].getPartsByName(internString("*constructor*"));
835845
if (constructor.length == 0)
836846
{
837847
// Build a call tip out of the struct fields
@@ -853,7 +863,7 @@ void setCompletions(T)(ref AutocompleteResponse response,
853863
response.completionType = CompletionType.calltips;
854864
foreach (symbol; symbols)
855865
{
856-
if (symbol.kind != CompletionKind.aliasName)
866+
if (symbol.kind != CompletionKind.aliasName && symbol.callTip !is null)
857867
response.completions ~= symbol.callTip;
858868
}
859869
}
@@ -1015,7 +1025,8 @@ bool shouldSwapWithType(CompletionType completionType, CompletionKind kind,
10151025
|| kind == CompletionKind.memberVariableName
10161026
|| kind == CompletionKind.enumMember
10171027
|| kind == CompletionKind.functionName;
1018-
return completionType == CompletionType.identifiers && isInteresting;
1028+
return isInteresting && (completionType == CompletionType.identifiers
1029+
|| (completionType == completionType.calltips && kind == CompletionKind.variableName)) ;
10191030
}
10201031

10211032
/**

src/conversion/first.d

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ final class FirstPass : ASTVisitor
470470
withStatement.statementNoCaseNoDefault.endLocation);
471471
SemanticSymbol* symbol = allocateSemanticSymbol(WITH_SYMBOL_NAME,
472472
CompletionKind.withSymbol, symbolFile, s.startLocation, null);
473-
Log.trace("WithStatement bounds: ", s.startLocation, " ", s.endLocation);
474473
s.parent = currentScope;
475474
currentScope.children.insert(s);
476475
populateInitializer(symbol, withStatement.expression, false);

src/conversion/third.d

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private:
271271
}
272272
resolveSuffixes:
273273
foreach (suffix; t.typeSuffixes)
274-
s = processSuffix(s, suffix);
274+
s = processSuffix(s, suffix, t);
275275
return s;
276276
}
277277

@@ -291,7 +291,7 @@ private:
291291
}
292292
}
293293

294-
ACSymbol* processSuffix(ACSymbol* symbol, const TypeSuffix suffix)
294+
ACSymbol* processSuffix(ACSymbol* symbol, const TypeSuffix suffix, const Type t)
295295
{
296296
import std.d.formatter;
297297
if (suffix.star)
@@ -314,10 +314,9 @@ private:
314314
s.type = symbol;
315315
s.qualifier = SymbolQualifier.func;
316316
QuickAllocator!1024 q;
317-
auto app = Appender!(char, typeof(q), 1024)(q);
317+
auto app = Appender!(char, typeof(q), 2048)(q);
318318
scope(exit) q.deallocate(app.mem);
319-
app.append(suffix.delegateOrFunction.text);
320-
app.formatNode(suffix.parameters);
319+
app.formatNode(t);
321320
s.callTip = internString(cast(string) app[]);
322321
return s;
323322
}

0 commit comments

Comments
 (0)