Skip to content

Commit 2457f70

Browse files
committed
use isCallableWithArg in paren completion
For consistency and to allow future changes to type matching (e.g. implicit type conversion)
1 parent 4fd12cf commit 2457f70

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/dcd/server/autocomplete/ufcs.d

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,26 @@ DSymbol*[] getSymbolsForUFCS(Scope* completionScope, const(DSymbol)* beforeDotSy
107107
}
108108

109109
/**
110-
Params:
111-
symbol = the symbol to check
112-
incomingSymbol = symbols we check on
113-
Returns:
114-
true if incomingSymbols first parameter matches beforeDotSymbol
115-
false otherwise
116-
*/
117-
bool isCallableWithArg(const(DSymbol)* incomingSymbol, const(DSymbol)* beforeDotSymbol, bool isGlobalScope = false)
110+
* Params:
111+
* incomingSymbol = the function symbol to check if it is valid for UFCS with `beforeDotType`.
112+
* beforeDotType = the type of the expression that's used before the dot.
113+
* isGlobalScope = the symbol to check
114+
* Returns:
115+
* `true` if `incomingSymbols`' first parameter matches `beforeDotType`
116+
* `false` otherwise
117+
*/
118+
bool isCallableWithArg(const(DSymbol)* incomingSymbol, const(DSymbol)* beforeDotType, bool isGlobalScope = false)
118119
{
119-
if (isGlobalScope && incomingSymbol.protection == tok!"private")
120+
if (!incomingSymbol || !beforeDotType
121+
|| (isGlobalScope && incomingSymbol.protection == tok!"private"))
120122
{
121123
return false;
122124
}
123125

124126
if (incomingSymbol.kind == CompletionKind.functionName && !incomingSymbol
125127
.functionParameters.empty)
126128
{
127-
return incomingSymbol.functionParameters.front.type is beforeDotSymbol;
129+
return incomingSymbol.functionParameters.front.type is beforeDotType;
128130
}
129131

130132
return false;
@@ -181,11 +183,11 @@ void getUFCSParenCompletion(ref DSymbol*[] symbols, Scope* completionScope, istr
181183
foreach(nextSymbol; possibleUFCSSymbol){
182184
if (nextSymbol && nextSymbol.functionParameters)
183185
{
184-
if (firstSymbol.type is nextSymbol.functionParameters.front.type)
186+
if (nextSymbol.isCallableWithArg(firstSymbol.type))
185187
{
186188
nextSymbol.kind = CompletionKind.ufcsName;
187189
symbols ~= nextSymbol;
188190
}
189191
}
190192
}
191-
}
193+
}

tests/tc_ufcs_calltip_in_func/file.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
void showSomething(int x, string message, bool ok){}
22
void showSomething(int x, string message, bool ok, float percentage){}
3+
void showSomething(string x, string message, bool ok){}
4+
void showSomething(){}
5+
int showSomething;
6+
struct showSomething { int x; }
37

48
void main(){
59
int x;

tests/tc_ufcs_calltip_in_func/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set -e
22
set -u
33

4-
../../bin/dcd-client $1 -c163 file.d > actual.txt
4+
../../bin/dcd-client $1 -c293 file.d > actual.txt
55
diff actual.txt expected.txt

0 commit comments

Comments
 (0)