From 2457f70b8e914af8ba980b7907161bca32fae543 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Wed, 7 Dec 2022 20:38:18 +0100 Subject: [PATCH] use `isCallableWithArg` in paren completion For consistency and to allow future changes to type matching (e.g. implicit type conversion) --- src/dcd/server/autocomplete/ufcs.d | 26 ++++++++++++++------------ tests/tc_ufcs_calltip_in_func/file.d | 4 ++++ tests/tc_ufcs_calltip_in_func/run.sh | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/dcd/server/autocomplete/ufcs.d b/src/dcd/server/autocomplete/ufcs.d index 8bc4d5f..b6ba298 100644 --- a/src/dcd/server/autocomplete/ufcs.d +++ b/src/dcd/server/autocomplete/ufcs.d @@ -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; } } } -} \ No newline at end of file +} diff --git a/tests/tc_ufcs_calltip_in_func/file.d b/tests/tc_ufcs_calltip_in_func/file.d index cbdb8d1..5299951 100644 --- a/tests/tc_ufcs_calltip_in_func/file.d +++ b/tests/tc_ufcs_calltip_in_func/file.d @@ -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; diff --git a/tests/tc_ufcs_calltip_in_func/run.sh b/tests/tc_ufcs_calltip_in_func/run.sh index 16cb3c4..9701891 100755 --- a/tests/tc_ufcs_calltip_in_func/run.sh +++ b/tests/tc_ufcs_calltip_in_func/run.sh @@ -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