Editors¶
konform ships a language server that shares the CLI's rule engine, so there is no second process and no stale results.
Code actions¶
A quickfix is offered for every fixable diagnostic (including unsafe ones such as KIS002, since editing one open document is an explicit, reviewable action), plus:
- Fix all auto-fixable problems: safe fixes only (
source.fixAll.konform). - Fix all problems (including unsafe fixes) (
source.fixAll.konform.unsafe): only offered when it changes something beyond the safe pass. - Disable CODE for this line: adds
# noqa: CODE(merged into an existing# noqa). Not offered for the KNQ rules, which# noqacan't suppress, or on a line that ends inside a multi-line string.
Hovering a code in a # noqa comment shows that rule's documentation; a prefix such as
KIS lists the rules it covers. Files matching exclude get no diagnostics or fixes.
The server reloads rules when pyproject.toml, konform.toml,
konform_patterns.toml/.yaml, konform_rules.toml, the configured rules_file
(of either rule) or a file pulled in through extend changes. If you
point rules_file or extend at a new path, restart the server.
Workspace root and folders¶
The server reads its configuration, and discovers the Python interpreter, from the
workspace root: the first workspace folder the client sends, else rootUri, else the
deprecated rootPath. Only if none is a local directory does it use its working
directory, and it then shows a warning saying so.
A server handles one root. With several workspace folders open, the first one's
configuration applies to all of them and the editor shows a warning; configure your
client to start one server per folder (as the Neovim example below does) for separate
settings. workspace/didChangeWorkspaceFolders is not supported.
If the Python interpreter cannot be run (a wrong python setting, a broken virtualenv),
the editor shows a warning naming it, since imports then cannot be resolved.
Neovim¶
vim.api.nvim_create_autocmd("FileType", {
pattern = "python",
callback = function()
vim.lsp.start({
name = "konform",
cmd = { "konform", "server" },
root_dir = vim.fs.dirname(
vim.fs.find({ "pyproject.toml", "konform.toml" }, { upward = true })[1]
),
})
end,
})
VS Code¶
Use the generic None ls extension, or any client supporting a custom LSP command:
Zed¶
Install the zed-konform extension (see extensions/zed-extension/README.md);
Zed installs the konform binary automatically. To override: