Skip to content

[audit] Gate pyrefly vs pyright — prevent dual Python LSP attach#272

Closed
stanfish06 wants to merge 1 commit into
masterfrom
audit/dual-python-lsp
Closed

[audit] Gate pyrefly vs pyright — prevent dual Python LSP attach#272
stanfish06 wants to merge 1 commit into
masterfrom
audit/dual-python-lsp

Conversation

@stanfish06

Copy link
Copy Markdown
Owner

What

vim.lsp.enable("pyright") and vim.lsp.enable("pyrefly") were both called unconditionally. On any machine where both tools are installed, two Python LSP clients attach to every .py file simultaneously.

File: lua/config/plugin_config.lua:102-105

Why it matters

When two LSPs attach to the same filetype:

  • Diagnostics are duplicated (same error shown twice, once per client)
  • Hover/completion results are interleaved
  • Code actions from both servers are merged, creating confusing duplicates

The inline comment already acknowledges pyrefly and pyright are alternatives ("pyrefly seems capable of showing more type issues"), not an intentional dual-server setup.

Change

Prefer pyrefly when installed, fall back to pyright — only one attaches per session:

if vim.fn.executable("pyrefly") == 1 then
    vim.lsp.enable("pyrefly")
else
    vim.lsp.enable("pyright")
end

To switch back to pyright temporarily, either uninstall pyrefly or comment out its branch.


Generated by Claude Code

Enables pyrefly when installed, falls back to pyright. Previously both
were unconditionally enabled, causing duplicate diagnostics and hover
conflicts on machines where both tools are present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BBEgozMQ7iHP5JETZTGfNi

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe881e47f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

-- pyrefly seems capable of showing more type issues as far as I can tell
vim.lsp.enable("pyrefly")
-- pyrefly seems capable of showing more type issues; prefer it when installed, fall back to pyright
if vim.fn.executable("pyrefly") == 1 then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not disable pyright just because pyrefly is installed

When pyrefly is installed globally for one project, this branch disables pyright for every Python buffer, including repos that only have pyrightconfig.json/pyright-specific settings. At the locked nvim-lspconfig rev, pyrefly starts as pyrefly lsp and does not list pyrightconfig.json among its root markers (source), while Pyrefly’s docs say projects without a Pyrefly config fall back to the much smaller basic preset (source); those projects therefore lose the configured pyright diagnostics that worked before. Please make the choice project/config-aware rather than only checking whether the executable exists.

Useful? React with 👍 / 👎.

@stanfish06 stanfish06 closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants