Giter Site home page Giter Site logo

yaegassy / coc-ruff Goto Github PK

View Code? Open in Web Editor NEW
52.0 2.0 1.0 206 KB

ruff-lsp (ruff) extension for coc.nvim

Home Page: https://www.npmjs.com/package/@yaegassy/coc-ruff

License: MIT License

JavaScript 6.48% TypeScript 93.52%
coc coc-extensions coc-nvim neovim python ruff vim coc-ruff python3 ruff-lsp

coc-ruff's Introduction

coc-ruff

ruff-lsp extension for coc.nvim.

coc-ruff-demo

Install

CocInstall:

:CocInstall @yaegassy/coc-ruff

scoped packages

e.g. vim-plug:

Plug 'yaegassy/coc-ruff', {'do': 'yarn install --frozen-lockfile'}

Note

Detecting the "ruff" command from the execution environment

The ruff command used by ruff-lsp uses the ruff command installed with the ruff-lsp dependency.

To use the ruff command installed in the virtual environment of a project created by venv, poetry, etc., ruff.path must be set to an absolute path.

coc-ruff adds the feature to automatically detect ruff commands in the execution environment and use them in ruff-lsp.

If you do not need this feature, set ruff.useDetectRuffCommand to false.

coc-settings.json:

{
  "ruff.useDetectRuffCommand": false
}

Format (DocumentFormatting)

The black equivalent formatting feature has been added to ruff. This feature is enabled by default in ruff-lsp "v0.0.42" and later.

If you want to disable this feature, set the ruff.disableDocumentFormatting setting to true.

coc-settings.json:

{
  "ruff.disableDocumentFormatting": true
}

If you are using ruff-lsp "v0.4.1" or earlier and want to use this feature, please follow these steps.

  1. Please set ruff.enableExperimentalFormatter to true.
  2. If you are using other Python-related coc-extensions alongside coc-ruff, please disable the formatting feature of those coc-extensions.
    • e.g. coc-pyright:
      • Please set python.formatting.provider to none.

coc-settings.json:

{
  "ruff.enableExperimentalFormatter": true,
  "python.formatting.provider": "none"
}

Auto-fixing

Auto-fixing can be executed via the ruff.executeAutofix command or CodeAction.

Set ruff.autoFixOnSave setting to true if you also want auto-fixing to be performed when the file is saved.

coc-settings.json:

{
  "ruff.autoFixOnSave": true
}

Order of detection of ruff-lsp used by extensions

coc-ruff detects and starts ruff-lsp in the following priority order.

  1. ruff.serverPath (If there is a setting)
  2. current python3/python environment (e.g. ruff-lsp in global or virtual environment)
  3. built-in ruff-lsp (Installation commands are also provided)

Bult-in install

coc-ruff allows you to create an extension-only "venv" and install ruff-lsp.

When using coc-ruff for the first time, if ruff-lsp is not present in the runtime environment, you will be prompted to do a built-in install.

To use the built-in installation feature, execute the following command.

:CocCommand ruff.builtin.installServer

Configuration options

  • ruff.enable: Enable coc-ruff extension, default: true
  • ruff.disableDocumentFormatting: Disable document formatting only, default: false
  • ruff.disableHover: Disable hover only, default: false
  • ruff.useDetectRuffCommand: Automatically detects the ruff command in the execution environment and sets ruff.path, default: true
  • ruff.autoFixOnSave: Turns auto fix on save on or off, default: false
  • ruff.client.codeAction.showDocumantaion.enable: Whether to display the code action for open the Ruff rule documentation web page included in the diagnostic information, default: false
  • ruff.serverPath: Custom path to the ruff-lsp command. If not set, the ruff-lsp command found in the current Python environment or in the venv environment created for the extension will be used, default: ""
  • ruff.builtin.pythonPath: Python 3.x path (Absolute path) to be used for built-in install, default: ""
  • ruff.trace.server: Traces the communication between coc.nvim and the ruff-lsp, default: "off"

Other settings have the same configuration as ruff-vscode.

Commands

  • ruff.executeAutofix: Fix all auto-fixable problems
  • ruff.executeFormat: Format document
  • ruff.executeOrganizeImports: Format imports
  • ruff.showOutput: Show ruff output channel
  • ruff.restart: Restart Server
  • ruff.builtin.installServer: Install ruff-lsp
    • It will be installed in this path:
      • Mac/Linux:
        • ~/.config/coc/extensions/@yaegassy/coc-ruff-data/ruff-lsp/venv/bin/ruff-lsp
      • Windows:
        • ~\AppData\Local\coc\extensions\@yaegassy\coc-ruff-data\ruff-lsp\venv\Scripts\ruff-lsp.exe

Thanks

License

MIT


This extension is built with create-coc-extension

coc-ruff's People

Contributors

dependabot[bot] avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ayersb

coc-ruff's Issues

Auto fix on file save

We can apply auto fix by running ruff.executeAutofix command. It would have been really nice if we get a configuration option for auto fix on file save like in coc-eslint.

Passing args cause ruff to stop linting

I have currently enabled autofix but want some rules to be not autofixable. Ruff provides a setting --unfixable exactly for this. I tried setting ruff.args=["--unfixable F401"] in coc-settings.json. As soon as I add this setting, coc-ruff stops working with no linting and fixing at all.

Adding whitespace before colon

The wrapping of astral-sh/ruff seems to be adding whitespace before colons and triggering the linter E203 after formatting fix. It seems like this was also an issue with astral-sh/ruff, issued here: astral-sh/ruff#8642 and fixed in 2023. Can this be fixed easily by upgrading to a new version of astral-sh?

"CocCommand ruff.builtin.installServer" failed on windows10

Dear coc-ruff developer, coc-ruff are great. Thanks for your contribution. While I tried to install ruff-lsp on windows10 using CocCommand, it failed. Here comes the error messages:

[coc.nvim] Installation of ruff-lsp failed. | Error: Command failed: D:\Program Files\Python38\python.EXE -m venv D:\Users\xxx\AppData\Local\coc\extensions\@yaegassy\coc-ruff-data\ruff-lsp\venv && D:\Users\xxx\AppData\Local\coc\extensions\@yaegassy\coc-ruff-data\ruff-lsp\venv\Scripts\python -m pip install -U pip ruff-lsp==0.0.27
'D:\Program' �����ڲ����ⲿ���Ҳ���ǿ����еij���

After I do the next three steps, everything goes fine. Hope It will benefit other junior windows users like me. And would you consider optimizing the install command?

  1. create a virtulenv,
  2. install ruff-lsp in exact virtualenv ,
  3. assign the actual ruff path via CocConfig:
    "ruff.path": ["D:/User/xxx/AppData/Local/coc/extensions/@yaegassy/coc-ruff-data/ruff-lsp/venv/Scripts/ruff"],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.