fix UFCS with partial completion, fix #731
This commit is contained in:
parent
109d56b248
commit
c324b60da3
|
@ -26,6 +26,7 @@ struct TokenCursorResult
|
||||||
CompletionContext completionContext;
|
CompletionContext completionContext;
|
||||||
istring functionName;
|
istring functionName;
|
||||||
istring symbolIdentifierName;
|
istring symbolIdentifierName;
|
||||||
|
string partialIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dlang.org/spec/type.html#implicit-conversions
|
// https://dlang.org/spec/type.html#implicit-conversions
|
||||||
|
@ -82,6 +83,13 @@ private TokenCursorResult getCursorToken(const(Token)[] tokens, size_t cursorPos
|
||||||
return tokenCursorResult;
|
return tokenCursorResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move before identifier for
|
||||||
|
if (sortedBeforeTokens[$ - 1].type is tok!"identifier")
|
||||||
|
{
|
||||||
|
tokenCursorResult.partialIdentifier = sortedBeforeTokens[$ - 1].text;
|
||||||
|
sortedBeforeTokens = sortedBeforeTokens[0 .. $ - 1];
|
||||||
|
}
|
||||||
|
|
||||||
if (sortedBeforeTokens.length >= 2
|
if (sortedBeforeTokens.length >= 2
|
||||||
&& sortedBeforeTokens[$ - 1].type is tok!"."
|
&& sortedBeforeTokens[$ - 1].type is tok!"."
|
||||||
&& sortedBeforeTokens[$ - 2].type is tok!"identifier")
|
&& sortedBeforeTokens[$ - 2].type is tok!"identifier")
|
||||||
|
@ -91,7 +99,7 @@ private TokenCursorResult getCursorToken(const(Token)[] tokens, size_t cursorPos
|
||||||
tokenCursorResult.symbolIdentifierName = istring(sortedBeforeTokens[$ - 2].text);
|
tokenCursorResult.symbolIdentifierName = istring(sortedBeforeTokens[$ - 2].text);
|
||||||
return tokenCursorResult;
|
return tokenCursorResult;
|
||||||
}
|
}
|
||||||
else
|
else if (!tokenCursorResult.partialIdentifier.length)
|
||||||
{
|
{
|
||||||
// Check if it's UFCS paren completion
|
// Check if it's UFCS paren completion
|
||||||
size_t index = goBackToOpenParen(sortedBeforeTokens);
|
size_t index = goBackToOpenParen(sortedBeforeTokens);
|
||||||
|
@ -213,17 +221,23 @@ DSymbol*[] getUFCSSymbolsForCursor(Scope* completionScope, ref const(Token)[] to
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return getUFCSSymbolsForDotCompletion(cursorSymbolType, completionScope, cursorPosition);
|
return getUFCSSymbolsForDotCompletion(cursorSymbolType, completionScope, cursorPosition, tokenCursorResult.partialIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DSymbol*[] getUFCSSymbolsForDotCompletion(const(DSymbol)* symbolType, Scope* completionScope, size_t cursorPosition)
|
private DSymbol*[] getUFCSSymbolsForDotCompletion(const(DSymbol)* symbolType, Scope* completionScope, size_t cursorPosition, string partial)
|
||||||
{
|
{
|
||||||
// local appender
|
// local appender
|
||||||
FilteredAppender!(a => a.isCallableWithArg(symbolType), DSymbol*[]) localAppender;
|
FilteredAppender!((DSymbol* a) =>
|
||||||
|
a.isCallableWithArg(symbolType)
|
||||||
|
&& toUpper(a.name.data).startsWith(toUpper(partial)),
|
||||||
|
DSymbol*[]) localAppender;
|
||||||
// global appender
|
// global appender
|
||||||
FilteredAppender!(a => a.isCallableWithArg(symbolType, true), DSymbol*[]) globalAppender;
|
FilteredAppender!((DSymbol* a) =>
|
||||||
|
a.isCallableWithArg(symbolType, true)
|
||||||
|
&& toUpper(a.name.data).startsWith(toUpper(partial)),
|
||||||
|
DSymbol*[]) globalAppender;
|
||||||
|
|
||||||
getUFCSSymbols(localAppender, globalAppender, completionScope, cursorPosition);
|
getUFCSSymbols(localAppender, globalAppender, completionScope, cursorPosition);
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
identifiers
|
identifiers
|
||||||
alignof k
|
|
||||||
arrayStuff1 F
|
arrayStuff1 F
|
||||||
arrayStuff7 F
|
arrayStuff7 F
|
||||||
doArray F
|
|
||||||
dup k
|
|
||||||
idup k
|
|
||||||
init k
|
|
||||||
length k
|
|
||||||
mangleof k
|
|
||||||
ptr k
|
|
||||||
sizeof k
|
|
||||||
stringof k
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ void arrayStuff6(int*[] x) { }
|
||||||
void arrayStuff7(const(int)[] x) { }
|
void arrayStuff7(const(int)[] x) { }
|
||||||
void doArray(int[] x, int[] y)
|
void doArray(int[] x, int[] y)
|
||||||
{
|
{
|
||||||
y.
|
y.arraySt
|
||||||
// TODO: arrayStuff4 isn't included yet, since we don't really process
|
// TODO: arrayStuff4 isn't included yet, since we don't really process
|
||||||
// templates, but should be!
|
// templates, but should be!
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
set -e
|
set -e
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
../../bin/dcd-client $1 -c259 file.d > actual_array_test.txt
|
../../bin/dcd-client $1 -c266 file.d > actual_array_test.txt
|
||||||
diff actual_array_test.txt expected_array_test.txt
|
diff actual_array_test.txt expected_array_test.txt
|
Loading…
Reference in New Issue