mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Optimize Imports in Python came only from the Ruff language server, which starts only below a Ruff configuration, so in other projects it said "Optimize imports is not available" and the Optimize imports options on save, before commit and in Code Cleanup did nothing. When no server offers `source.organizeImports` for a Python file, the IDE now runs `ruff check --extend-select I --fixable I,F401 --fix --exit-zero` on the unsaved text and offers the result as the organize-imports action, for the editor and for the MCP tools' organize-imports step alike. Imports are sorted; unused ones are removed where the project's Ruff rules check F401 (Ruff's defaults do; an `ignore` or `select` without it keeps them). It reads the project's Ruff settings or the configured Ruff configuration directory. Ruff comes from the file's project environment first (`.venv/bin/ruff`), as the Ruff language server does, then the IDE's copy and `PATH`. Without Ruff the action is disabled with "Install Ruff to optimize imports in Python files". Projects with a Ruff configuration keep using the Ruff server, which only sorts. The first commit (Ruff from the project environment for Reformat Code too) answers a review comment on #5372, which was merged before it landed there. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>