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.

Bug 120491 - Provide compatibility with the HTML indentation/formatting infrastructure
Summary: Provide compatibility with the HTML indentation/formatting infrastructure
Status: RESOLVED FIXED
Alias: None
Product: ruby
Classification: Unclassified
Component: Editing (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Torbjorn Norbye
URL:
Keywords:
Depends on:
Blocks: 109262 116231
  Show dependency tree
 
Reported: 2007-10-30 16:20 UTC by Tomasz Slota
Modified: 2007-10-31 21:22 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomasz Slota 2007-10-30 16:20:31 UTC
The easiest way to assure compliance with the HTML indentation/formatting infrastructure is to make sure the following assertions are true:  

- the formatter for html/text mime type always is called first
- HTML_FORMATTER_ACTS_ON_TOP_LEVEL document property is set to a non-null value for every rhtml document
Comment 1 Torbjorn Norbye 2007-10-30 18:14:56 UTC
Hi Tomasz,
I thought both of these assertions should already be true; have you observed anything to the contrary or did you just
file this to make sure?

I have an RhtmlIndentTask, which should always be called first since it's the top-level language in an RHTML file. It
looks like this:

    public static void reindent(BaseDocument doc, int start, int end) throws BadLocationException {
//        doc.putProperty(HTMLLexerFormatter.HTML_FORMATTER_ACTS_ON_TOP_LEVEL, Boolean.TRUE);
        doc.putProperty("HTML_FORMATTER_ACTS_ON_TOP_LEVEL", Boolean.TRUE);
        int offset = Utilities.getRowStart(doc, end);
        org.netbeans.editor.Formatter editorFormatter = doc.getFormatter();
        while (offset >= start) {
            editorFormatter.changeRowIndent(doc, offset, 0);

            if (offset > 0) {
                // XXX >= ? What about empty first line?
                offset--;
                offset = Utilities.getRowStart(doc, offset);
            } else {
                break;
            }
        }
    }

As you can see it first sets HTML_FORMATTER_ACTS_ON_TOP_LEVEL.  It also reindents all lines to line 0 before the HTML
indenter runs (to preserve the original semantics of the HTML formatter which the RHTML indenter was relying on.)

Also, there is custom code in editor/indent's TaskHandler class to ensure that the Ruby indenter is always called last
(e.g. after the HTML indenter) - look for x-ruby in there.
Comment 2 Torbjorn Norbye 2007-10-30 18:25:21 UTC
Tomasz, I see that the following RHTML indentation scenario is still broken (this is from issue 116231)

<div>
  <%if session[:user]%>
  <%end%>
  <div>$cursor is here</div>
</div>

In issue 116231 you said to file separate bugs for RHTML specific things; do you want a separate issue for the above?
Can you reproduce it? What else can I do to help?
Comment 3 Tomasz Slota 2007-10-31 15:09:58 UTC
The latter assertion is already satisfied (sorry, I had a debugging problem).

However when indenting new line IndentTask for 'application/x-httpd-eruby' is called before IndentTask for 'text/html'. 
The HTML formatter/indent task should be always called first, i.e. before Ruby, CSS, JavaScript, etc. formatters 
Comment 4 Torbjorn Norbye 2007-10-31 15:18:49 UTC
Hi Tomasz, the application/x-httpd-eruby indent task is not the Ruby indenter, it's the RHTML indent task that I showed
in my bug entry yesterday: it's the one which SETS the HTML_FORMATTER_ACTS_ON_TOP_LEVEL property, as well as moves all
the content to column 0.  Without that, the HTML formatter no longer reindented text (only the first line, it left all
the other lines relative) and that breaks my compound indentation.

I'll play with turning that off and seeing if things work better now with all the other fixes, but basically, if HTML
treats the Ruby embedded sections as text, then it needs to move

   hello
     <% foo %>
 bar

to all have the same left-side alignment.

(Are you doing compound-indentation for JSP? E.g. the HTML block tags indent the JSP tags, and logic inside the JSP tags
can further indent the text inside? e.g.

<div>
   <% if (true) { %>
     <span>Extra indented because of the if
   <% } %>
   <span>only indented for the <div>
</div>
<span>not indented at all</span>

The HTML formatter used to align all text lines, which is how I was able to figure out where the logical block tags are.
Thus, after the HTML indenter ran, all I had to do was add indentation inside logical Ruby sections. 

Does this make sense?
Comment 5 Tomasz Slota 2007-10-31 16:27:21 UTC
Hi Tor, 

Are you moving the content to column to 0 only for lines that belong completely to Ruby (and not lines that start with some HTML)? In such case it should be 
OK, otherwise it will break the new line indentation algorithm (it looks like it is the case now).

Instead moving the content to column 0 in a separate pre-formatter can't you just adjust indentation of each line in the Ruby block to match the first line?

Comment 6 Torbjorn Norbye 2007-10-31 21:22:03 UTC
It looks like removing the pre-html-indentataion column adjustment is no longer necessary so I've taken it out. That
means that I'm now doing everything this issue is calling for: Having the top-level flag set before HTML indentation is
performed, and having Ruby formatting happen -after- html indentation.