eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
665 stars 61 forks source link

langium/lsp: Added 'getReferenceCandidates(...)' hook to 'DefaultCompletionProvider' #1385

Closed sailingKieler closed 4 months ago

sailingKieler commented 4 months ago

… allowing to add the completion-specific scope computation refinements.

sailingKieler commented 4 months ago

Thought: shall the template method also include the call to scope.getAllElements()? That means it would return a Stream, making it very easy to filter elements from the scope without the need to manipulate the scope hierarchy.

Hmm ... I don't have strong opinion here, we could do that yes.

In my case I only manipulated the ReferenceInfo depending on some conditions wrt. the CompetionContext, and then delegated to the scope provider and returned its result.

We could also take { getAllElements: () => Stream<AstNodeDescription> } as return type. Then a Scope would be a valid result, but something like the following is also possible.

    const scope = this.scopeProvider.getScope(refInfo);
    .
    .
    .
    return {
        getAllElements: () => scope.getAllElements().filter(e => ... ),
    };
spoenemann commented 4 months ago

Hmm ... I don't have strong opinion here, we could do that yes.

Imagine cases where you want elements to be linkable, but hide them from completion because they would cause a validation error (e.g. type checking indicates that they don't match).

We could also take { getAllElements: () => Stream<AstNodeDescription> } as return type.

I think just returning the stream is a bit simpler than wrapping it in an object.

sailingKieler commented 4 months ago

You may be right, but then we need a better template method name.