dlang-community / DCD

The D Completion Daemon is an auto-complete program for the D programming language
GNU General Public License v3.0
349 stars 71 forks source link

Removing ufcs for non constrained template #728

Closed vushu closed 1 year ago

vushu commented 1 year ago

@WebFreak001 I thought that CompletionKind.tmpTmpParam respected if statements before the function body, it states symbol.d:105 type template parameter when no constraint, which should not included if's before function body?

so I thought for that the example below was not included.

bool isSorted(alias less = "a < b", Range)(Range r)
if (isForwardRange!(Range)
{
...
}

Since I mistook that, it is probably best to disable this feature.

Could we somehow use the compiler or dmd-fe to deduce template constraints?

WebFreak001 commented 1 year ago

template constraints are e.g. void foo(T : int)(T x)

constrained template arguments probably get resolved to the constraint type for auto-complete I guess?

You need to check on the function symbol if it has any if constraints. We could probably store it in the bitflags that's mostly unused in the symbol.

vushu commented 1 year ago

Hmm okay I will try to take a look at it.

vushu commented 1 year ago

@WebFreak001 do you mean adding one more flag to SymbolQualifier?

WebFreak001 commented 1 year ago

I meant a good place is probably the

    // dfmt off
    mixin(bitfields!(bool, "ownType", 1,
        bool, "skipOver", 1,
        ubyte, "", 6));
    // dfmt on

e.g. having a

/* `true` if there is a template constraint, e.g. `if (is(T == foo))` that references this type */
bool, "isMentionedInTemplateConstraint", 1,

or maybe it would instead make more sense to have extra symbols as children of the template symbol, with a qualifier set to constraint.

What do you think?

vushu commented 1 year ago

@WebFreak001 I think I like the second idea since it stores more data, maybe we also can store the if parameters to further deduce if the cursorSymbol is allowed to use the function?

vushu commented 1 year ago

Im closing this and will come up with a solution for this.