langium icon indicating copy to clipboard operation
langium copied to clipboard

Proposal missing from the content assist

Open ydaveluy opened this issue 1 year ago • 4 comments

Hey !

I probably found a minor issue in the content assist in case of multiple keyword alternatives. It seems that if the previous token is of a keyword kind, this keyword is not proposed by the content assist.

Langium version: 3.1 Package name: Langium

Steps To Reproduce

  1. Open this playground
  2. Ctrl+space on line 4

The current behavior

The content assist propose to create a new 'student' but not an other 'teacher'. After a 'student', the content assist propose to create a 'teacher' but not an other 'student'.

The expected behavior

The content assist should propose a 'student' and a 'teacher' in all cases.

ydaveluy avatar Sep 13 '24 15:09 ydaveluy

Hm, interesting. It's also pretty interest that this can be pretty easily fixed by using a small refactoring of the grammar. See here.

msujew avatar Sep 13 '24 19:09 msujew

Yes, in your refactoring, 'student' and 'teacher' are on different AstNodes, and it works properly.

In my case, I think the issue comes from DefaultCompletionProvider.findFeaturesAt, which does not return the previous feature, but I don't fully understand how this function works.

ydaveluy avatar Sep 13 '24 20:09 ydaveluy

Yeah, I'm not saying that this isn't a bug - but there are at least in theory ways to circumvent this. I've added this to https://github.com/eclipse-langium/langium/issues/1678.

msujew avatar Sep 14 '24 08:09 msujew

Thanks for the workaround.

I continued investigating this issue and I noticed that we enter in this branch for the missing feature: https://github.com/eclipse-langium/langium/blob/b2a6fe9684434117eb6a344fc2721e3c26d989bf/packages/langium/src/lsp/completion/follow-element-computation.ts#L131

It means that the previous feature is added in the visited Set somewhere before processing the Group.

ydaveluy avatar Sep 17 '24 06:09 ydaveluy