Community
Participate
Working Groups
Created attachment 257816 [details] Source code triggering the formatting error. I get a illegal argument exception when formatting a particular piece of source code: package com.iar.jsonrpc class FormattingBug { def foo() { val x = 2 ''' // Formatting is ok if the blank line after the IF below is removed. «IF x > 0» «ENDIF» ''' } } (I've attached the source file also.) The exception is: java.lang.IllegalArgumentException: length must be >= 0 at com.google.common.base.Preconditions.checkArgument(Preconditions.java:93) at org.eclipse.xtext.formatting2.regionaccess.internal.TextReplacement.<init>(TextReplacement.java:24) at org.eclipse.xtext.formatting2.regionaccess.internal.TextRegionRewriter.createReplacement(TextRegionRewriter.java:79) at org.eclipse.xtext.formatting2.regionaccess.internal.AbstractTextSegment.replaceWith(AbstractTextSegment.java:117) at org.eclipse.xtext.formatting2.internal.WhitespaceReplacer.createReplacements(WhitespaceReplacer.java:92) at org.eclipse.xtext.formatting2.internal.FormattableDocument.createReplacements(FormattableDocument.java:143) at org.eclipse.xtext.formatting2.internal.FormattableDocument.renderToTextReplacements(FormattableDocument.java:281) at org.eclipse.xtext.formatting2.AbstractFormatter2.format(AbstractFormatter2.java:270) at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter.exec(ContentFormatter.java:90) at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter$FormattingUnitOfWork.exec(ContentFormatter.java:57) at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter$FormattingUnitOfWork.exec(ContentFormatter.java:1) at org.eclipse.xtext.resource.OutdatedStateManager.exec(OutdatedStateManager.java:121) at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.internalReadOnly(XtextDocument.java:520) at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.priorityReadOnly(XtextDocument.java:485) at org.eclipse.xtext.ui.editor.model.XtextDocument.priorityReadOnly(XtextDocument.java:142) at org.eclipse.xtext.ui.editor.formatting2.ContentFormatter.format(ContentFormatter.java:103) at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:1023)
Some more detail: the culprit seem to be the empty line after the IF. If I replace the empty line with a line containing spaces (so that the amount of space aligns with the IF), then formatting works. Hope this helps in figuring out the problem.
can be reproduced with 2.11 problem is in RichStringFormatter.format(RichString richString, IFormattableDocument doc) (length is < 0 since rootIndentLenght > line.indentLength @Mortiz: Should that line be formatted at all? fixing the length to zero would result in «IF x > 0» «ENDIF» not formatting would result in «IF x > 0» «ENDIF» or should the emply line be kept
the empty line should be kept. The general rule is that the formatter must only (and should) change whitespace that does not impact the template's output. That's generally *not* the white-space highlighted as "grey-space", but other whitespace and also whitespace inside « ».
*** Bug 521909 has been marked as a duplicate of this bug. ***