-
Notifications
You must be signed in to change notification settings - Fork 877
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
Monaco Adapter: Rewrite from scratch in ES6+ #325
Conversation
URGENT |
@Progyan1997 thanks for the contribution! This is a very large change and it will be tough to review. I see your last message marked this URGENT, can you explain? In general can you explain the benefit to Firepad developers of converting the Monaco adapter to ES6? Apologies if this seems obvious, I have not been involved with Firepad for long so it's not clear to me. |
@samtstern There were couple of bugs regarding changing ES6+ standard is just a design choice that I made as it is latest standard. I have also added build tasks in |
@Progyan1997 Thanks for the PR! As Sam said, this is fairly large, and I'm not very familiar with monaco in the first place, so it's difficult for me to review this and ensure it'll be an improvement for people using the monaco support. I wonder if any of the folks who have worked on the monaco support in the past would be interested in taking a look and/or trying it out (e.g. @pranjaltale16, @Cnidarias, @ddunkin, @oliverlin, or @jbchavez19 )? |
@mikelehen @samtstern Why don't you guys perform build and launch |
@Progyan1997 the problem is that it's very hard to just click-test a complete re-write of code like this, the possibility of missing bugs is too high if we're not comfortable with our review. Another option would be to split this into two PRs: Separating those would make it much easier to have a high level of confidence. |
I can have a look at what was done coming this weekend, but I am no expert on the subject as well. |
I support merging this PR in some form (or splitting it into two). I have been testing |
@zach-karat thanks for your PR (#327). Are there more bug fixes contained in this PR that were not present there? |
@samtstern Not that I know of, but I did not review every file. @Progyan1997 ? |
@samtstern @mikelehen @zach-karat I created an updated PR following current ES5 syntax, so that ES6 rewrite overhead can be avoided in review process. Thanks. Additional Fixes: Proper undo-redo, multiline commenting/uncommenting, sharing selection and cursor. |
@Progyan1997 thank you for taking the time to simplify! I will review this when I get a chance (since I am not a firepad expert it will take me longer than it should) and hopefully we will get it merged. |
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 mostly have some minor concerns (in comments). How confident are you that the tests / your own testing ensure this change is correct?
I really like the increased code readability of the new code but I am having trouble keeping enough in my head (without knowing anything about Monaco) to say that I can guarantee the same behavior just by reading the code.
|
||
/** Add style rules only once */ | ||
if (this.addedStyleRules.indexOf(clazz) === -1) { |
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 old implementation this was an object {}
which made it easier to check for membership, why move to an array and indexOf
?
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.
Because I rewrote in ES6 at first, and using []
is not regarded as best practice. I will vouch we keep it like this, so that most of the responsibility moves toward language and library than the coder.
start = this.monacoModel.getOffsetAt(selection.getStartPosition()); | ||
end = this.monacoModel.getOffsetAt(selection.getEndPosition()); | ||
} catch (_error) { | ||
e2 = _error; |
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.
What happened to this error case?
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 didn't find any situation where statements above will throw any error.
* @param {function[]} callbacks - Set of callback functions | ||
*/ | ||
MonacoAdapter.prototype.registerCallbacks = function registerCallbacks(callbacks) { | ||
this.callbacks = Object.assign({}, this.callbacks, callbacks); |
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.
Can you explain why the move to Object.assign
from straight assignment?
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.
So that if new param doesn't have action for some event, we can use the existing ones.
offsetLength = offsetLength + (pair[0].targetLength - pair[0].baseLength); | ||
this.trigger.apply(this, ['change'].concat(__slice.call(pair))); | ||
}.bind(this)) | ||
return this.grabDocumentState(); |
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.
So was this return value unused before?
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.
Exactly.
} | ||
this.grabDocumentState(); |
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.
Do we want to call this at the end of applyOperation
?
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.
No, related state transition has already been taken care of
**This is a modified commit of earlier PR** Created only those APIs that are been called either by Firepad or EditorClient. Main fix is for syncing between multiple pads and cursors. Removed depenencies and function prototypes created while transpiling from Coffescript code for Ace. Rewritten specific to Monaco Editor and it's API standards. Capable of handling multi-line operations and flexible with undo-redo. Add Testcases to verify changes from Monaco editor onChange event handler to OT.js Text Operations. Reduced scope for internal methods, so that they are inaccessible from outside world. There were couple of bugs regarding changing `onChange` event in Monaco to `OT.js` Text Operations, and in syncing of cursor position and selection between pads. These bugs sometimes were hard to reproduce and fix. Also existing codebase was a conversion of `Ace-Adapter` with couple of changes for Monaco and had residues of converted `coffee` code which was not required. Ref: #324 (Transpiled down to ES5) Closes: #313 Signed-off-by: Progyan Bhattacharya <Progyan@hackerrank.com>
@zach-karat have you tried this change since #327 was merged? |
@samtstern I haven't had a chance to test the latest version yet, but I can try to find time to merge and test. |
@zach-karat no worries I don't want to put extra burden on you was just curious if you'd already tried it, thanks! |
Ok I have taken a few more looks at this and while I am still a little uncomfortable with my lack of understanding, I think it's a shame to let such a well thought out contribution to a community-managed project go unmerged. So we can merge this, cut a release, and fix new issues as they come up. |
@samtstern Hey just wanted to know when the next release is going to be published? |
Created only those APIs that are been called either by
Firepad or EditorClient.
Syncing between editors and cursors.
Updated package-lock, found 7 vulnerability with breaking
change update
Removed depenencies and function prototypes created while
transpiling from Coffescript code for Ace. Rewritten specific to
Monaco Editor and it's API standards.
Add Build task to convert ES6+ codes into ES5 using Babel.
Add Testcases to verify changes from Monaco editor onChange
event handler to OT.js Text Operations.
Ref: #324
Closes: #313
Signed-off-by: Progyan Bhattacharya Progyan@hackerrank.com