From 4e70e2bac0d6eead8508b4625cfb8967771bd5f2 Mon Sep 17 00:00:00 2001 From: Timmy Keller Date: Mon, 2 Sep 2024 08:42:34 -0500 Subject: nvim vimscript to lua --- nvim/lua/user/cmp.lua | 129 ----------------------------------------- nvim/lua/user/lsp/handlers.lua | 104 --------------------------------- nvim/lua/user/lsp/init.lua | 7 --- nvim/lua/user/lsp/mason.lua | 47 --------------- nvim/lua/user/lsp/null-ls.lua | 19 ------ 5 files changed, 306 deletions(-) delete mode 100644 nvim/lua/user/cmp.lua delete mode 100644 nvim/lua/user/lsp/handlers.lua delete mode 100644 nvim/lua/user/lsp/init.lua delete mode 100644 nvim/lua/user/lsp/mason.lua delete mode 100644 nvim/lua/user/lsp/null-ls.lua (limited to 'nvim/lua/user') diff --git a/nvim/lua/user/cmp.lua b/nvim/lua/user/cmp.lua deleted file mode 100644 index c83ddce..0000000 --- a/nvim/lua/user/cmp.lua +++ /dev/null @@ -1,129 +0,0 @@ -local cmp_status_ok, cmp = pcall(require, "cmp") -if not cmp_status_ok then - return -end - -local snip_status_ok, luasnip = pcall(require, "luasnip") -if not snip_status_ok then - return -end - -require("luasnip/loaders/from_vscode").lazy_load() - -local check_backspace = function() - local col = vim.fn.col "." - 1 - return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" -end - ---   פּ ﯟ   some other good icons -local kind_icons = { - Text = "", - Method = "m", - Function = "", - Constructor = "", - Field = "", - Variable = "", - Class = "", - Interface = "", - Module = "", - Property = "", - Unit = "", - Value = "", - Enum = "", - Keyword = "", - Snippet = "", - Color = "", - File = "", - Reference = "", - Folder = "", - EnumMember = "", - Constant = "", - Struct = "", - Event = "", - Operator = "", - TypeParameter = "", -} --- find more here: https://www.nerdfonts.com/cheat-sheet - -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) -- For `luasnip` users. - end, - }, - mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. - [""] = cmp.mapping { - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }, - -- Accept currently selected item. If none selected, `select` first item. - -- Set `select` to `false` to only confirm explicitly selected items. - [""] = cmp.mapping.confirm { select = true }, - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expandable() then - luasnip.expand() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif check_backspace() then - fallback() - else - fallback() - end - end, { - "i", - "s", - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { - "i", - "s", - }), - }, - formatting = { - fields = { "kind", "abbr", "menu" }, - format = function(entry, vim_item) - -- Kind icons - vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) - -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind - vim_item.menu = ({ - luasnip = "[Snippet]", - buffer = "[Buffer]", - path = "[Path]", - })[entry.source.name] - return vim_item - end, - }, - sources = { - { name = "nvim_lsp" }, - { name = "nvim_lua" }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - }, - confirm_opts = { - behavior = cmp.ConfirmBehavior.Replace, - select = false, - }, - window = { - documentation = cmp.config.window.bordered(), - }, - experimental = { - ghost_text = false, - native_menu = false, - }, -} diff --git a/nvim/lua/user/lsp/handlers.lua b/nvim/lua/user/lsp/handlers.lua deleted file mode 100644 index 8de0abd..0000000 --- a/nvim/lua/user/lsp/handlers.lua +++ /dev/null @@ -1,104 +0,0 @@ -local M = {} - --- TODO: backfill this to template -M.setup = function() - local signs = { - { name = "DiagnosticSignError", text = "" }, - { name = "DiagnosticSignWarn", text = "" }, - { name = "DiagnosticSignHint", text = "" }, - { name = "DiagnosticSignInfo", text = "" }, - } - - for _, sign in ipairs(signs) do - vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) - end - - local config = { - -- disable virtual text - virtual_text = false, - -- show signs - signs = { - active = signs, - }, - update_in_insert = true, - underline = true, - severity_sort = true, - float = { - focusable = false, - style = "minimal", - border = "rounded", - source = "always", - header = "", - prefix = "", - }, - } - - vim.diagnostic.config(config) - - 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", - }) -end - -local function lsp_highlight_document(client) - -- Set autocommands conditional on server_capabilities - if client.server_capabilities.documentHighlight then - vim.api.nvim_exec( - [[ - augroup lsp_document_highlight - autocmd! * - autocmd CursorHold lua vim.lsp.buf.document_highlight() - autocmd CursorMoved lua vim.lsp.buf.clear_references() - augroup END - ]], - false - ) - end -end - -local function lsp_keymaps(bufnr) - local opts = { noremap = true, silent = true } - vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "f", "lua vim.diagnostic.open_float()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", 'lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) - vim.api.nvim_buf_set_keymap( - bufnr, - "n", - "gl", - 'lua vim.diagnostic.open_float()', - opts - ) - vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", 'lua vim.diagnostic.goto_next({ border = "rounded" })', opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "q", "lua vim.diagnostic.setloclist()", opts) - vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] -end - -M.on_attach = function(client, bufnr) - if client.name == "tsserver" then - client.server_capabilities.documentFormattingProvider = false - end - lsp_keymaps(bufnr) - lsp_highlight_document(client) -end - -local capabilities = vim.lsp.protocol.make_client_capabilities() - -local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") -if not status_ok then - return -end - -M.capabilities = cmp_nvim_lsp.default_capabilities(capabilities) - -return M diff --git a/nvim/lua/user/lsp/init.lua b/nvim/lua/user/lsp/init.lua deleted file mode 100644 index 8a84467..0000000 --- a/nvim/lua/user/lsp/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -local status_ok, _ = pcall(require, "lspconfig") -if not status_ok then - return -end - -require "user.lsp.mason" -require("user.lsp.handlers").setup() diff --git a/nvim/lua/user/lsp/mason.lua b/nvim/lua/user/lsp/mason.lua deleted file mode 100644 index a2e5384..0000000 --- a/nvim/lua/user/lsp/mason.lua +++ /dev/null @@ -1,47 +0,0 @@ -local servers = { - "lua_ls", - "pyright", - "jsonls", -} - -local settings = { - ui = { - border = "none", - icons = { - package_installed = "◍", - package_pending = "◍", - package_uninstalled = "◍", - }, - }, - log_level = vim.log.levels.INFO, - max_concurrent_installers = 4, -} - -require("mason").setup(settings) -require("mason-lspconfig").setup({ - ensure_installed = servers, - automatic_installation = true, -}) - -local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig") -if not lspconfig_status_ok then - return -end - -local opts = {} - -for _, server in pairs(servers) do - opts = { - on_attach = require("user.lsp.handlers").on_attach, - capabilities = require("user.lsp.handlers").capabilities, - } - - server = vim.split(server, "@")[1] - - local require_ok, conf_opts = pcall(require, "user.lsp.settings." .. server) - if require_ok then - opts = vim.tbl_deep_extend("force", conf_opts, opts) - end - - lspconfig[server].setup(opts) -end diff --git a/nvim/lua/user/lsp/null-ls.lua b/nvim/lua/user/lsp/null-ls.lua deleted file mode 100644 index 874e19c..0000000 --- a/nvim/lua/user/lsp/null-ls.lua +++ /dev/null @@ -1,19 +0,0 @@ -local null_ls_status_ok, null_ls = pcall(require, "null-ls") -if not null_ls_status_ok then - return -end - --- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting -local formatting = null_ls.builtins.formatting --- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics -local diagnostics = null_ls.builtins.diagnostics - -null_ls.setup({ - debug = false, - sources = { - formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }), - formatting.black.with({ extra_args = { "--fast" } }), - formatting.stylua, - -- diagnostics.flake8 - }, -}) -- cgit v1.2.3