From 94127cb5df0a513e66777d18a2c7fa6219404280 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Sun, 22 Oct 2023 22:38:11 -0700 Subject: fix(lsp): do not add extra indentation --- runtime/lua/vim/snippet.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua index 3fe8ab2d48..7680d2e216 100644 --- a/runtime/lua/vim/snippet.lua +++ b/runtime/lua/vim/snippet.lua @@ -346,6 +346,7 @@ end function M.expand(input) local snippet = G.parse(input) 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. --- @type table @@ -377,10 +378,10 @@ function M.expand(input) --- --- @param text string|string[] 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. - local base_indent = vim.api.nvim_get_current_line():match('^%s*') or '' - if #snippet_text > 0 then - base_indent = base_indent .. (snippet_text[#snippet_text]:match('^%s*') or '') --- @type string + if #snippet_lines > 0 then + base_indent = base_indent .. (snippet_lines[#snippet_lines]:match('(^%s*)%S') or '') --- @type string end local lines = vim.iter.map(function(i, line) -- cgit