summaryrefslogtreecommitdiff
path: root/nvim/lua/user
diff options
context:
space:
mode:
authorTimmy Keller <tjk@tjkeller.xyz>2024-09-02 08:42:34 -0500
committerTimmy Keller <tjk@tjkeller.xyz>2024-09-02 08:42:34 -0500
commit4e70e2bac0d6eead8508b4625cfb8967771bd5f2 (patch)
tree6b651a905ceaeeca047ca4bb4cf7ca21059ead16 /nvim/lua/user
parent692b2f5f5231dddfbaab92f749ee9513e423be60 (diff)
downloaddotconfig-4e70e2bac0d6eead8508b4625cfb8967771bd5f2.tar.xz
dotconfig-4e70e2bac0d6eead8508b4625cfb8967771bd5f2.zip
nvim vimscript to lua
Diffstat (limited to 'nvim/lua/user')
-rw-r--r--nvim/lua/user/cmp.lua129
-rw-r--r--nvim/lua/user/lsp/handlers.lua104
-rw-r--r--nvim/lua/user/lsp/init.lua7
-rw-r--r--nvim/lua/user/lsp/mason.lua47
-rw-r--r--nvim/lua/user/lsp/null-ls.lua19
5 files changed, 0 insertions, 306 deletions
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 = {
- ["<C-k>"] = cmp.mapping.select_prev_item(),
- ["<C-j>"] = cmp.mapping.select_next_item(),
- ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
- ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
- ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
- ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
- ["<C-e>"] = 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.
- ["<CR>"] = cmp.mapping.confirm { select = true },
- ["<Tab>"] = 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",
- }),
- ["<S-Tab>"] = 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! * <buffer>
- autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
- autocmd CursorMoved <buffer> 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", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
- -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
- -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
- -- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>f", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts)
- vim.api.nvim_buf_set_keymap(
- bufnr,
- "n",
- "gl",
- '<cmd>lua vim.diagnostic.open_float()<CR>',
- opts
- )
- vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", 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
- },
-})