From b6f3df8ab10e0a45f627544ffa5a5472a0b79981 Mon Sep 17 00:00:00 2001 From: Ava Gaiety W Date: Mon, 16 Jun 2025 23:29:08 -0600 Subject: [PATCH] fixed vim global, added lsp keys, moved pairs, cmp configured again right --- .luarc.json | 5 + nvim/lazy-lock.json | 2 + nvim/lua/plugins/completion.lua | 53 --------- nvim/lua/plugins/lsp.lua | 190 ++++++++++++++++++++++++++++++-- nvim/lua/plugins/pairs.lua | 12 ++ 5 files changed, 200 insertions(+), 62 deletions(-) create mode 100644 .luarc.json delete mode 100644 nvim/lua/plugins/completion.lua diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..1e1765c --- /dev/null +++ b/.luarc.json @@ -0,0 +1,5 @@ +{ + "diagnostics.globals": [ + "vim" + ] +} \ No newline at end of file diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index cb933a8..81ff5b1 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -2,7 +2,9 @@ "LuaSnip": { "branch": "master", "commit": "fb525166ccc30296fb3457441eb979113de46b00" }, "alpha-nvim": { "branch": "main", "commit": "a35468cd72645dbd52c0624ceead5f301c566dff" }, "catppuccin": { "branch": "main", "commit": "fa42eb5e26819ef58884257d5ae95dd0552b9a66" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, + "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "codestats.nvim": { "branch": "master", "commit": "041b315c4f82997186fcdb3fc2f687cc128a28f3" }, "flash.nvim": { "branch": "main", "commit": "3c942666f115e2811e959eabbdd361a025db8b63" }, diff --git a/nvim/lua/plugins/completion.lua b/nvim/lua/plugins/completion.lua deleted file mode 100644 index 0a554e3..0000000 --- a/nvim/lua/plugins/completion.lua +++ /dev/null @@ -1,53 +0,0 @@ -return { - { - "windwp/nvim-ts-autotag", - config = function() - require('nvim-ts-autotag').setup({ - opts = { - enable_close = true, -- Auto close tags - enable_rename = true, -- Auto rename pairs of tags - enable_close_on_slash = true -- Auto close on trailing '] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, -- For luasnip users. - { name = 'path' }, - { name = 'emoji' }, - }, { - { name = 'buffer' }, - }) - }) - end - }, - { - "L3MON4D3/LuaSnip", - dependencies = { - "rafamadriz/friendly-snippets", - "saadparwaiz1/cmp_luasnip", - }, - } -} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index 4801de2..3e7c572 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -3,14 +3,6 @@ return { "smjonas/inc-rename.nvim", opts = {} }, - -- { - -- "mason-org/mason-lspconfig.nvim", - -- opts = {}, - -- dependencies = { - -- { "mason-org/mason.nvim", opts = {} }, - -- "neovim/nvim-lspconfig", - -- }, - -- }, { { "mason-org/mason-lspconfig.nvim", @@ -18,9 +10,189 @@ return { ensure_installed = { "lexical" } }, dependencies = { - { "mason-org/mason.nvim", opts = {} }, + { "mason-org/mason.nvim", opts = {} }, { "neovim/nvim-lspconfig" }, + { "hrsh7th/nvim-cmp" }, + { "hrsh7th/cmp-nvim-lsp" }, + { "hrsh7th/cmp-buffer" }, + { "hrsh7th/cmp-path" }, + { "saadparwaiz1/cmp_luasnip" }, + { "L3MON4D3/LuaSnip" }, + { "rafamadriz/friendly-snippets" }, }, + config = function() + vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function() + local bufmap = function(mode, lhs, rhs) + local opts = { buffer = true } + vim.keymap.set(mode, lhs, rhs, opts) + end + + bufmap('n', 'K', 'lua vim.lsp.buf.hover()') + bufmap('n', 'gd', 'lua vim.lsp.buf.definition()') + bufmap('n', 'gD', 'lua vim.lsp.buf.declaration()') + bufmap('n', 'gi', 'lua vim.lsp.buf.implementation()') + bufmap('n', 'go', 'lua vim.lsp.buf.type_definition()') + bufmap('n', 'gr', 'lua vim.lsp.buf.references()') + bufmap('n', 'gs', 'lua vim.lsp.buf.signature_help()') + bufmap('n', '', 'lua vim.lsp.buf.rename()') + bufmap('n', '', 'lua vim.lsp.buf.format({async = true})') + bufmap('n', '', 'lua vim.lsp.buf.code_action()') + bufmap('n', 'gl', 'lua vim.diagnostic.open_float()') + bufmap('n', '[d', 'lua vim.diagnostic.goto_prev()') + bufmap('n', ']d', 'lua vim.diagnostic.goto_next()') + end + }) + + + --- + -- Diagnostics + --- + + local sign = function(opts) + vim.fn.sign_define(opts.name, { + texthl = opts.name, + text = opts.text, + numhl = '' + }) + end + + sign({ name = 'DiagnosticSignError', text = '✘' }) + sign({ name = 'DiagnosticSignWarn', text = '▲' }) + sign({ name = 'DiagnosticSignHint', text = '⚑' }) + sign({ name = 'DiagnosticSignInfo', text = '' }) + + vim.diagnostic.config({ + virtual_text = false, + severity_sort = true, + float = { + border = 'rounded', + source = 'always', + }, + }) + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + { border = 'rounded' } + ) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + { border = 'rounded' } + ) + + --- + -- LSP servers + --- + + -- require('mason').setup({}) + -- require('mason-lspconfig').setup({}) + + local lspconfig = require('lspconfig') + local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities() + + lspconfig.tsserver.setup({ + capabilities = lsp_capabilities, + }) + lspconfig.lua_ls.setup({ + capabilities = lsp_capabilities, + }) + + + --- + -- Autocomplete + --- + vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } + + require('luasnip.loaders.from_vscode').lazy_load() + + local cmp = require('cmp') + local luasnip = require('luasnip') + + local select_opts = { behavior = cmp.SelectBehavior.Select } + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + sources = { + { name = 'path' }, + { name = 'nvim_lsp', keyword_length = 1 }, + { name = 'buffer', keyword_length = 3 }, + { name = 'luasnip', keyword_length = 2 }, + }, + window = { + documentation = cmp.config.window.bordered() + }, + formatting = { + fields = { 'menu', 'abbr', 'kind' }, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + return item + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), + + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), + + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.confirm({ select = false }), + + [''] = cmp.mapping(function(fallback) + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + local col = vim.fn.col('.') - 1 + + if cmp.visible() then + cmp.select_next_item(select_opts) + elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + fallback() + else + cmp.complete() + end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item(select_opts) + else + fallback() + end + end, { 'i', 's' }), + }, + }) + end } }, { diff --git a/nvim/lua/plugins/pairs.lua b/nvim/lua/plugins/pairs.lua index 6d50630..8e75e15 100644 --- a/nvim/lua/plugins/pairs.lua +++ b/nvim/lua/plugins/pairs.lua @@ -2,6 +2,18 @@ return { { 'RRethy/nvim-treesitter-endwise', }, + { + "windwp/nvim-ts-autotag", + config = function() + require('nvim-ts-autotag').setup({ + opts = { + enable_close = true, -- Auto close tags + enable_rename = true, -- Auto rename pairs of tags + enable_close_on_slash = true -- Auto close on trailing