-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Reduce how much text needs to be diffed when computing cursor positions #15709
base: main
Are you sure you want to change the base?
Conversation
…sor positioning changes
Conflicts: tests/format/js/cursor/__snapshots__/jsfmt.spec.js.snap tests/format/js/cursor/cursor-11.js
…bility breakage for existing third-party plugins
c43902c
to
34df586
Compare
…-diffs Conflicts: src/document/builders.js src/document/printer.js src/document/public.js src/main/core.js src/utils/ast-utils.js
@fisker just in case you're not aware, note this is ready for review and has been for a while. |
Is this the reason why you add |
Ooh, sorry, missed the comment above somehow. Yeah, I think the new |
I'm not sure it worth to make the change ( a) plugins maybe already using |
Fair enough; I've removed the new |
Description
This implements roughly the tactic I proposed at #4801 (comment).
It's a draft for now. I have a bunch of outstanding concerns I want to dig into before it's ready for review (in addition to the stuff in the PR template checklist), many of which probably require tweaks to the logic here:
opts.cursorNode
to address this.opts.cursorNode
, but perhaps that's something that third party plugins might use or modify, in which case I've broken them?--help
text specifically says that those two features can't be used together. (I also have no idea why my changes broke that scenario in particular.) I guess I should investigate...printAstToDoc
to insert thecursor
symbol at beginning or end of the doc in the scenario where the cursor is located before the first AST node. But what happens when there are embedded docs, or whenprintAstToDoc
gets called from the multiparser (are these the same scenario?)? Since I didn't consider these scenarios at all when writing the code, I presume the behaviour of my code in them is currently broken.printDocToString
(e.g. because the other is part of a group that doesn't get printed at all for some reason)? If this happens it will causeprintDocToString
to throw, so I need to either ensure it's impossible or modifyprintDocToString
to handle it when it happens.nodeBeforeCursor
ends up afternodeAfterCursor
in the formatted doc, e.g. because some sort of sorting plugin for Prettier was used like https://github.com/trivago/prettier-plugin-sort-imports? This obviously breaks the intended logic for computing the cursor position, and right now I don't detect it or recover from it.Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨