mirror of
https://github.com/neovim/neovim
synced 2025-07-22 22:31:46 +00:00
fix(snippet): do not add extra indent on newlines (#28538)
Reverts parts of https://github.com/neovim/neovim/pull/27674 LSP snippets typically do include tabs or spaces to add extra indentation and don't rely on the client using `autoindent` functionality. For example: public static void main(String[] args) {\n\t${0}\n} Notice the `\t` after `{\n` Adding spaces or tabs independent of that breaks snippets for languages like Haskell where you can have snippets like: ${1:name} :: ${2}\n${1:name} ${3}= ${0:undefined} To generate: name :: name = undefined
This commit is contained in:
committed by
GitHub
parent
c3061a40f7
commit
4625394a76
@ -459,8 +459,7 @@ function M.expand(input)
|
|||||||
end
|
end
|
||||||
-- Add the base indentation.
|
-- Add the base indentation.
|
||||||
if i > 1 then
|
if i > 1 then
|
||||||
line = #line ~= 0 and base_indent .. line
|
line = base_indent .. line
|
||||||
or (expandtab and (' '):rep(shiftwidth) or '\t'):rep(vim.fn.indent('.') / shiftwidth + 1)
|
|
||||||
end
|
end
|
||||||
lines[#lines + 1] = line
|
lines[#lines + 1] = line
|
||||||
end
|
end
|
||||||
|
@ -245,6 +245,15 @@ describe('vim.snippet', function()
|
|||||||
|
|
||||||
it('correctly indents with newlines', function()
|
it('correctly indents with newlines', function()
|
||||||
local curbuf = api.nvim_get_current_buf()
|
local curbuf = api.nvim_get_current_buf()
|
||||||
|
test_expand_success(
|
||||||
|
{ 'function($2)\n\t$3\nend' },
|
||||||
|
{ 'function()', ' ', 'end' },
|
||||||
|
[[
|
||||||
|
vim.opt.sw = 2
|
||||||
|
vim.opt.expandtab = true
|
||||||
|
]]
|
||||||
|
)
|
||||||
|
api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
|
||||||
test_expand_success(
|
test_expand_success(
|
||||||
{ 'function($2)\n$3\nend' },
|
{ 'function($2)\n$3\nend' },
|
||||||
{ 'function()', '', 'end' },
|
{ 'function()', '', 'end' },
|
||||||
@ -255,7 +264,7 @@ describe('vim.snippet', function()
|
|||||||
)
|
)
|
||||||
api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
|
api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
|
||||||
test_expand_success(
|
test_expand_success(
|
||||||
{ 'func main() {\n$1\n}' },
|
{ 'func main() {\n\t$1\n}' },
|
||||||
{ 'func main() {', '\t', '}' },
|
{ 'func main() {', '\t', '}' },
|
||||||
[[
|
[[
|
||||||
vim.opt.sw = 4
|
vim.opt.sw = 4
|
||||||
@ -263,5 +272,18 @@ describe('vim.snippet', function()
|
|||||||
vim.opt.expandtab = false
|
vim.opt.expandtab = false
|
||||||
]]
|
]]
|
||||||
)
|
)
|
||||||
|
api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
|
||||||
|
test_expand_success(
|
||||||
|
{ '${1:name} :: ${2}\n${1:name} ${3}= ${0:undefined}' },
|
||||||
|
{
|
||||||
|
'name :: ',
|
||||||
|
'name = undefined',
|
||||||
|
},
|
||||||
|
[[
|
||||||
|
vim.opt.sw = 4
|
||||||
|
vim.opt.ts = 4
|
||||||
|
vim.opt.expandtab = false
|
||||||
|
]]
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user