eclipse-xtext / eclipse-xtext/xtext
AbstractContentAssistTest: incorrect cursor position calculation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
I would like to customize the cursor position after a proposal has been applied. After adapting the Proposal Provider, I got the right behaviour in the Xtext Editor, but the corresponding ContentAssistant test case fails.
Step to reproduce:
- Create a new Xtext project with the default settings (org.xtext.example.mydsl)
- Replace the MyDslProposalProvider by the following implementation:
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
override complete_Greeting(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
val completionProposal = createCompletionProposal("Hello2", context) as ConfigurableCompletionProposal
completionProposal.cursorPosition = 3
acceptor.accept(completionProposal)
}
}
- Create an empty test.mydsl file in a runtime project. The content assistant offers two proposals ("Hello", "Hello2"). After applying the "Hello2" proposal, the cursor is placed between the two l letters.
- However, the corresponding test case implementation
package org.xtext.example.mydsl.ui.tests;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.ui.testing.AbstractContentAssistTest;
import org.junit.Test;
import org.junit.runner.RunWith;
@SuppressWarnings("restriction")
@RunWith(XtextRunner.class)
@InjectWith(MyDslUiInjectorProvider.class)
public class ContentAssistTest extends AbstractContentAssistTest {
@Test
public void emptyTest() throws Exception{
newBuilder().assertText("Hello", "Hello2").applyProposal("Hello2").assertCursorIsAfter("Hel");
}
}
fails reporting the following message: java.lang.AssertionError: cursor should be after 'Hel' but it's after Hello2.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with AbstractContentAssistTest and the ContentAssistTest example shown in the issue, then run the reproduced empty-test scenario in an Xtext UI test project. Compare the cursor position reported after applying "Hello2" with the proposal's configured position. Done means the test and editor agree on the cursor location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100