use `isCallableWithArg` in paren completion

For consistency and to allow future changes to type matching (e.g.
implicit type conversion)
This commit is contained in:
WebFreak001 2022-12-07 20:38:18 +01:00 committed by Jan Jurzitza
parent 4fd12cf485
commit 2457f70b8e
3 changed files with 19 additions and 13 deletions

View File

@ -107,16 +107,18 @@ DSymbol*[] getSymbolsForUFCS(Scope* completionScope, const(DSymbol)* beforeDotSy
}
/**
Params:
symbol = the symbol to check
incomingSymbol = symbols we check on
Returns:
true if incomingSymbols first parameter matches beforeDotSymbol
false otherwise
*/
bool isCallableWithArg(const(DSymbol)* incomingSymbol, const(DSymbol)* beforeDotSymbol, bool isGlobalScope = false)
* Params:
* incomingSymbol = the function symbol to check if it is valid for UFCS with `beforeDotType`.
* beforeDotType = the type of the expression that's used before the dot.
* isGlobalScope = the symbol to check
* Returns:
* `true` if `incomingSymbols`' first parameter matches `beforeDotType`
* `false` otherwise
*/
bool isCallableWithArg(const(DSymbol)* incomingSymbol, const(DSymbol)* beforeDotType, bool isGlobalScope = false)
{
if (isGlobalScope && incomingSymbol.protection == tok!"private")
if (!incomingSymbol || !beforeDotType
|| (isGlobalScope && incomingSymbol.protection == tok!"private"))
{
return false;
}
@ -124,7 +126,7 @@ bool isCallableWithArg(const(DSymbol)* incomingSymbol, const(DSymbol)* beforeDot
if (incomingSymbol.kind == CompletionKind.functionName && !incomingSymbol
.functionParameters.empty)
{
return incomingSymbol.functionParameters.front.type is beforeDotSymbol;
return incomingSymbol.functionParameters.front.type is beforeDotType;
}
return false;
@ -181,11 +183,11 @@ void getUFCSParenCompletion(ref DSymbol*[] symbols, Scope* completionScope, istr
foreach(nextSymbol; possibleUFCSSymbol){
if (nextSymbol && nextSymbol.functionParameters)
{
if (firstSymbol.type is nextSymbol.functionParameters.front.type)
if (nextSymbol.isCallableWithArg(firstSymbol.type))
{
nextSymbol.kind = CompletionKind.ufcsName;
symbols ~= nextSymbol;
}
}
}
}
}

View File

@ -1,5 +1,9 @@
void showSomething(int x, string message, bool ok){}
void showSomething(int x, string message, bool ok, float percentage){}
void showSomething(string x, string message, bool ok){}
void showSomething(){}
int showSomething;
struct showSomething { int x; }
void main(){
int x;

View File

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