eclipse-langium / langium

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

Proposal missing from the content assist #1677

Open ydaveluy opened 1 month ago

ydaveluy commented 1 month ago

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.

msujew commented 1 month ago

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

ydaveluy commented 1 month ago

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.

msujew commented 1 month ago

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.

ydaveluy commented 1 month ago

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.