diff options
author | Maria José Solano <majosolano99@gmail.com> | 2023-10-22 22:38:11 -0700 |
---|---|---|
committer | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2023-10-23 17:21:41 +0200 |
commit | 94127cb5df0a513e66777d18a2c7fa6219404280 (patch) | |
tree | a382c4cc0fd5fa9045bc48e918a889c072fd514f | |
parent | 370232dbefb91b7ee773ee9a61a9b1ad77d7f1af (diff) | |
download | rneovim-94127cb5df0a513e66777d18a2c7fa6219404280.tar.gz rneovim-94127cb5df0a513e66777d18a2c7fa6219404280.tar.bz2 rneovim-94127cb5df0a513e66777d18a2c7fa6219404280.zip |
fix(lsp): do not add extra indentation
-rw-r--r-- | runtime/lua/vim/snippet.lua | 7 | ||||
-rw-r--r-- | test/functional/lua/snippet_spec.lua | 4 |
2 files changed, 8 insertions, 3 deletions
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<integer, string> @@ -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) diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua index fea9d1e982..738420d87d 100644 --- a/test/functional/lua/snippet_spec.lua +++ b/test/functional/lua/snippet_spec.lua @@ -48,6 +48,10 @@ describe('vim.snippet', function() ) 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() test_success( { 'function $1($2)', '\t$0', 'end' }, |