sublimelsp / LSP-ruff

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

Linting to only trigger on demand and/or while saving? #67

Closed jklaiho closed 3 weeks ago

jklaiho commented 4 months ago

I would love the ability to only trigger linting when I hit a specific key combo, instead of automatically while I'm typing. The linting errors and warnings that pop up while typing code that will eventually be valid are annoying and distracting, IMHO. I ended up ignoring W293 to stop the worst offender: Ruff nagging me about whitespace on an empty line when I press Enter and get auto-indentation.

In addition, an option to lint automatically when saving would be really nice. Ruff seems to have a VS Code specific setting called lint.run, which you can set to onSave instead of onType. Would something like this be possible to implement for LSP-ruff?

I've looked through a bunch of docs and haven't found an option for either of these; sorry if I've missed something.

rchl commented 4 months ago

That's more of a request for the core LSP package and there already is a request like that: https://github.com/sublimelsp/LSP/issues/2161

jklaiho commented 4 months ago

OK, fair enough; I'm new at this LSP business and don't really know what type of issues belong where. I guess this can be closed.

I had another request in mind: being able to sort imports with a hotkey. Should that go here or the core LSP?

Some context to maybe save me from creating the issue altogether, my apologies that it's unrelated to this one: the README lists source.organizeImports and source.organizeImports.ruffas possible "code actions on save"—if it's already possible to bind these to key combos, I don't know how. This attempt didn't work:

    {
        "keys": ["super+ctrl+i"],
        "command": "lsp_code_actions",
        "context": [{"key": "lsp.session_with_capability", "operand": "source.organizeImports"}]
    },
rchl commented 3 weeks ago

Since we have issue in LSP, this one is redundant.

The keybinding you are looking for would look something like:

    {
        "keys": ["super+ctrl+i"],
        "command": "lsp_code_actions",
        "args": {"only_kinds": ["source"]},
        "context": [{"key": "lsp.session_with_capability", "operand": "codeActionProvider.codeActionKinds"}]
    },

You can find that example in the default LSP keybindings (commented out).

EDIT: Although invoking specific code action is currently not possible - https://github.com/sublimelsp/LSP/issues/1356