-
-
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
Wrong cursorOffset with multi-line comment #14811
Comments
Please use the issue template. Prettier Playground supports ranges if this is what you are trying to show: |
@kachkaev Ok, I've updated the format. The playground does not help here since it cannot set the cursor position. |
Your right about this, this is strange. I can't change the code either. My script to testimport * as mainPrettier from "./index.js";
import stablePrettier from "./node_modules/prettier/index.js";
const code = `
// All messages are represented in JSON.
// So, the prettierd.py controls a subprocess which spawns "node {this_file}".
import {<|> } from "fs"
`;
const cursorOffset = code.indexOf("<|>");
const codeToFormat = code.replace("<|>", "");
console.table([
{
prettier: mainPrettier.version,
originalCursorOffset: cursorOffset,
cursorOffset: (
await mainPrettier.formatWithCursor(codeToFormat, {
cursorOffset,
parser: "babel",
})
).cursorOffset,
},
{
prettier: stablePrettier.version,
originalCursorOffset: cursorOffset,
cursorOffset: (
await stablePrettier.formatWithCursor(codeToFormat, {
cursorOffset,
parser: "babel",
})
).cursorOffset,
},
]); |
Smaller reproduction
Change the first |
import { diffArrays } from "diff";
const code = `
// All m are represented in JSON.
// So, the prettierd.py controls a subprocess which spawns "node {this_file}".
import {} from "fs";
`.trim();
function diff(string) {
return diffArrays([...'import { } from "fs";'], [...string]);
}
console.log([diff(code), diff(code.replace("m", "a"))]); The results are so different, maybe bug in diff?
|
Raised an issue kpdecker/jsdiff#400 |
Shortest string I can find import { diffArrays } from "diff";
const code = `
// m represent o, 1 represent 1 1 {}
import {} from "fs";
`.trim();
function diff(string) {
return diffArrays([...'import { } from "fs";'], [...string]);
}
console.log([
diff(code),
diff(code.replace("o", "a")),
diff(code.replace("m", "a")),
]); |
jsdiff is almost... dead? I think the project has been abandoned by its author and this bug may not be fixed in a while. Just curious. Never mind. |
I know that. My PR has been there for over a year kpdecker/jsdiff#351 Anyway, #14812 will fix your issue, so not that important. |
Environments:
Steps to reproduce:
Save this script and run it:
Expected behavior:
Expect the returned
cursorOffset
to be around 129, right in the{}
.Actual behavior:
It returns 65, which is in the comments.
Frankly, I don't even find a minimal case to reproduce this issue (the code above is all I could make, changing any line of the comment may make the result correct).
The text was updated successfully, but these errors were encountered: