-
-
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
--cursor-offset output is wrong sometimes #1981
Comments
Since the `cursorOffset` option (introduced in prettier#1637) works by tracking the cursor position relative to an AST node (rather than a CST token), it can produce incorrect results. See prettier#1981
This partially addresses prettier#1981 by ensuring that the cursor cannot jump outside of its node upon formatting. It could be improved upon by keeping track of the offset relative to the end of the node as well.
Partially addresses prettier#1981
Hmm, after working on #1983, I see that the issue with this particular test case is that |
Ohh, so the issue is that it's based on Statements and not every node. Interesting! |
This partially address prettier#1981 See prettier#1981 (comment)
Since the `cursorOffset` option (introduced in prettier#1637) works by tracking the cursor position relative to an AST node (rather than a CST token), it can produce incorrect results. See prettier#1981
* Add test demonstrating SourceElement-relative cursor translation See #1981 (comment) * Translate cursor relative to nearest node, not SourceElement This partially address #1981 See #1981 (comment) * Add test demonstrating incorrect cursor translation Since the `cursorOffset` option (introduced in #1637) works by tracking the cursor position relative to an AST node (rather than a CST token), it can produce incorrect results. See #1981
Is this fixed now? |
Not quite, there's still the bug mentioned here: #1989 (comment) |
other bug example: input: (where |
I've been looking into fixing cursorOffset tracking recently, and I intend to submit a PR that will make it at least a lot better than it is currently, if not perfect. Will document what I've learned so far here now. prettier currently decides where the cursor should end up using the following method:
This approach has two problems right now
|
Again, publicly keeping track of my own progress on this, in case I get distracted and it helps someone else one day: A potential approach to solving the first issue mentioned above is as follows:
I've tried this out. It seems to work very nicely. Need to do more extensive testing though. |
I just wanted to note that since the
cursorOffset
option (introduced in #1637) works by tracking the cursor position relative to an AST node (rather than a CST token), it can produce incorrect results. For example:(related to prettier/prettier-vscode#12 (comment))
The text was updated successfully, but these errors were encountered: