prettier icon indicating copy to clipboard operation
prettier copied to clipboard

[prettier-plugin-sql] does not return cursor Position

Open stonerl opened this issue 7 months ago • 5 comments

I added prettier-plugin-sql to my Prettier extension for Nova. I also use Prettiers formatWithCursor to retrieve the correct cursor Position after formatting.

prettier-plugin-sql seems to always return 0 as position, so the cursor always jumps to the beginning of the document.

stonerl avatar Apr 30 '25 21:04 stonerl

Please provide a online runnable reproduction. I'm not familiar with the formatWithCurson API.

JounQin avatar Apr 30 '25 23:04 JounQin

Dumb, question, but what would be an online runnable reproduction? I can only point you to the API doc.

https://prettier.io/docs/api/#prettierformatwithcursorsource--options

I'm just handing the cursor position to Prettier it and retrieve the new cursor position after formatting. That works for all languages supported by Prettier and all other plugins I use. e.g @prettier/plugin-xml and @prettier/plugin-php. So, not sure what I can do here?

stonerl avatar May 20 '25 12:05 stonerl

I didn't find what the plugin author need to do with formatWithCursor API or even cursor keyword: https://prettier.io/docs/plugins#developing-plugins

Maybe we can do better here?

https://github.com/un-ts/prettier/blob/2b277b89f9d1bb96ba20364cc60480828eabc0e3/packages/sql/src/index.ts#L46-L47

cc @fisker

JounQin avatar May 20 '25 13:05 JounQin

Here is how the cursor node is located https://github.com/prettier/prettier/blob/c2ad588ec38f204427cad076fa58d608a3e9e02d/src/main/get-cursor-node.js#L20, Prettier will insert two prettier.doc.builders.cursor around that node when printing node.

fisker avatar May 20 '25 13:05 fisker

As a side note, the TOML plugin has the same issue.

stonerl avatar May 20 '25 17:05 stonerl