This commit is contained in:
Hackerpilot 2014-01-28 21:58:38 -08:00
parent e7f39523cf
commit b3a828e243
1 changed files with 16 additions and 12 deletions

View File

@ -108,7 +108,7 @@ AutocompleteResponse findDeclaration(const AutocompleteRequest request)
auto expression = getExpression(beforeTokens); auto expression = getExpression(beforeTokens);
const(ACSymbol)*[] symbols = getSymbolsByTokenChain(completionScope, expression, const(ACSymbol)*[] symbols = getSymbolsByTokenChain(completionScope, expression,
request.cursorPosition, CompletionType.identifiers); request.cursorPosition, CompletionType.location);
if (symbols.length > 0) if (symbols.length > 0)
{ {
@ -125,6 +125,18 @@ AutocompleteResponse findDeclaration(const AutocompleteRequest request)
return response; return response;
} }
bool shouldSwapWithType(CompletionType completionType, CompletionKind kind,
size_t current, size_t max) pure nothrow @safe
{
immutable bool isInteresting =
kind == CompletionKind.variableName
|| kind == CompletionKind.memberVariableName
|| kind == CompletionKind.enumMember
|| kind == CompletionKind.functionName;
return (current < max && completionType == CompletionType.location)
|| (completionType == CompletionType.identifiers && isInteresting);
}
const(ACSymbol)*[] getSymbolsByTokenChain(T)(const(Scope)* completionScope, const(ACSymbol)*[] getSymbolsByTokenChain(T)(const(Scope)* completionScope,
T tokens, size_t cursorPosition, CompletionType completionType) T tokens, size_t cursorPosition, CompletionType completionType)
{ {
@ -144,11 +156,7 @@ const(ACSymbol)*[] getSymbolsByTokenChain(T)(const(Scope)* completionScope,
" with type ", symbols[0].type is null ? "null" : symbols[0].type.name); " with type ", symbols[0].type is null ? "null" : symbols[0].type.name);
} }
if (completionType == CompletionType.identifiers if (shouldSwapWithType(completionType, symbols[0].kind, 0, tokens.length - 1))
&& symbols[0].kind == CompletionKind.memberVariableName
|| symbols[0].kind == CompletionKind.variableName
|| symbols[0].kind == CompletionKind.aliasName
|| symbols[0].kind == CompletionKind.enumMember)
{ {
symbols = symbols[0].type is null ? [] : [symbols[0].type]; symbols = symbols[0].type is null ? [] : [symbols[0].type];
if (symbols.length == 0) if (symbols.length == 0)
@ -220,12 +228,8 @@ const(ACSymbol)*[] getSymbolsByTokenChain(T)(const(Scope)* completionScope,
Log.trace("Couldn't find it."); Log.trace("Couldn't find it.");
break loop; break loop;
} }
if ((symbols[0].kind == CompletionKind.variableName if (shouldSwapWithType(completionType, symbols[0].kind, i,
|| symbols[0].kind == CompletionKind.memberVariableName tokens.length - 1))
|| symbols[0].kind == CompletionKind.enumMember
|| symbols[0].kind == CompletionKind.functionName)
&& (completionType == CompletionType.identifiers
|| i + 1 < tokens.length))
{ {
symbols = symbols[0].type is null ? [] : [symbols[0].type]; symbols = symbols[0].type is null ? [] : [symbols[0].type];
} }