| Summary: | [Auto Edit] Issue with comment terminals with common prefix | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Dénes Harmath <thsoft> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | anton, sebastian.zarnekow, thsoft |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | Macintosh | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | v2.4.3 | ||
With 2.4.2.v201306120542, only one problem remains: when typing %{ into an empty document, it is autocompleted to %{}, not %{%}
Preliminary scheduled for 2.4.3 since Anton's currently looking into auto edit anyway. Pushed to Gerrit: https://git.eclipse.org/r/#/c/14772/ It seems that the issue is with the grammar. Both single line comment and multiline comment start with % character. So if you type %{ then it will be beginning of single line comment and there is no reason to add %}. Autocompletion of } in that case is the bug because we don't support auto edit for {} in the context of single line comment. You can try to use two % character in a row for SL_COMMENT to overcome ambiguity: terminal SL_COMMENT: "%%" !("\n" | "\r")* ("\r"? "\n")?; But in that case you will run into the problem with auto edit for %{%} in the single line. So if you type %{ you will get %{}. The reason is that the auto edit for {} works before auto edit for %{%}. You will have to change the order to fix this problem: package org.xtext.example.mydsl.ui.editor.autoedit import org.eclipse.xtext.ui.editor.autoedit.DefaultAutoEditStrategyProvider import org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategyProvider.IEditStrategyAcceptor import org.eclipse.jface.text.IDocument import org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper class Bug351644AutoEditStrategyProvider extends DefaultAutoEditStrategyProvider { override configure(IEditStrategyAcceptor acceptor) { configureIndentationEditStrategy(acceptor); configureStringLiteral(acceptor); configureParenthesis(acceptor); configureSquareBrackets(acceptor); configureMultilineComments(acceptor); // (1) <-- swop these two lines configureCurlyBracesBlock(acceptor); // (2) configureCompoundBracesBlocks(acceptor); } override protected configureMultilineComments(extension IEditStrategyAcceptor acceptor) { singleLineTerminals.newInstance("%{", "%}").accept(IDocument.DEFAULT_CONTENT_TYPE); multiLineTerminals.newInstance("%{", null, "%}").accept(IDocument.DEFAULT_CONTENT_TYPE); multiLineTerminals.newInstance("%{", null, "%}").accept(TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION); } } Merged into repo. Requested via bug 522520. -M. Requested via bug 522520. -M. |
Build Identifier: I20110613-1736 My grammar's comment terminal rules look like this: terminal SL_COMMENT: "%" !("\n" | "\r")* ("\r"? "\n")?; terminal ML_COMMENT: "%{" -> "%}"; I register a SingleLineTerminalsStrategy and a MultiLineTerminalsStrategy for %{ %}. There are two problems: - When typing %{ into an empty document, it is not autocompleted. (Condition "command.text.length() - command.length + documentContent.length() >= getLeftTerminal().length()" in SingleLineTerminalsStrategy returns false.) - Otherwise, when having typed %{, it is autocompleted, and I press enter, no indentation is applied. I get %{ <cursor>%} instead of %{ <cursor> %} Reproducible: Always