Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

pylsp delete all text when formatting #1025

Closed
3 tasks done
nkta3m opened this issue Oct 18, 2023 · 9 comments
Closed
3 tasks done

pylsp delete all text when formatting #1025

nkta3m opened this issue Oct 18, 2023 · 9 comments
Labels
bug Something isn't working lsp LSP related issues upstream Upstream (neovim/plugin) issues

Comments

@nkta3m
Copy link

nkta3m commented Oct 18, 2023

Version confirmation

  • Confirm

Following prerequisites

  • Confirm

Not a user config issue

  • Confirm

Neovim version

NVIM v0.9.4 Build type: Release LuaJIT 2.1.1692716794

Operating system/version

Debian

Terminal name/version

alacritty

$TERM environment variable

No response

Branch info

main (Default/Latest)

Fetch Preferences

HTTPS (use_ssh = false)

Affected language servers

pylsp

How to reproduce the issue

  1. open python file
  2. save

Actual behavior

normal format

Expected behavior

No response

Support info

2023-10-18 14_47_02-Window
2023-10-18 14_47_25-Window

Logs

[ERROR][2023-10-18 14:41:56] .../vim/lsp/rpc.lua:734	"rpc"	"~/.local/share/nvim/mason/bin/pylsp"	"stderr"	"2023-10-18 14:41:56,891 CST - ERROR - pylsp_ruff.plugin - Error running ruff: error: unexpected argument '--format' found\n\n  tip: to pass '--format' as a value, use '-- --format'\n\nUsage: ruff check <--verbose|--quiet|--silent> [FILES]...\n\nFor more information, try '--help'.\n\n"

Additional information

No response

@nkta3m nkta3m added bug Something isn't working lsp LSP related issues labels Oct 18, 2023
@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 18, 2023

seems like an upstream error, have u check their repo yet?

@nkta3m
Copy link
Author

nkta3m commented Oct 18, 2023

no, i don't know how to configure pylsp.

@ayamir
Copy link
Owner

ayamir commented Oct 18, 2023

In fact, ruff is not responsible for formatting, it just provides the code lint function. black is installed to do format. I have no idea about the error log.

image

@nkta3m
Copy link
Author

nkta3m commented Oct 18, 2023

Is it possible to specify the version of pylsp?

@ayamir
Copy link
Owner

ayamir commented Oct 18, 2023

Is it possible to specify the version of pylsp?

You reminded me. I upgraded the latest pylsp. This bug can be reproduced for pylsp (version==1.8.2)

@ayamir ayamir added has:repro This issue contains reproducing steps upstream Upstream (neovim/plugin) issues labels Oct 18, 2023
@ayamir
Copy link
Owner

ayamir commented Oct 18, 2023

@ayamir
Copy link
Owner

ayamir commented Oct 18, 2023

The workaround is to use black via null-ls and disable the format function from pylsp.

@nkta3m Add these lines to lua/user/settings.lua.

settings["server_formatting_block_list"] = {
	pylsp = true,
}
settings["null_ls_deps"] = {
	"black",
}

Additionally, to use the lint function normally before python-lsp-ruff be fixed, you should enable flake8 or pyflakes by adding lua/user/configs/lsp-servers/pylsp.lua with the following content:

-- https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/pylsp.lua
return {
	cmd = { "pylsp" },
	filetypes = { "python" },
	settings = {
		pylsp = {
			plugins = {
				-- Lint
				ruff = {
					enabled = false,
					select = {
						-- enable pycodestyle
						"E",
						-- enable pyflakes
						"F",
					},
					ignore = {
						-- ignore E501 (line too long)
						-- "E501",
						-- ignore F401 (imported but unused)
						-- "F401",
					},
					extendSelect = { "I" },
					severities = {
						-- Hint, Information, Warning, Error
						F401 = "I",
						E501 = "I",
					},
				},
				flake8 = { enabled = true },
				pyflakes = { enabled = false },
				pycodestyle = { enabled = false },
				mccabe = { enabled = false },

				-- Code refactor
				rope = { enabled = true },

				-- Formatting
				black = { enabled = true },
				pyls_isort = { enabled = false },
				autopep8 = { enabled = false },
				yapf = { enabled = false },
			},
		},
	},
}

@ayamir ayamir added the has:workaround This issue is not fixed but can be circumvented until then label Oct 18, 2023
@nkta3m
Copy link
Author

nkta3m commented Oct 18, 2023

Great, thanks!

@Jint-lzxy Jint-lzxy added status:blocked-external Needs a third-party / external change or fix and removed has:repro This issue contains reproducing steps labels Oct 18, 2023
@nkta3m
Copy link
Author

nkta3m commented Oct 20, 2023

Upstream has been fixed, reinstalling the plugin will solve the problem

@ayamir ayamir closed this as completed Oct 20, 2023
@ayamir ayamir removed has:workaround This issue is not fixed but can be circumvented until then status:blocked-external Needs a third-party / external change or fix labels Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lsp LSP related issues upstream Upstream (neovim/plugin) issues
Projects
None yet
Development

No branches or pull requests

4 participants