Skip to content

Conversation

@sbraconnier
Copy link
Contributor

Default format shortcut is Ctrl+Shift+F (like Eclipse). I hesitated between Eclipse (Ctrl+Shift+F), Intellij (Ctrl+Alt+L) and Postman (Ctrl+B).

Note that I also add the menu item "toggle comment" option to the new contextual "code" menu.

tonygermano
tonygermano previously approved these changes Aug 30, 2025
Copy link
Member

@tonygermano tonygermano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes all look good to me. I split the original commit into two because while adding the ability to toggle comments via the context menu makes sense, it is not related to the other change of being able to format the code. I also expanded the commit messages to better describe the changes.

As an example of what the code formatting can do, here is a before:
image

And after:
image

The context menu changes after both commits appears as the following:
image

@tonygermano tonygermano requested review from a team, gibson9583, jonbartels, kayyagari, kpalang and pacmano1 and removed request for a team August 30, 2025 16:45
Copy link
Contributor

@pacmano1 pacmano1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of QA on the compiled running behavior:

  • Appears to format e4x code
  • Appears to not break things like XML literals (e.g. it might indent a var x = <someliteral/> but it will not indent the subsequent line (which it should not) should the XML blob continue
  • Note sure the right click toggle comment is needed, but not a breaker.

One issue - it should probably not format bad code (i.e. the editor window should be clean prior to format)

gibson9583
gibson9583 previously approved these changes Aug 30, 2025
@gibson9583
Copy link
Contributor

@pacmano1 - noted same issue on malformed JS. Only option around this would be to call validation first, but I don't think it's a deal breaker after kicking around with SC. Some beautifiers will and some won't format "bad" code.

@tonygermano
Copy link
Member

In the context of QA on the compiled running behavior:

  • Appears to format e4x code
  • Appears to not break things like XML literals (e.g. it might indent a var x = <someliteral/> but it will not indent the subsequent line (which it should not) should the XML blob continue
  • Note sure the right click toggle comment is needed, but not a breaker.

One issue - it should probably not format bad code (i.e. the editor window should be clean prior to format)

I think the right-click toggle comment is nice to have for users who forget the hotkey combination or didn't even know the option existed.

I disagree about it not formatting bad code. If I copy code that is a mess and ask it to format, I expect it to do its best. I don't need it complaining to me that the code is not perfect, because I might be asking it to format so that I can more easily find mismatched or misplaced parentheses or braces.

@pacmano1
Copy link
Contributor

pacmano1 commented Aug 30, 2025

well, I'm sure it's predictable in an algorithmic sense, it just feels unpredictable from a UI perspective. I'd probably warn and allow forever dismiss.

If everyone else is OK with this behavior, I can agree to disagree.

@tonygermano
Copy link
Member

@pacmano1 The engine still won't let you save the channel with code that doesn't validate.

I just typed this mess into vscode

var     a           =1
   var  b=    2;

   for(  vara i of [1,2,3])) {
    const c=4
   }

   function d() {
    while (true)
        false;}
   }

And it formatted it to this without complaining, even though there are several syntax errors.

var a = 1
var b = 2;

for (vara i of[1, 2, 3])) {
    const c = 4
}

function d() {
    while (true)
        false;
}
   }

I don't think it's the job of the formatter to warn you about invalid code. It just does its best to tidy up. There are other mechanisms that already exist to tell you that your code has errors, and formatted code can make it easier to see where you made a mistake.

@pacmano1
Copy link
Contributor

I came across this same issue with the content formatter. A different PR. For example, both built in prettyPrints will format the "wrong" data type.

So if I'm understanding you correctly, your position is the developer should know better.

@tonygermano
Copy link
Member

I'm not sure what you mean by the developer should know better. I think the formatter should do what it is asked to do, and there is no implication that because it improves the readability of the code that the code is syntactically correct.

The program will still alert the user if there is a syntax error whether the format feature is used or not. If you want to test if the code has syntax errors, there is already a validate button for that.

@pacmano1 pacmano1 self-requested a review September 2, 2025 15:49
Copy link
Contributor

@pacmano1 pacmano1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said my peace here, approving. I will remind you all of this in the future with the map variable formatter that does have a similar "problem". Cool feature though @sbraconnier.

@kpalang kpalang requested a review from pacmano1 September 2, 2025 18:31
pacmano1
pacmano1 previously approved these changes Sep 2, 2025
@tonygermano tonygermano linked an issue Sep 2, 2025 that may be closed by this pull request
This change allows the user to format code within the code editor areas.
The user can format the currently selected lines or the entire document.
A default hotkey of ctrl+shift+F has been added to run this action, but
it may be changed by the user. Additionally, this action can be
performed in the right-click context menu by selecting "Code->Format"

Signed-off-by: Tony Germano <tony@germano.name>
Original-sign-off: OpenIntegrationEngine@132de74
Issue: OpenIntegrationEngine#87
This lets the user perform the action to toggle comments on or off for
the current line or the current selection in the code editor by
selecting "Code->Toggle Comment" from the right-click context menu.
Previously this action could only be performed by hotkey (ctrl+/ by
default.)

Signed-off-by: Tony Germano <tony@germano.name>
Original-sign-off: OpenIntegrationEngine@132de74
Issue: OpenIntegrationEngine#87
@tonygermano tonygermano dismissed stale reviews from pacmano1, gibson9583, and themself via 98dde20 September 2, 2025 23:50
@pacmano1 pacmano1 self-requested a review September 3, 2025 17:43
Copy link
Contributor

@pacmano1 pacmano1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving - previous comments noted.

Copy link
Contributor

@mgaffigan mgaffigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes:

  • Formatting fails pretty hard with var x = <{a} {a}={a} />;
  • The user caret is moved to the start of the formatted selection (rather than wherever it was prior to formatting)
  • The editor in general has some odd behavior with characters outside of the BMP

I don't think any of those are cause for correction. LGTM

@kpalang kpalang self-requested a review September 4, 2025 09:45
@kpalang kpalang merged commit 98dde20 into OpenIntegrationEngine:main Sep 4, 2025
2 checks passed
@sbraconnier sbraconnier deleted the feature/js-beautify branch September 8, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[IDEA] Add the ability to format javascript code

6 participants