Adding non contrainted templates into ufcs completion

This commit is contained in:
davu 2023-03-13 19:17:33 +01:00 committed by Jan Jurzitza
parent e6b94622f0
commit 2fd33fc27f
2 changed files with 27 additions and 3 deletions

View File

@ -658,7 +658,6 @@ ScopeSymbolPair generateAutocompleteTreesProd(string source, string filename, si
version (linux)
{
import std.string;
enum string ufcsExampleCode =
q{class Incrementer
{
@ -690,4 +689,30 @@ void doIncrement()
assert(pair.ufcsSymbols[0].name == "increment");
}
enum string ufcsTemplateExampleCode =
q{int increment(T)(T x)
{
return x++;
}
void doIncrement()
{
int life = 42;
life.
}};
unittest
{
import dsymbol.ufcs;
writeln("Getting Templated UFCS Symbols For life");
ModuleCache cache;
// position of variable life
size_t cursorPos = 82;
auto pair = generateAutocompleteTreesProd(ufcsTemplateExampleCode, randomDFilename, cursorPos, cache);
assert(pair.ufcsSymbols.length > 0);
assert(pair.ufcsSymbols[0].name == "increment");
}
}

View File

@ -65,7 +65,6 @@ private DSymbol* deduceSymbolType(DSymbol* symbol)
private bool isInvalidForUFCSCompletion(const(DSymbol)* beforeDotSymbol)
{
return beforeDotSymbol is null
|| beforeDotSymbol.kind == CompletionKind.templateName
|| beforeDotSymbol.name is getBuiltinTypeName(tok!"void")
|| (beforeDotSymbol.type !is null && beforeDotSymbol.type.name is getBuiltinTypeName(
tok!"void"));
@ -307,11 +306,11 @@ bool isCallableWithArg(DSymbol* incomingSymbol, const(DSymbol)* beforeDotType, b
.functionParameters.empty)
{
if (beforeDotType is incomingSymbol.functionParameters.front.type
|| incomingSymbol.functionParameters.front.type.kind is CompletionKind.typeTmpParam // non constrained template
|| willImplicitBeUpcasted(beforeDotType.name, incomingSymbol
.functionParameters.front.type.name)
|| matchAliasThis(beforeDotType, incomingSymbol, recursionDepth))
{
// incomingSymbol.kind = CompletionKind.ufcsName;
return true;
}