Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Setup --preview flag for neovim lsp #12408

Closed
eltbus opened this issue Jul 19, 2024 · 7 comments
Closed

Setup --preview flag for neovim lsp #12408

eltbus opened this issue Jul 19, 2024 · 7 comments
Labels
question Asking for support or clarification

Comments

@eltbus
Copy link

eltbus commented Jul 19, 2024

Keywords

"neovim", "nvim", "lsp", "ruff", "server", "--preview"

Code/settings example

# Using Lazy, inside "neovim/nvim-lspconfig":
["ruff"] = function()
	local lspconfig = require("lspconfig")
	local lsp_python = require("plugins.lsp.python")
	local custom_on_attach = function(client, bufnr)
		on_attach(client, bufnr)
		client.server_capabilities.hoverProvider = false
	end
	lspconfig.ruff.setup {
		on_attach = custom_on_attach,
		capabilities=capabilities,
		on_init = function(client)
			client.config.settings.interpreter = lsp_python.get_python_path(client.config.root_dir)
		end,
		init_options = { settings = { lint = { preview = true } } }
	}
end,

Ruff version

0.5.2

Issue

On medium to big projects (i.e. uvicorn) I get the following warning:

[ERROR][2024-07-19 18:03:54] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/eltbus/.local/share/nvim/mason/bin/ruff"	"stderr"	"error: --preview needs to be provided as a command line argument while the server is still unstable.\nFor example: `ruff server --preview`\n"

Question

How can I set that flag while using nvim? I tried the following

init_options = { settings = { lint = { preview = true } } }

But it does not solve the issue (probably because this is a LINTER option, and not a SERVER option.

@FishAlchemist
Copy link
Contributor

FishAlchemist commented Jul 19, 2024

If you want to enable preview for lint, why not just set it in the configuration file(e.g. pyproject.toml, ruff.toml)?
I just want to know why your usage scenario can't do this.

These are the relevant link to the settings:
https://docs.astral.sh/ruff/settings/#preview
https://docs.astral.sh/ruff/settings/#lint_preview
https://docs.astral.sh/ruff/settings/#format_preview

Edit:
Ruff server (ruff-lsp) was unstable before Ruff version 0.5.3, so the preview flag needed to be provided. Providing only the preview flag for lint would not allow the Ruff server to be used.

@T-256
Copy link
Contributor

T-256 commented Jul 19, 2024

error: --preview needs to be provided as a command line argument while the server is still unstable.

I think update to 0.5.3 will solve it.

@eltbus
Copy link
Author

eltbus commented Jul 20, 2024

Update 0.5.3 did indeed solve my issue. Thank you, @T-256!

@dhruvmanila
Copy link
Member

Yes, this was indicated as a breaking change in nvim-lspconfig (neovim/nvim-lspconfig#3241). If you've upgrade nvim-lspconfig to include that commit, you need to be using a minimum Ruff version of 0.5.3.

@dhruvmanila dhruvmanila added the question Asking for support or clarification label Jul 22, 2024
@dhruvmanila
Copy link
Member

Closing this issue as resolved. Feel free to ask any other questions that you might have.

@FishAlchemist
Copy link
Contributor

Yes, this was indicated as a breaking change in nvim-lspconfig (neovim/nvim-lspconfig#3241). If you've upgrade nvim-lspconfig to include that commit, you need to be using a minimum Ruff version of 0.5.3.

Should this PR be mentioned in Editors > Setup > Neovim?

@dhruvmanila
Copy link
Member

Should this PR be mentioned in Editors > Setup > Neovim?

Yeah, good idea.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

4 participants