eXist-db / eXide

A web-based XQuery IDE for eXist-db
GNU General Public License v3.0
45 stars 32 forks source link

[BUG] Formatting operation removes spaces around operator, making code invalid #679

Open galtm opened 7 months ago

galtm commented 7 months ago

Describe the bug When I use XQuery > Format code on a certain function, some spaces get removed such that the code is no longer valid. The problem might be related to a code comment near the code that becomes invalid.

Expected behavior The code should be formatted differently but should still produce the same behavior.

To Reproduce

  1. Enter this code in eXide:
    
    xquery version "3.1";

declare function local:myfcn( $arg as xs:integer ) as xs:string* {

(: Multiple-line comment that is not in eXist-db style :) if ($arg gt 0) then 'positive' else 'nonpositive' };

local:myfcn(1)


2. Select all the text (or only the function declaration)
3. Select **XQuery > Format code**

The function declaration now looks like this, with no spaces around the `gt` operator:
```xquery
declare function local:myfcn($arg as xs:integer)
as xs:string*
{
    (:
     : Multiple-line comment that is
     : not in eXist-db style
     :)if($arggt0)then'positive'else'nonpositive'};

Screenshot image

Context (please always complete the following information):

Additional context

joewiz commented 7 months ago

@galtm Thank you for the report! This sounds like a bug indeed. It is likely in the upstream project that @wolfgangmm drew on when he contributed the feature. That project, xqlint, has since changed its architecture in a way that makes it incompatible with eXide. Thus, I am not hopeful that a fix will be easy. (I, at least, lack the javascript skills that would be necessary to investigate the bug.) If we confirm the problem is irreparable, the solution may be to remove the feature, lest it cause damage to people's code.

galtm commented 7 months ago

@joewiz, Thanks for looking at this so quickly and for setting my expectations about the feasibility of a fix.