mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
fix(lsp): do not add extra indentation
This commit is contained in:
parent
370232dbef
commit
94127cb5df
@ -346,6 +346,7 @@ end
|
|||||||
function M.expand(input)
|
function M.expand(input)
|
||||||
local snippet = G.parse(input)
|
local snippet = G.parse(input)
|
||||||
local snippet_text = {}
|
local snippet_text = {}
|
||||||
|
local base_indent = vim.api.nvim_get_current_line():match('^%s*') or ''
|
||||||
|
|
||||||
-- Get the placeholders we should use for each tabstop index.
|
-- Get the placeholders we should use for each tabstop index.
|
||||||
--- @type table<integer, string>
|
--- @type table<integer, string>
|
||||||
@ -377,10 +378,10 @@ function M.expand(input)
|
|||||||
---
|
---
|
||||||
--- @param text string|string[]
|
--- @param text string|string[]
|
||||||
local function append_to_snippet(text)
|
local function append_to_snippet(text)
|
||||||
|
local snippet_lines = text_to_lines(snippet_text)
|
||||||
-- Get the base indentation based on the current line and the last line of the snippet.
|
-- Get the base indentation based on the current line and the last line of the snippet.
|
||||||
local base_indent = vim.api.nvim_get_current_line():match('^%s*') or ''
|
if #snippet_lines > 0 then
|
||||||
if #snippet_text > 0 then
|
base_indent = base_indent .. (snippet_lines[#snippet_lines]:match('(^%s*)%S') or '') --- @type string
|
||||||
base_indent = base_indent .. (snippet_text[#snippet_text]:match('^%s*') or '') --- @type string
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local lines = vim.iter.map(function(i, line)
|
local lines = vim.iter.map(function(i, line)
|
||||||
|
@ -48,6 +48,10 @@ describe('vim.snippet', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('adds indentation based on the start of snippet lines', function()
|
||||||
|
test_success({ 'if $1 then', ' $0', 'end' }, { 'if then', ' ', 'end' })
|
||||||
|
end)
|
||||||
|
|
||||||
it('replaces tabs with spaces when expandtab is set', function()
|
it('replaces tabs with spaces when expandtab is set', function()
|
||||||
test_success(
|
test_success(
|
||||||
{ 'function $1($2)', '\t$0', 'end' },
|
{ 'function $1($2)', '\t$0', 'end' },
|
||||||
|
Loading…
Reference in New Issue
Block a user