diff --git a/lua/lsp/mappings.lua b/lua/lsp/mappings.lua index f1e034d..71f10cf 100644 --- a/lua/lsp/mappings.lua +++ b/lua/lsp/mappings.lua @@ -40,8 +40,8 @@ function M.init(client, bufnr) -- code actions buf_map('n', 'r', 'lua vim.lsp.buf.rename()', { desc = 'Rename' }) - buf_map('n', 'la', 'lua vim.lsp.buf.code_actions()', { desc = 'Code Actions' }) - buf_map('v', 'la', 'lua vim.lsp.buf.range_code_actions()', { desc = 'Range Code Actions' }) + buf_map('n', 'a', 'lua vim.lsp.buf.code_action()', { desc = 'Code Actions' }) + buf_map('v', 'a', 'lua vim.lsp.buf.range_code_action()', { desc = 'Range Code Actions' }) -- formatting if client.supports_method('textDocument/formatting') then diff --git a/lua/lsp/servers.lua b/lua/lsp/servers.lua index 6819ce0..8641e11 100644 --- a/lua/lsp/servers.lua +++ b/lua/lsp/servers.lua @@ -1,5 +1,7 @@ return { rust_analyzer = true, + zls = true, + clangd = true, erlangls = true, lua_ls = { format_on_save = false, @@ -11,5 +13,8 @@ return { ts_ls = { format_on_save = false, }, + tailwindcss = { + format_on_save = false, + }, svelte = true, } diff --git a/lua/plugins/nvim-cmp/config.lua b/lua/plugins/nvim-cmp/config.lua index 569f0f7..8028de4 100644 --- a/lua/plugins/nvim-cmp/config.lua +++ b/lua/plugins/nvim-cmp/config.lua @@ -17,6 +17,27 @@ local snippet = { end, } +-- check if the cursor is inside a snippet. +local function in_snippet() + local session = luasnip.session + local node = session.current_nodes[vim.api.nvim_get_current_buf()] + if not node then + return + end + local snippet = node.parent.snippet + local snip_begin_pos, snip_end_pos = snippet.mark:pos_begin_end() + local pos = vim.api.nvim_win_get_cursor(0) + if pos[1] - 1 >= snip_begin_pos[1] and pos[1] - 1 <= snip_end_pos[1] then + return true -- not on row inside snippet + end +end + +-- check if snippet is expandable or jumpable. +-- Only jumping if the cursor is inside the snippet +local function expandable_or_locally_jumpable() + return luasnip.expandable() or (in_snippet() and luasnip.jumpable()) +end + local cmp_opts = { enabled = function() -- disable completion in comments @@ -44,7 +65,7 @@ local cmp_opts = { [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then + elseif expandable_or_locally_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then cmp.complete()