[Feature request] Allow disabling `--cursor-offset` through user option
Prinzhorn opened this issue · 9 comments
Explain the Issue and Expected Behavior
#147 says the freezing is not an issue with Sublime or SublimeJsPrettier. I agree but I'd love to be able to disable --cursor-offset
in user settings. Adding the following to the settings
"additional_cli_args": {
"--cursor-offset": -1
}
results in the following command
... --loglevel debug --cursor-offset -1 --cursor-offset 509
so I'm not able to disable it at all.
I'm working with markdown a lot and even the tiniest bit of unformatted JSON code blocks will cause the prettier process to freeze for minutes due to --cursor-offset
(I confirmed that on the CLI).
Prettier version
To show the currently installed prettier version, run the following command:
$ prettier --version
1.16.4
JsPrettier Plug-in Version
The JsPrettier Sublime Text Plug-in version is located in the package.json
file.
...
"name": "sublime-js-prettier",
"version": "1.26.3",
...
Platform Details
Provide your Sublime Text version and Platform details.
Example
- Sublime Text Version: 3.2
- Sublime Text Build: 3200
- Sublime Text Architecture: 64-bit
- Operating System Name: Ubuntu
- Operating System Version: 18.04.2
- Operating System Architecture: 64-bit
Yea... I often experience the same problem. I'll work this in.
I often experience the same problem too. Sublime freezes frequently when I format scss
or tsx
files, spiking CPU to 200%.
I found a hacked way to disable --cursor-offset
for people who in trouble a slow format performance like me.
-
First, Open the package folder
Sublime Text
-->Preferences
-->Browse Packages...
, Find theJsPrettier
folder and openJsPrettier.py
. -
Second, Find
provide_cursor=True
and change it toprovide_cursor=False
-
Finally, If you get an error like this in sublime console:
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 1082, in run_
return self.run(edit, **args)
File "/Users/wanglei/Library/Application Support/Sublime Text 3/Packages/JsPrettier/JsPrettier.py", line 295, in run
transformed, new_cursor = result
ValueError: too many values to unpack (expected 2)
Find a line return stdout.decode('utf-8')
in format_code
function. Change this line to return stdout.decode('utf-8'), None
will work fine.
Yea... I often experience the same problem. I'll work this in.
I would very much appreciate that. I was just thinking if there could be a third option besides on
and off
, e.g. auto
. I'm wondering if there could be a heuristic that determines whether to enabled cursor or not. E.g. if there is at least one line with more than say 200 characters. I'm mostly experiencing the freezing when pasting minified js/json (inside a markdown block or stand-alone) and want it formatted (in which case the cursor option is definitely not needed at all). But maybe that's too fancy and we just hope prettier will figure the performance out and we can get rid of the option again.
@Prinzhorn: I thought about the heuristic approach...and did some trial and error... but never could pin-point a reasonable location.
Give it a whirl.
Nice, works as advertised. Just pasted a big minified js file and saving/formatting only took like 2s. Thanks!
@jonlabelle would it be possible for the cursor to stay at the position it was before formatting? Right now the cursor is gone after formatting. Maybe it can be reset to where it was. Right now I need to click into the file in order to get a cursor back, so the option made regular programming kind of a pain instead of just having a slightly misaligned cursor from time to time.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.