sublimelsp / LSP-ruff

LSP helper for ruff - an extremely fast Python linter, written in Rust.
https://packagecontrol.io/packages/LSP-ruff
MIT License
26 stars 4 forks source link

Adding the option to format the selection in addition to format file #56

Closed seperman closed 3 months ago

seperman commented 4 months ago

Hello, Is it possible to add the option to format the selection? Currently, we can only format the whole file. Thanks

jfcherng commented 3 months ago

looks good to me? image

seperman commented 3 months ago

My menu looks very different than yours. How come? image

jfcherng commented 3 months ago

Are you still using ST 3?

seperman commented 3 months ago

I'm on Sublime build 4169. So I assume it is ST 4?

jfcherng commented 3 months ago

Looks good. I just tried a clean portable ST but it still works on my side. So I have no idea what's happening here.

I do see a payload sent to the server and it works...

:: [02:46:07.137] --> LSP-ruff textDocument/rangeFormatting (5): {'textDocument': {'uri': 'file:///xxx.py'}, 'options': {'insertSpaces': True, 'insertFinalNewline': True, 'tabSize': 4, 'trimFinalNewlines': True, 'trimTrailingWhitespace': True}, 'range': {'end': {'character': 0, 'line': 1}, 'start': {'character': 0, 'line': 0}}, 'workDoneToken': '$ublime-work-done-progress-5'}

seperman commented 3 months ago

I uninstalled and re-installed lsp and lsp-ruff. Also changed the interpreter path to another virtualenv. My menu doesn't look like yours but at least I have the "format selection" option now.

image image

Also, I am on Ubuntu if that matters. I tried to avoid installing the debian package for virtualenv but gave up. All I wanted to do was to point lsp to the ruff-lsp package in a virtualenv, instead of having lsp-ruff create its own virtualenv in the ~/.cache folder.

rchl commented 3 months ago

The version of ruff that you were using likely didn't support it yet. That's why it's safest to use the bundled version.

(@jfcherng was showing you the right-click menu. That's why it's different from yours.)

seperman commented 3 months ago

Ok thanks. I'm happy the selection format works now.