Some notices won't go away

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Some notices won't go away

Postby Filip » Thu Mar 08, 2012 11:00 am

Hi, first of all thanks for this great component!

I have a custom parser that extends AbstractParser and in its parse() method, it uses "result.addNotice(n)" to add instances of DefaultParserNotice.

Everything seems to work real well, but sometimes a notice stays there and won't go away (even though the parse() method does not return any notices at all). You can type in the underlined text, and the notice seems to maintain the position in the document (grows/shrinks as you type).

Do you have any idea where I should look?

My parser class looks like this:

Code: Select all
class MyParser extends AbstractParser {
    private DefaultParseResult result;

    MyParser() {
        result = new DefaultParseResult(this);
        // ....
    }
    public ParseResult parse(RSyntaxDocument doc, String style) {
        result.clearNotices();
        Element root = doc.getDefaultRootElement();
        result.setParsedLines(0, root.getElementCount()-1);
        try {
          // ...
                  DefaultParserNotice n = new DefaultParserNotice(
                            this,
                            error.getMessage(), // a String
                            rowNumber(error.getStart(), doc),
                            error.getStart(),
                            Math.max(error.getEnd() - error.getStart() + 1, 1));
                  if ( error.getError_type().equals(ExpressionErrorType.semantic_error) ) {
                    n.setLevel(DefaultParserNotice.WARNING);
                    n.setColor(new Color(0, 192, 0));
                  }
                  else {
                    n.setLevel(DefaultParserNotice.ERROR);
                    n.setColor(new Color(255, 0, 0));
                  }
                  result.addNotice(n);
          // ...
        } catch (Exception e) {
           System.out.println(e.getStackTrace());
        }

        return result;
    }

    private int rowNumber(int position, RSyntaxDocument doc) {
        for (int i = 0; i < doc.getDefaultRootElement().getElementCount(); i++) {
            Element e = doc.getDefaultRootElement().getElement(i);
            if (position >= e.getStartOffset() && position <= e.getEndOffset())
                return i + 1;
        }
        return doc.getRootElements().length;
    }
}


Thanks,
Filip
Filip
 

Re: Some notices won't go away

Postby robert » Thu Mar 08, 2012 2:12 pm

I just saw this the other day with the Perl language support. Something's definitely fishy, I'll take a look.

Just one idea off the top of my head - are your ParserNotices covering a range including the trailing newline of a line? It shouldn't cause problems, of course, and I don't know if that's what the culprit is; just thinking out loud.

Things just keep pushing back that next RSTA release!
User avatar
robert
 
Posts: 774
Joined: Sat May 10, 2008 5:16 pm

Re: Some notices won't go away

Postby Filip » Thu Mar 08, 2012 2:29 pm

Thanks for the response. It does not seem to be the case, most of the time the notices appear on a line like this:

set(grouping_start, gr_start)


(the lingering notice is underlining the identifier grouping_start).

I'm "happy" that it is happening elsewhere as well. Currently I seem to have one case that keeps happening consistently, so if you find something I should be able to test that. Unfortunately my environment is so huge that I can't easily send a repro.
Filip
 

Re: Some notices won't go away

Postby robert » Mon Mar 12, 2012 3:25 am

Please grab the latest from SVN and try again. If there were > 1 ParserNotices for a single line that compared equally via equals(), one of the two would be forgotten (they were eventually stored in a Map vs. a List).
User avatar
robert
 
Posts: 774
Joined: Sat May 10, 2008 5:16 pm

Re: Some notices won't go away

Postby Filip » Mon Mar 12, 2012 8:49 am

Great, this helped! Thanks a lot!

What you say is probably indeed what was happening...I could have had two notices that compared equal.
Filip
 


Return to Help

Who is online

Users browsing this forum: No registered users and 3 guests

cron