diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2024-04-26 12:48:36 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2024-04-26 12:48:36 -0400 |
commit | 7e1c5f4418a629d6f3bae954dd172ca81e476b3e (patch) | |
tree | d0806f2925ff0574e26fa22a7ff073036a2a0d9a /config/nvim/lua | |
parent | 7b79203f54853733d4fae88943829d0e24e6e49f (diff) | |
download | nix-config-7e1c5f4418a629d6f3bae954dd172ca81e476b3e.tar.gz nix-config-7e1c5f4418a629d6f3bae954dd172ca81e476b3e.tar.bz2 nix-config-7e1c5f4418a629d6f3bae954dd172ca81e476b3e.zip |
update laptop config
Diffstat (limited to 'config/nvim/lua')
-rw-r--r-- | config/nvim/lua/lsp.lua | 145 | ||||
-rw-r--r-- | config/nvim/lua/settings.lua | 34 |
2 files changed, 179 insertions, 0 deletions
diff --git a/config/nvim/lua/lsp.lua b/config/nvim/lua/lsp.lua new file mode 100644 index 0000000..1056431 --- /dev/null +++ b/config/nvim/lua/lsp.lua @@ -0,0 +1,145 @@ +local cmp = require("cmp") +local nvim_lsp = require("lspconfig") +local cmp_window = require("cmp.utils.window") + +vim.o.completeopt = "menuone,noselect" +vim.o.shortmess = vim.o.shortmess .. "c" + +local function on_attach(client, bufn) + local function map(...) + vim.api.nvim_buf_set_keymap(bufn, ...) + end + + local function buf_set_option(...) + vim.api.nvim_buf_set_option(bufn, ...) + end + + local opts = { noremap = true, silent = true } + map("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) + map("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts) + map("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts) + map("n", "gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>", opts) + map("n", "<C-k>", "<Cmd>lua vim.lsp.buf.signature_help()<CR>", opts) + map("n", "<leader>D", "<Cmd>lua vim.lsp.buf.type_definition()<CR>", opts) + map("n", "gr", "<Cmd>lua vim.lsp.buf.references()<CR>", opts) + map("n", "<leader>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts) + map("n", "[d", "<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts) + map("n", "]d", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts) + map("n", "<leader>q", "<Cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts) + map("n", "ga", "<Cmd>lua vim.lsp.buf.code_action()<CR>", opts) +end + +local function has_words_before() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil +end + +local function feedkey(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end + +local function border(hl_name) + return { + { "╭", hl_name }, + { "─", hl_name }, + { "╮", hl_name }, + { "│", hl_name }, + { "╯", hl_name }, + { "─", hl_name }, + { "╰", hl_name }, + { "│", hl_name }, + } +end + +cmp_window.info_ = cmp_window.info +cmp_window.info = function(self) + local info = self:info_() + info.scrollable = false + return info +end + +cmp.setup({ + window = { + completion = { + border = border "CmpBorder", + winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", + }, + documentation = { + border = border "CmpDocBorder" + }, + }, + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + ['<C-b>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + ['<C-Space>'] = cmp.mapping.complete(), + ['<C-e>'] = cmp.mapping.abort(), + ['<CR>'] = cmp.mapping.confirm({select = true}), + ["<Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("<Plug>(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, {"i", "s"}), + + ["<S-Tab"] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("<Plug>(vsnip-jump-prev)", "") + end + end, {"i", "s"}), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "vsnip" }, + { name = "treesitter" }, + { name = "path", option = { trailing_slash = true }}, + { name = "buffer" } + }), +}) + +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), +}) + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = true, + signs = true, + update_in_insert = true + } +) + +local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + +local servers = { "ccls", "bashls", "rnix", "texlab", "lua_ls" } + +for _, lang in pairs(servers) do + nvim_lsp[lang].setup({ + root_dir = vim.loop.cwd, + on_attach = on_attach, + capabilities = capabilities + }) +end + +require("nvim-treesitter.configs").setup({ + highlight = { enable = true, }, +}) + +require("gitsigns").setup({}) + diff --git a/config/nvim/lua/settings.lua b/config/nvim/lua/settings.lua new file mode 100644 index 0000000..6f440bb --- /dev/null +++ b/config/nvim/lua/settings.lua @@ -0,0 +1,34 @@ +vim.g.mapleader = " " + +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +--Decorative +vim.opt.termguicolors = true +vim.opt.cursorline = true +vim.opt.number = true +vim.opt.signcolumn = "yes" +vim.opt.cmdheight = 1 +vim.cmd.colorscheme "catppuccin" + +--Undo +vim.opt.undofile = true + +--Indents +vim.opt.smartindent = true +vim.opt.autoindent = true +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.softtabstop = 4 +vim.opt.expandtab = true + +--Clipboard +vim.opt.clipboard = "unnamedplus" + +--Misc +vim.opt.hidden = true +vim.opt.smartcase = true +vim.opt.splitbelow = true +vim.opt.splitright = true +vim.opt.colorcolumn = "80" +vim.opt.updatetime = 250 |