ligasgr / intellij-xquery

Plugin to support XQuery in Intellij Idea
Apache License 2.0
35 stars 23 forks source link

Confused string highlighting within an XML text block with {} constructs. #168

Closed rhdunn closed 8 years ago

rhdunn commented 8 years ago

Given:

declare function foo($a, $b) {
    <foo>a is '{$a}<caret></foo>
};
()

Typing ' causes the string from the inserted ' (i.e. '</foo>\n};\n()) to be highlighted with the string colour.

Then typing , b is '{$b}' results in ', b is ' being highlighted as a string, in addition to '</foo>\n};\n().

Selecting the <foo>a is '{$a}', b is '{$b}'</foo> line, cutting it (Ctrl+X) then pasting it (Ctrl+V) results in the correct behaviour -- the a is '{$a}', b is '{$b}' text is highlighted as black text on white.

Selecting that line again, then pasting the previously selected line contents (Ctrl+V) results in only '</foo>\n};\n() being highlighted as a string.

NOTE: The behaviour is the same when using " instead of '.

ligasgr commented 8 years ago

Hey,

Don't know if you are aware but according to the standard strings are mult-line in XQuery.

"abc
def
ghi"

Try this out. It works fine in any implementation. Because of that it's impossible to handle cases like you mentioned because there is no single character that can be reasonably treated as end-of-invalid-string (like new-line in Java for example). What I'm planning to do though is to improve automatic insertion of matching (closing) single/double quote (which doesn't work properly in all the cases). Would that improve your situation?

rhdunn commented 8 years ago

From what I understand, the problem is due to the }' part -- that is closing the inline xquery and continuing the XML text block section. It looks like the parser is getting confused and is not doing the xquery => XML transition, so is parsing the ' in xquery mode.

Thus, the parsing modes should look like:

xml tag  : <foo>
xml text : a is '
xquery   : {$a}
xml text : ', b is '
xquery   : {$b}
xml text : '
xml tag  : </foo>
ligasgr commented 8 years ago

Ahh. I see your point now. Initially I missed the fact that you are inserting the closing quote in <caret>'s place. That's definitely a bug an I'll try to fix it.