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

Define IIdentifiedSingleEditOperation.range as IRange instead of Range #90950

Merged
merged 2 commits into from
Feb 19, 2020

Conversation

bolinfest
Copy link
Contributor

With the upcoming changes in TypeScript 3.8 to support import type, it is even more compelling to declare weak references via types rather than strong references via concrete classes. Most APIs in Monaco already do this well, accepting monaco.IRange instead of monaco.Range, though IIdentifiedSingleEditOperation appears to be an exception in this regard, which means a strong dependency on monaco.Range is required to use ITextModel.pushEditOperations().

It would be nice to relax this constraint, though I admit I have not yet attempted to trace through whether this breaks anything since I am submitting this via GitHub's web UI.

This PR fixes #

With the upcoming changes in TypeScript 3.8 to support `import type`, it is even more compelling to declare weak references via types rather than strong references via concrete classes. Most APIs in Monaco already do this well, accepting `monaco.IRange` instead of `monaco.Range`, though `IIdentifiedSingleEditOperation` appears to be an exception in this regard, which means a strong dependency on `monaco.Range` is required to use `ITextModel.pushEditOperations()`.

It would be nice to relax this constraint, though I admit I have not yet attempted to trace through whether this breaks anything since I am submitting this via GitHub's web UI.
@bolinfest
Copy link
Contributor Author

Indeed, the test failures illustrate where VS Code/Monaco expect a Range rather than an IRange. For example, snippetSession.ts has this line:

return undoEdits.map(edit => Selection.fromPositions(edit.range.getEndPosition()));

Would you be open to changes like Range having a static getEndIPosition() method so that edit.range could be an IRange? Presumably it could be implemented as follows if the existing getEndPosition() method were special in some way:

function getEndIPosition(range: IRange): IPosition {
  if (range instanceof Range) {
    return range.getEndPosition();
  } else {
    return {
      lineNumber: range. endLineNumber,
      column: range. endColumn,
    };
  }
}

I'm happy to go through and try to do these sorts of refactorings, but if you aren't open to this change, then feel free to close the PR.

@alexdima
Copy link
Member

Thank you!

@microsoft microsoft deleted a comment from msftclas Feb 19, 2020
@alexdima alexdima merged commit 9caab0b into microsoft:master Feb 19, 2020
@bolinfest
Copy link
Contributor Author

w00t!!! Thanks @alexdima for taking my proposal and making it legit!

/**
* The range to replace. This can be empty to emulate a simple insert.
*/
range: Range;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexdima Did you intend for this to be a Range rather than an IRange? Without tracing through the code, I assume it's extra work to relax this constraint right now?

Copy link
Member

Choose a reason for hiding this comment

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

That is intentional. You can see how IValidEditOperation is always returned from the editor or passed in as a callback argument by the editor, so this is not a constrained on the editor user, it is a constrained on the editor implementation.

@bolinfest
Copy link
Contributor Author

Also, @alexdima I'm not sure how much work it is on your end to publish a new monaco-editor release, but I would love to take advantage of this fix if it isn't too much work. Maybe I can try to land some other perf fixes to Monaco to make a new release more worth your while...

In the meantime, I'll guess I'll try following the instructions on https://github.com/microsoft/monaco-editor/blob/master/CONTRIBUTING.md to produce a local build.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants