From 89de3828a1beb3a6045795d177012cb3569300f3 Mon Sep 17 00:00:00 2001 From: Warren Hood Date: Wed, 9 Nov 2022 00:44:29 +0200 Subject: [PATCH] Enable LSP servers automatically after installing, add telescope, etc --- neovim/.config/nvim/.luarc.json | 4 + neovim/.config/nvim/init.lua | 2 + .../nvim/lua/warrenhood/cmp-config.lua | 65 +++++++++++++ .../.config/nvim/lua/warrenhood/keybinds.lua | 7 +- .../nvim/lua/warrenhood/mason-config.lua | 42 ++++++++ .../.config/nvim/lua/warrenhood/plugins.lua | 95 ++----------------- .../.config/nvim/lua/warrenhood/settings.lua | 3 + 7 files changed, 129 insertions(+), 89 deletions(-) create mode 100644 neovim/.config/nvim/.luarc.json create mode 100644 neovim/.config/nvim/lua/warrenhood/cmp-config.lua create mode 100644 neovim/.config/nvim/lua/warrenhood/mason-config.lua diff --git a/neovim/.config/nvim/.luarc.json b/neovim/.config/nvim/.luarc.json new file mode 100644 index 0000000..e1b9d70 --- /dev/null +++ b/neovim/.config/nvim/.luarc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", + "Lua.workspace.checkThirdParty": false +} \ No newline at end of file diff --git a/neovim/.config/nvim/init.lua b/neovim/.config/nvim/init.lua index 6ab7bd4..fca6853 100644 --- a/neovim/.config/nvim/init.lua +++ b/neovim/.config/nvim/init.lua @@ -1,3 +1,5 @@ require("warrenhood.settings") require("warrenhood.keybinds") require("warrenhood.plugins") +require("warrenhood.mason-config") +require("warrenhood.cmp-config") diff --git a/neovim/.config/nvim/lua/warrenhood/cmp-config.lua b/neovim/.config/nvim/lua/warrenhood/cmp-config.lua new file mode 100644 index 0000000..e7e3efc --- /dev/null +++ b/neovim/.config/nvim/lua/warrenhood/cmp-config.lua @@ -0,0 +1,65 @@ +-- Setup nvim-cmp +local cmp = require("cmp") + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, + vim.lsp.buf.format, + }, + window = { + + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [""] = 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 = "vsnip" }, -- For vsnip users. + { name = "treesitter" }, + }, { + { name = "buffer" }, + }), +}) + +-- Set configuration for specific filetype. +cmp.setup.filetype("gitcommit", { + sources = cmp.config.sources({ + { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = "buffer" }, + }), +}) + +-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline({ "/", "?" }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, +}) + +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }, { + { name = "stylua" }, + }), +}) + diff --git a/neovim/.config/nvim/lua/warrenhood/keybinds.lua b/neovim/.config/nvim/lua/warrenhood/keybinds.lua index 9ceb6df..99a6cb3 100644 --- a/neovim/.config/nvim/lua/warrenhood/keybinds.lua +++ b/neovim/.config/nvim/lua/warrenhood/keybinds.lua @@ -11,4 +11,9 @@ map('i', '', ':wq') map('n', '', ':w') map('i', '', ':w') - +-- Telescope +local builtin = require('telescope.builtin') +map('n', 'ff', builtin.find_files) +map('n', 'fg', builtin.live_grep) +map('n', 'fb', builtin.buffers) +map('n', 'fh', builtin.help_tags) diff --git a/neovim/.config/nvim/lua/warrenhood/mason-config.lua b/neovim/.config/nvim/lua/warrenhood/mason-config.lua new file mode 100644 index 0000000..6753819 --- /dev/null +++ b/neovim/.config/nvim/lua/warrenhood/mason-config.lua @@ -0,0 +1,42 @@ +-- Setup mason and language servers +require("mason").setup() + + +require("mason-lspconfig").setup({ + ensure_installed = { "sumneko_lua", "rust_analyzer", "pyright" } +}) + + +local lspconfig = require('lspconfig') +require("mason-lspconfig").setup_handlers({ + -- default handler + function(server_name) -- default handler (optional) + require("lspconfig")[server_name].setup {} + end, + -- Overrides + ["sumneko_lua"] = function() + lspconfig.sumneko_lua.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + } + end, +}) + diff --git a/neovim/.config/nvim/lua/warrenhood/plugins.lua b/neovim/.config/nvim/lua/warrenhood/plugins.lua index 060abfb..f2400b3 100644 --- a/neovim/.config/nvim/lua/warrenhood/plugins.lua +++ b/neovim/.config/nvim/lua/warrenhood/plugins.lua @@ -33,99 +33,18 @@ require("packer").startup(function() use("hrsh7th/cmp-vsnip") use("hrsh7th/vim-vsnip") + -- Treesitter use("nvim-treesitter/nvim-treesitter") - -- Auto format - use("sbdchd/neoformat") + + -- Telescope + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.0', + requires = { { 'nvim-lua/plenary.nvim' } } + } -- Automatically set up configuration after cloning packer.nvim if packer_bootstrap then require("packer").sync() end end) - --- Setup mason -require("mason").setup() -require("mason-lspconfig").setup() - - - - --- Setup nvim-cmp -local cmp = require("cmp") - -cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - end, - vim.lsp.buf.format, - }, - window = { - - -- completion = cmp.config.window.bordered(), - -- documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [""] = 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 = "vsnip" }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, { - { name = "buffer" }, - }), -}) - --- Set configuration for specific filetype. -cmp.setup.filetype("gitcommit", { - sources = cmp.config.sources({ - { name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { name = "buffer" }, - }), -}) - --- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline({ "/", "?" }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer" }, - }, -}) - --- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "path" }, - }, { - { name = "cmdline" }, - }, { - { name = "stylua" }, - }), -}) - --- Set up lspconfig. -local capabilities = require("cmp_nvim_lsp").default_capabilities() --- Replace with each lsp server you've enabled. ---for lsp_server_name,v in pairs(require('lspconfig')) do --- require('lspconfig')[lsp_server_name].setup { --- capabilities = capabilities --- } --- end --- require('lspconfig')['stylua'].setup { --- capabilities = capabilities --- } diff --git a/neovim/.config/nvim/lua/warrenhood/settings.lua b/neovim/.config/nvim/lua/warrenhood/settings.lua index e3b7d7c..c7902e2 100644 --- a/neovim/.config/nvim/lua/warrenhood/settings.lua +++ b/neovim/.config/nvim/lua/warrenhood/settings.lua @@ -18,3 +18,6 @@ o.smartcase = true -- Enable mouse o.mouse = 'a' + +-- Use space for leader key +g.mapleader = " "