Skip to content
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

[Feature request] Allow disabling --cursor-offset through user option #168

Closed
Prinzhorn opened this issue Mar 26, 2019 · 9 comments
Closed

Comments

@Prinzhorn
Copy link

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
@jonlabelle
Copy link
Owner

Yea... I often experience the same problem. I'll work this in.

@wlchn
Copy link

wlchn commented Apr 3, 2019

I often experience the same problem too. Sublime freezes frequently when I format scss or tsx files, spiking CPU to 200%.

@wlchn
Copy link

wlchn commented Apr 3, 2019

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 the JsPrettier folder and open JsPrettier.py.

  • Second, Find provide_cursor=True and change it to provide_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.

@Prinzhorn
Copy link
Author

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.

@jonlabelle
Copy link
Owner

@Prinzhorn: I thought about the heuristic approach...and did some trial and error... but never could pin-point a reasonable location.

@jonlabelle
Copy link
Owner

Give it a whirl.

@Prinzhorn
Copy link
Author

Nice, works as advertised. Just pasted a big minified js file and saving/formatting only took like 2s. Thanks!

@Prinzhorn
Copy link
Author

@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.

@lock
Copy link

lock bot commented Aug 1, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants