diff --git a/README.md b/README.md index 1416441..2dc7e5a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # My curent Neovim config -Inspired by [ThePrimeagen](https://github.com/ThePrimeagen/init.lua) +Inspired by [ThePrimeagen](https://github.com/ThePrimeagen/init.lua) and [Josean](https://github.com/josean-dev/dev-environment-files) Make sure to run `:PackerSync` so it grabs all plugins. You can also run `nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'` diff --git a/after/plugin/autopairs.lua b/after/plugin/autopairs.lua new file mode 100644 index 0000000..363310b --- /dev/null +++ b/after/plugin/autopairs.lua @@ -0,0 +1,13 @@ +local autopairs_setup, autopairs = pcall(require, "nvim-autopairs") +if not autopairs_setup then + return +end + +autopairs.setup { + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, +} diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua.old similarity index 85% rename from after/plugin/lsp.lua rename to after/plugin/lsp.lua.old index 4c4be2f..6a3cbc5 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua.old @@ -15,22 +15,6 @@ lsp.on_attach(function(client, bufnr) vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) end) -local cmp = require('cmp') -local cmp_select = {behavior = cmp.SelectBehavior.Select} -local cmp_mappings = lsp.defaults.cmp_mappings({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping.complete(), -}) - -cmp_mappings[''] = nil -cmp_mappings[''] = nil - -lsp.setup_nvim_cmp({ - mapping = cmp_mappings -}) - lsp.ensure_installed({ 'lua_ls', 'tsserver', @@ -40,3 +24,18 @@ lspconfig.lua_ls.setup(lsp.nvim_lua_ls()) lspconfig.tsserver.setup({}) lsp.setup() +local cmp = require('cmp') +local cmp_select = {behavior = cmp.SelectBehavior.Select} +local cmp_mappings = lsp.defaults.cmp_mappings({ + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping.complete(), +}) + +lsp.setup_nvim_cmp({ + mapping = cmp_mappings +}) +cmp_mappings[''] = nil +cmp_mappings[''] = nil + diff --git a/after/plugin/lsp/lspconfig.lua b/after/plugin/lsp/lspconfig.lua new file mode 100644 index 0000000..fe63f94 --- /dev/null +++ b/after/plugin/lsp/lspconfig.lua @@ -0,0 +1,58 @@ +local lspconfig_status, lspconfig = pcall(require, "lspconfig") +if not lspconfig_status then + return +end + +local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not cmp_nvim_lsp_status then + return +end + +local on_attach = function(client, bufnr) + local opts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) +end + +local capabilities = cmp_nvim_lsp.default_capabilities() + +local signs = { Error = " ", Warn = " ", Hint = "ﴞ ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end + +lspconfig["lua_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + }, + }, +}) + +lspconfig["html"].setup({ + capabilities = capabilities, + on_attach = on_attach, +}) + +lspconfig["tsserver"].setup({ + capabilities = capabilities, + on_attach = on_attach, +}) + +lspconfig["cssls"].setup({ + capabilities = capabilities, + on_attach = on_attach, +}) diff --git a/after/plugin/lsp/mason.lua b/after/plugin/lsp/mason.lua new file mode 100644 index 0000000..09afc6d --- /dev/null +++ b/after/plugin/lsp/mason.lua @@ -0,0 +1,35 @@ +local mason_status, mason = pcall(require, "mason") +if not mason_status then + return +end + +local mason_lspconfig_status, mason_lspconfig = pcall(require, "mason-lspconfig") +if not mason_lspconfig_status then + return +end + +local mason_null_ls_status, mason_null_ls = pcall(require, "mason-null-ls") +if not mason_null_ls_status then + return +end + +mason.setup() + +mason_lspconfig.setup({ + ensure_installed = { + "tsserver", + "html", + "cssls", + "lua_ls" + }, + automatic_installation = true, +}) + +mason_null_ls.setup({ + ensure_installed = { + "stylua", + "clang_format", + "eslint_d" + }, + automatic_installation = true, +}) diff --git a/after/plugin/lsp/null-ls.lua b/after/plugin/lsp/null-ls.lua new file mode 100644 index 0000000..4cdc6d6 --- /dev/null +++ b/after/plugin/lsp/null-ls.lua @@ -0,0 +1,18 @@ +local setup, null_ls = pcall(require, "null-ls") +if not setup then + return +end + +local formatting = null_ls.builtins.formatting +local diagnostics = null_ls.builtins.diagnostics + +null_ls.setup({ + sources = { + formatting.stylua, + diagnostics.eslint_d.with({ + condition = function(utils) + return utils.root_has_file(".eslintrc.js") + end, + }), + }, +}) diff --git a/after/plugin/nvim-cmp.lua b/after/plugin/nvim-cmp.lua new file mode 100644 index 0000000..28e8efe --- /dev/null +++ b/after/plugin/nvim-cmp.lua @@ -0,0 +1,47 @@ +local cmp_status, cmp = pcall(require, "cmp") +if not cmp_status then + return +end + +local luasnip_status, luasnip = pcall(require, "luasnip") +if not luasnip_status then + return +end + +local lspkind_status, lspkind = pcall(require, "lspkind") +if not lspkind_status then + return +end + +require("luasnip/loaders/from_vscode").lazy_load() + +vim.opt.completeopt = "menu,menuone,noselect" + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), -- previous suggestion + [""] = cmp.mapping.select_next_item(), -- next suggestion + [""] = cmp.mapping.complete(), -- show completion suggestions + [""] = cmp.mapping.confirm({ select = false }), + [''] = nil, + [''] = nil + }), + + sources = cmp.config.sources({ + { name = "nvim_lsp" }, -- lsp + { name = "luasnip" }, -- snippets + { name = "buffer" }, -- text within current buffer + { name = "path" }, -- file system paths + }), + formatting = { + format = lspkind.cmp_format({ + maxwidth = 50, + ellipsis_char = "...", + }), + }, +})