Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for synchronising edits between two nb editors of the same file #10189

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

Merged
merged 11 commits into from
Mar 10, 2020

Conversation

DonJayamanne
Copy link

@DonJayamanne DonJayamanne commented Feb 19, 2020

For #9879
Notes:

  • Renamed userAction to other, as its misleading (was to me, cuz if its a user action they why isn't it synchronized).
  • Will add tests in a separate PR, want this out of the way (as I believe that will require a bit more work)
  • Apart from the syncing, looks like we have other issues (open an nb , make some changes and save the file, open the same file again on the side, and the changes are not in the new duplicate editor) - that's not part of the scope of synchronizing edits (not part of the initial work I was planning on working on, but will work on that next - should be some simple bug fix. Once thats done the tests will be added).
  • Also found that (without
  • I'm testing and I'll add a few more PRs to sync a few actions (will just update an enum to sync other actions, e.g. running a cell should update the same cell on the other editor required one line change).
  • Oh yes, edits are not synced, as I'm waiting for another PR that will ensure model is updated for each edit (simpler)

@DonJayamanne DonJayamanne added the no-changelog No news entry required label Feb 19, 2020
@@ -9,7 +9,7 @@ export enum MessageType {
/**
* Action dispatched as result of some user action.
*/
userAction = 0,
other = 0,
Copy link

Choose a reason for hiding this comment

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

This seems okay, but I wonder if we even need to sync all of this stuff. I believe the model edits sync'd to all views should just work. That seems simpler to me.

Copy link
Author

Choose a reason for hiding this comment

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

Ahh yes, agreed, but we'd need to know where cell edits come from (i.e. from which editor and ensure those are propagated to the other views).
I'll check that out.

Copy link
Author

Choose a reason for hiding this comment

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

but I wonder if we even need to sync all of this stuff

  • This is stuff like cell selection, focus (for live share)
  • We control what actions can be synchronized (cell progress states, error states, etc).
    • If the model state captures all of this then yes that will work as well. I'll look into that right now.

Copy link

Choose a reason for hiding this comment

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

Yeah I think that should be pretty easy. Add like an origin or something to the NotebookModelChange class. And then check that in the code in the nativeEditor that skips when from 'user'. Only skip if from 'user' and 'origin' is self.

Copy link

Choose a reason for hiding this comment

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

I don't think we need to sync selection or focus. That's weird. Would you want your other editor (or your editor if on liveshare) to change focus/selection?

Copy link

Choose a reason for hiding this comment

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

But otherwise each view should represent the model.

Copy link

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

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

:shipit:

@DonJayamanne
Copy link
Author

@rchiodo
With the current solution

  • Kernel updates are synchronized using this approach
  • Progress indicators for cells are synchronized using this approach
  • Allows syncing other stuff for live share (cell selection, focus, Opening variables view (live share), scrolling to a cell)
  • I've found that undo/redo works as expected as well.
  • Basically we have a fine grained control over what is synchrnonized & what isn't (its a simple dictionary)

That being said, I'm not saying this is a full proof solution, however using the model alone doesn't give us all the synchronization we need (cell state for execution, & the like)
That would require some more changes to the model, and we'd probably need to include other parts into the model. Also, we'd need to ensure the model keeps track of the editor that made the changes.

I.e. i think using the latter solution would require some more changes and wouldn't cover all scenarios.
However, I'll keep exploring that approach (still working on that).

@@ -99,8 +100,8 @@ export function reBroadcastMessageIfRequired(
// tslint:disable-next-line: no-any
const syncPayloadData: BaseReduxActionPayload<any> = { data: payload?.data, messageType: result[1], messageDirection: 'incoming' };
// tslint:disable-next-line: no-any
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you can ditch the no-any now.

@codecov-io
Copy link

codecov-io commented Feb 19, 2020

Codecov Report

Merging #10189 into ds/custom_editor will increase coverage by 0.02%.
The diff coverage is 21.73%.

Impacted file tree graph

@@                 Coverage Diff                  @@
##           ds/custom_editor   #10189      +/-   ##
====================================================
+ Coverage             60.80%   60.83%   +0.02%     
====================================================
  Files                   579      580       +1     
  Lines                 31301    31336      +35     
  Branches               4454     4461       +7     
====================================================
+ Hits                  19032    19062      +30     
- Misses                11308    11312       +4     
- Partials                961      962       +1     
Impacted Files Coverage Δ
...ient/datascience/interactive-ipynb/nativeEditor.ts 11.56% <20.00%> (+0.16%) ⬆️
...ence/interactive-ipynb/nativeEditorSynchronizer.ts 22.22% <22.22%> (ø)
src/client/common/utils/platform.ts 64.70% <0.00%> (-11.77%) ⬇️
src/client/linters/pydocstyle.ts 86.66% <0.00%> (-2.23%) ⬇️
src/client/datascience/debugLocationTracker.ts 76.56% <0.00%> (-1.57%) ⬇️
src/client/common/process/proc.ts 14.49% <0.00%> (-0.73%) ⬇️
...t/common/insidersBuild/insidersExtensionService.ts 100.00% <0.00%> (ø)
...ascience/interactive-ipynb/nativeEditorProvider.ts 56.41% <0.00%> (+9.61%) ⬆️
src/datascience-ui/react-common/arePathsSame.ts 75.00% <0.00%> (+37.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88dd250...ad544d6. Read the comment docs.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@DonJayamanne DonJayamanne merged commit d8de159 into microsoft:ds/custom_editor Mar 10, 2020
@DonJayamanne DonJayamanne deleted the syncingUIActions branch March 10, 2020 23:20
DonJayamanne added a commit that referenced this pull request Mar 17, 2020
* master:
  Fix merge issue
  Move redux logging to a different file (#10605)
  Disable custom editor API (#10604)
  Ensure local host only if connection not available (#10600)
  Delegate management of notebooks (creation and disposing) to I… (#10568)
  Refactor to accommodate upstream VSCode API changes (#10569)
  Use a single notebook beetween multiple native editors (#10514)
  Add support for synchronising edits between two nb editors of… (#10189)
  Fix tests in ds/custom_editor branch (#10512)
  Fix linter
  Reimplement custom editor using new API
@lock lock bot locked as resolved and limited conversation to collaborators Mar 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
no-changelog No news entry required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants