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

LSP snippets are expanding with incorrect indentation level. #2091

Open
2 tasks done
Rid1FZ opened this issue Nov 18, 2024 · 0 comments
Open
2 tasks done

LSP snippets are expanding with incorrect indentation level. #2091

Rid1FZ opened this issue Nov 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Rid1FZ
Copy link

Rid1FZ commented Nov 18, 2024

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

-- install lazy.nvim if not already installed
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable", -- latest stable release
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)

-- install and setup plugins with lazy.nvim
require("lazy").setup({
	{
		"neovim/nvim-lspconfig",
		lazy = false,
		config = function()
			local lspconfig = require("lspconfig")

			lspconfig.pyright.setup({})
		end,
	},
	{
		"hrsh7th/nvim-cmp",
		dependencies = {
			"onsails/lspkind.nvim",
			"hrsh7th/cmp-nvim-lsp",
		},
		config = function()
			local cmp = require("cmp")
			cmp.setup({
				snippet = {
					expand = function(args)
						vim.snippet.expand(args.body)
					end,
				},

				preselect = cmp.PreselectMode.None,
				confirm_opts = {
					behavior = cmp.ConfirmBehavior.Replace,
					select = true,
				},

				mapping = {
					["<CR>"] = cmp.mapping(cmp.mapping.confirm({ select = false }), { "i", "c" }),
					["<Tab>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i" }),
				},

				sources = cmp.config.sources({ { name = "nvim_lsp" } }),
			})
		end,
	},
})

Description

I noticed that for pyright language server, some LSP snippets were not expanding correctly. It is particularly happening inside classes for some dunders(like __init__ or __str__). What actually happens is it indents the second line incorrectly. I did some research and found that those snippets were expanding accordingly in AstroNvim and LazyVim configs. I copy pasted some lines from those configs, but no luck. An example gif is added demonstrating the issue.

Steps to reproduce

  1. Setup pyright language server with default configs
  2. Open any python file
  3. Create a class
  4. Try to create any dunder(like __init__). cmp will give suggestions. There will be one suggestion which is a snippet provided by pyright language server
  5. Expand that snippet
  6. See the error

Expected behavior

The second line(with pass keyword) should have indented 1 level deeper

Actual behavior

The second line(with pass keyword) is indented at the same level as def keyword which is wrong.

Additional context

This gif demonstrates the actual issue.
pyright

@Rid1FZ Rid1FZ added the bug Something isn't working label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant