This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
RHTML formatting no longer works for a lot of typical RHTML pages. This is due to some changes in the way HTML indentation works, and I believe I can work around most of them, but I've encountered two blocking problems. The following RHTML fragment will no longer indent: <tr class="<%= article.status %>"> <td></td> </tr> In Beta 1, it gets indented as expected: <tr class="<%= article.status %>"> <td></td> </tr> However, with trunk bits (and Ruby formatting disabled, so it's just the HTML indenter that operates on the buffer), it doesn't realign the inner <td></td> based on the outer <tr>. In fact, it seems not to modify any formatting at all. The problem appears to be the embedded RHTML token within the <tr> tag, inside the class attribute. If I remove it, everything works okay. However, this is unfortunately a -very- common idiom in RHTML files, so we have to support it - and it worked before. It also takes very little to upset the editor; inserting newlines in some places will post exception popups: javax.swing.text.BadLocationException: Invalid offset=-1 not within <0, 60> at org.netbeans.editor.Utilities.checkOffsetValid(Utilities.java:1309) at org.netbeans.editor.Utilities.getLineOffset(Utilities.java:591) at org.netbeans.modules.editor.structure.formatting.TagBasedLexerFormatter.calcIndents_processOpeningTag(TagBasedLexerFormatter.java:163) at org.netbeans.modules.editor.structure.formatting.TagBasedLexerFormatter.reformat(TagBasedLexerFormatter.java:281) at org.netbeans.modules.html.editor.indent.HtmlIndentTask.reindent(HtmlIndentTask.java:50) at org.netbeans.modules.editor.indent.TaskHandler$MimeItem.runTask(TaskHandler.java:350) at org.netbeans.modules.editor.indent.TaskHandler.runTasks(TaskHandler.java:213) This means RHTML editing, not just formatting, is hosed at the moment which is why I'm making this a P1. Note that there is one key difference between the lexing in Beta 1 and the trunk: The language embedding sections are no longer using joinSections for LanguageEmbedding.create. I turned them off recently because something changed in the lexer which was causing problems for indentation. But you can re-enable it using this patch in case this helps (possibly html should have joinSections=true and Ruby have joinSections=false): Index: ruby/rhtml/src/org/netbeans/modules/ruby/rhtml/lexer/api/RhtmlTokenId.java =================================================================== RCS file: /cvs/ruby/rhtml/src/org/netbeans/modules/ruby/rhtml/lexer/api/RhtmlTokenId.java,v retrieving revision 1.4 diff -u -r1.4 RhtmlTokenId.java --- ruby/rhtml/src/org/netbeans/modules/ruby/rhtml/lexer/api/RhtmlTokenId.java 6 Sep 2007 19:17:01 -0000 1.4 +++ ruby/rhtml/src/org/netbeans/modules/ruby/rhtml/lexer/api/RhtmlTokenId.java 20 Sep 2007 23:44:11 -0000 @@ -94,10 +94,10 @@ LanguagePath languagePath, InputAttributes inputAttributes) { switch(token.id()) { case HTML: - return LanguageEmbedding.create(HTMLTokenId.language(), 0, 0, false); + return LanguageEmbedding.create(HTMLTokenId.language(), 0, 0, true); case RUBY_EXPR: case RUBY: - return LanguageEmbedding.create(RubyTokenId.language(), 0, 0, false); + return LanguageEmbedding.create(RubyTokenId.language(), 0, 0, true); default: return null; }
*** Issue 116235 has been marked as a duplicate of this issue. ***
Formatting is broken by exception thrown when there is a language embedded *inside a tag*. This can be also reproduced in JSP with the following code: <tr class="<%= page %>"> <td></td> </tr> I will probably need support from lexer to fix this. I suggest downgrading to P2.
The reason I made it a P1 was the exception popup which occurs whenever you try to edit the file. If that can be resolved (and the exception is coming from TagBasedLexerFormatter), then the rest of the issue can be a P2 - as long as that doesn't mean it won't get done for 6.0 :) Is there anything I can do to help? Do you need a new issue filed against lexer or are you already talking to Mila? As a fallback plan for 6.0 (if we don't get this done), perhaps we can keep the old HTML formatter around, and in the HtmlIndentTask, invoke it whenever we see that the outermost language has mimetype "application/x-httpd-eruby". But this is definitely only an emergency solution. Unfortunately, I think I have to make other changes to the RHTML indenter too (after the above bug is fixed) to address the fact that <% %> sections are no longer indented by the HTML indenter, and so on. So, hopefully this bug won't be fixed at the very last minute before the deadline since I need additional time :) Here's a patch which restores RHTML formatting for now as described above (it -does- expose a lexer bug on some source files) Index: html/editor/src/org/netbeans/modules/html/editor/indent/HtmlIndentTask.java =================================================================== RCS file: /cvs/html/editor/src/org/netbeans/modules/html/editor/indent/HtmlIndentTask.java,v retrieving revision 1.2 diff -u -r1.2 HtmlIndentTask.java --- html/editor/src/org/netbeans/modules/html/editor/indent/HtmlIndentTask.java 17 Sep 2007 15:40:18 -0000 1.2 +++ html/editor/src/org/netbeans/modules/html/editor/indent/HtmlIndentTask.java 21 Sep 2007 15:25:10 -0000 @@ -47,6 +47,15 @@ } public void reindent() throws BadLocationException { + // Workaround for http://www.netbeans.org/issues/show_bug.cgi?id=116231 + String mimeType = NbEditorUtilities.getMimeType(context.document()); + if (mimeType != null && mimeType.equals("application/x-httpd-eruby")) { // NOI18N + new org.netbeans.editor.ext.html.HTMLFormatter(HTMLKit.class). + reformat((BaseDocument) context.document(), + context.startOffset(), context.endOffset(), true);; + return; + } + getFormatter().reformat((BaseDocument) context.document(), context.startOffset(), context.endOffset(), true); }
OK, the error window didn't pop up with my config. I already worked around the missing lexer infrastructure and am very close to having this issue fixed, it will not happen today though.
Fixed. Checking in web/jspsyntax/src/org/netbeans/modules/web/core/syntax/formatting/JSPLexerFormatter.java; /cvs/web/jspsyntax/src/org/netbeans/modules/web/core/syntax/formatting/JSPLexerFormatter.java,v <-- JSPLexerFormatter.java new revision: 1.4; previous revision: 1.3 done Checking in html/editor/lib/src/org/netbeans/editor/ext/html/HTMLLexerFormatter.java; /cvs/html/editor/lib/src/org/netbeans/editor/ext/html/HTMLLexerFormatter.java,v <-- HTMLLexerFormatter.java new revision: 1.6; previous revision: 1.5 done Checking in xml/tageditorsupport/src/org/netbeans/modules/editor/structure/formatting/TagBasedLexerFormatter.java; /cvs/xml/tageditorsupport/src/org/netbeans/modules/editor/structure/formatting/TagBasedLexerFormatter.java,v <-- TagBasedLexerFormatter.java new revision: 1.13; previous revision: 1.12 done
I updated my netbeans as soon as this got fixed. However, there are still some small problems with indentation. 1. extra indent before closing tag after formatting 2. after pressing enter, extra indent inserted before the line under the cursor I've been trying to simplify the case but it played hide-and-seek. Here is as far as I can get: <div> <%if session[:user]%> <%end%> </div> After Alt+Shift+F <div> <%if session[:user]%> <%end%> </div> Or <div> <%if session[:user]%> <%end%> <div>$cursor is here</div> </div> After pressing enter <div> <%if session[:user]%> <%end%> <div> </div> </div> Netbeans is my favorite ruby IDE. Thank you for the great work! I hope I'm providing helpful information.
Thank you for your feedback arrix. The HTML formatting/indentation has been undergoing massive changes, hopefully the situation is stabilized now. I've just committed a few fixes in the new line line indentation area, they are not present in any build yet. Tor please have a look at the RHTML-specific issues, if there are problems please file separate bugs.
I examined the specific scenario which is still reproducible: <div> <%if session[:user]%> <%end%> </div> It turns out that the JRuby lexer is incorrectly passing the second "]" as an identifier token rather than an RBRACKET, which breaks the formattter. I added a similar workaround to one I have for a few "[" identifiers instead of LBRACKETs and formatting now passes this test. I believe everything else should work in RHTML indentation now (and in particular the two previous broken code fragments listed in this bug report), so closing this older issue as fixed.