eclipse-xtext / eclipse-xtext/xtext

Xtext LSP Content Assist not showing types with Fragments

Open
#2,755 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help_wanted
Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

Hi,

While using fragments in my grammar, I noticed the types were not showing with the LSP content assist. With the state machine example, I changed the grammar from this:

Transition: event=[Event] '=>' state=[State] ;

to this

fragment StateTransition *: '=>' state=[State] ; Transition: event=[Event] StateTransition ;

And in a unit test that checks the content assist, the "states" are not displayed:

@Test
public void testCompletion()
{
  testCompletion((TestCompletionConfiguration it) -> {
    final var model = "events\n"
              + "    event1 abc\n"
              + "    event2 def\n"
              + "end\n"
              + "\n"
              + "commands\n"
              + "    command1 commandA\n"
              + "    command2 commandB\n"
              + "end\n"
              + "\n"
              + "state initialState\n"
              + "    actions { command1 }\n"
              + "    event1 => nextState\n"
              + "    event2 => finalState\n"
              + "end\n"
              + "\n"
              + "state nextState\n"
              + "    actions { command2 }\n"
              + "    event2 => finalState\n"
              + "end\n"
              + "\n"
              + "state finalState\n"
              + "end\n"
              + "";
      it.setModel(model);
      it.setLine(12);
      it.setColumn(14); // The cursor points after the arrow of "event1" in "initialState"

        final var expected = "finalState (State) -> finalState [[12, 14] .. [12, 14]]\n"
                + "initialState (State) -> initialState [[12, 14] .. [12, 14]]\n"
                + "nextState (State) -> nextState [[12, 14] .. [12, 14]]\n"
                + "";

      it.setExpectedCompletionItems(expected); // actual --> blank
    });
  }

Workaround:

  • Customize "IdeContentProposalProvider" and override the _createProposals(CrossReference, ...) method.

  • Get the content of the parent method and add the following line if "type" is null: type = context.getCurrentModel().eClass();
    Full method here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the unit test's testCompletion case with the grammar fragment and inspect IdeContentProposalProvider, especially createProposals(CrossReference, ...). Compare the completion context and expected items in the example; done means the three State references appear with their State labels and ranges instead of a blank result.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.