-
Notifications
You must be signed in to change notification settings - Fork 35
Add the ability to manually format Javascript code (#87) #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to manually format Javascript code (#87) #90
Conversation
e2b172f to
132de74
Compare
132de74 to
1b367fd
Compare
tonygermano
left a comment
There was a problem hiding this 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:

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

pacmano1
left a comment
There was a problem hiding this 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)
|
@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. |
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. |
|
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. |
|
@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. |
|
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. |
|
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
left a comment
There was a problem hiding this 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.
client/src/com/mirth/connect/client/ui/components/rsta/actions/FormatCodeAction.java
Outdated
Show resolved
Hide resolved
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
98dde20
1b367fd to
98dde20
Compare
pacmano1
left a comment
There was a problem hiding this 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.
mgaffigan
left a comment
There was a problem hiding this 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

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.