Added paren completion for UFCS

This commit is contained in:
davu 2022-10-23 20:18:02 +02:00 committed by Jan Jurzitza
parent 15ae4e5f00
commit 6c3a4d3797
5 changed files with 37 additions and 0 deletions

View File

@ -558,6 +558,12 @@ void setCompletions(T)(ref AutocompleteResponse response,
DSymbol*[] symbols = getSymbolsByTokenChain(completionScope, tokens,
cursorPosition, completionType);
if (tokens.length > 2 && tokens[1] == tok!".")
{
symbols.getUFCSParenCompletion(completionScope, stringToken(tokens[0]), stringToken(
tokens[2]), cursorPosition);
}
if (symbols.length == 0)
return;

View File

@ -169,3 +169,19 @@ bool doUFCSSearch(string beforeToken, string lastToken)
// we do the search if they are different from eachother
return beforeToken != lastToken;
}
void getUFCSParenCompletion(ref DSymbol*[] symbols, Scope* completionScope, istring firstToken, istring nextToken, size_t cursorPosition)
{
DSymbol* firstSymbol = completionScope.getFirstSymbolByNameAndCursor(firstToken, cursorPosition);
DSymbol*[] possibleUFCSSymbol = completionScope.getSymbolsByNameAndCursor(nextToken, cursorPosition);
foreach(nextSymbol; possibleUFCSSymbol){
if (nextSymbol && nextSymbol.functionParameters)
{
if (firstSymbol.type is nextSymbol.functionParameters.front.type)
{
nextSymbol.kind = CompletionKind.ufcsName;
symbols ~= nextSymbol;
}
}
}
}

View File

@ -0,0 +1,3 @@
calltips
void showSomething(int x, string message, bool ok)
void showSomething(int x, string message, bool ok, float percentage)

View File

@ -0,0 +1,7 @@
void showSomething(int x, string message, bool ok){}
void showSomething(int x, string message, bool ok, float percentage){}
void main(){
int x;
x.showSomething(
}

View File

@ -0,0 +1,5 @@
set -e
set -u
../../bin/dcd-client $1 -c163 file.d > actual.txt
diff actual.txt expected.txt