Skip to content
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

Merged
merged 1 commit into from
Feb 28, 2019
Merged

Monaco Adapter: Rewrite from scratch in ES6+ #325

merged 1 commit into from
Feb 28, 2019

Conversation

0xTheProDev
Copy link
Contributor

@0xTheProDev 0xTheProDev commented Jan 14, 2019

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

@0xTheProDev
Copy link
Contributor Author

URGENT
@mikelehen Can you please review this?

@samtstern
Copy link
Contributor

@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.

@0xTheProDev
Copy link
Contributor Author

0xTheProDev commented Jan 17, 2019

@samtstern 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. So to fix existing issues and specialising Adapter for Monaco, the rewrite has been done.

ES6+ standard is just a design choice that I made as it is latest standard. I have also added build tasks in grunt to facilitate ES5 support for old browsers and tests as well.

@mikelehen
Copy link
Collaborator

@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 )?

@0xTheProDev
Copy link
Contributor Author

@mikelehen @samtstern Why don't you guys perform build and launch monaco.html from example to see the improvements?

@samtstern
Copy link
Contributor

@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:
#1 - fix the two bugs you're targeting
#2 - convert code to ES6

Separating those would make it much easier to have a high level of confidence.

@Cnidarias
Copy link
Contributor

I can have a look at what was done coming this weekend, but I am no expert on the subject as well.

@zach-karat
Copy link
Contributor

I support merging this PR in some form (or splitting it into two).

I have been testing monaco-adapter in my own project and encountered a few bugs that make it almost unusable in a few key situations (such as tabbing multiple lines and commenting out multiple lines). I have been testing locally and this change fixes all the bugs I am aware of in the adapter.

@samtstern
Copy link
Contributor

@zach-karat thanks for your PR (#327). Are there more bug fixes contained in this PR that were not present there?

@zach-karat
Copy link
Contributor

@samtstern Not that I know of, but I did not review every file. @Progyan1997 ?

@0xTheProDev 0xTheProDev reopened this Feb 14, 2019
@0xTheProDev
Copy link
Contributor Author

0xTheProDev commented Feb 14, 2019

@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.

@samtstern samtstern self-assigned this Feb 15, 2019
@samtstern
Copy link
Contributor

@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.

Copy link
Contributor

@samtstern samtstern left a 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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly.

lib/monaco-adapter.js Outdated Show resolved Hide resolved
}
this.grabDocumentState();
Copy link
Contributor

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?

Copy link
Contributor Author

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>
@samtstern
Copy link
Contributor

@zach-karat have you tried this change since #327 was merged?

@zach-karat
Copy link
Contributor

@samtstern I haven't had a chance to test the latest version yet, but I can try to find time to merge and test.

@samtstern
Copy link
Contributor

@zach-karat no worries I don't want to put extra burden on you was just curious if you'd already tried it, thanks!

@samtstern
Copy link
Contributor

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 samtstern merged commit e39b4c1 into FirebaseExtended:master Feb 28, 2019
samtstern added a commit that referenced this pull request Feb 28, 2019
@0xTheProDev 0xTheProDev deleted the develop branch February 28, 2019 21:21
@0xTheProDev
Copy link
Contributor Author

@samtstern Hey just wanted to know when the next release is going to be published?

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.

None yet

6 participants