From 16ee7441f40a71872f8fb6a89da470564e76ce04 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Sat, 15 Jul 2023 15:49:24 +0530 Subject: nvim: Adding autocompletions- nvim-cmp+luasnip+nvim-lsp+cmdline+path --- .config/nvim/lua/justsaumit/lsp-config.lua | 76 +++++++++++++++++------------- 1 file changed, 44 insertions(+), 32 deletions(-) (limited to '.config/nvim/lua/justsaumit/lsp-config.lua') diff --git a/.config/nvim/lua/justsaumit/lsp-config.lua b/.config/nvim/lua/justsaumit/lsp-config.lua index f4db75f..3e1db1f 100644 --- a/.config/nvim/lua/justsaumit/lsp-config.lua +++ b/.config/nvim/lua/justsaumit/lsp-config.lua @@ -1,83 +1,95 @@ -local on_attach = function(client, bufnr) - local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) - end - local function buf_set_option(...) - vim.api.nvim_buf_set_option(bufnr, ...) - end +local lspconfig = require("lspconfig") +local on_attach = function(_, bufnr) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + local function buf_set_option(...) + vim.api.nvim_buf_set_option(bufnr, ...) + end - buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") + buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") - local opts = { noremap = true, silent = true } - - buf_set_keymap("n", "gd", ":lua vim.lsp.buf.definition()", opts) --> jumps to the definition of the symbol under the cursor - buf_set_keymap("n", "lh", ":lua vim.lsp.buf.hover()", opts) --> information about the symbol under the cursos in a floating window - buf_set_keymap("n", "gi", ":lua vim.lsp.buf.implementation()", opts) --> lists all the implementations for the symbol under the cursor in the quickfix window - buf_set_keymap("n", "rn", ":lua vim.lsp.util.rename()", opts) --> renaname old_fname to new_fname - buf_set_keymap("n", "ca", ":lua vim.lsp.buf.code_action()", opts) --> selects a code action available at the current cursor position - buf_set_keymap("n", "gr", ":lua vim.lsp.buf.references()", opts) --> lists all the references to the symbl under the cursor in the quickfix window - buf_set_keymap("n", "ld", ":lua vim.diagnostic.open_float()", opts) - buf_set_keymap("n", "[d", ":lua vim.diagnostic.goto_prev()", opts) - buf_set_keymap("n", "]d", ":lua vim.diagnostic.goto_next()", opts) - buf_set_keymap("n", "lq", ":lua vim.diagnostic.setloclist()", opts) - buf_set_keymap("n", "lf", ":lua vim.lsp.buf.formatting()", opts) --> formats the current buffer + local opts = { noremap = true, silent = true } + buf_set_keymap("n", "K", ":lua vim.lsp.buf.hover()", opts) --> information about the symbol under the cursors in a floating window + buf_set_keymap("n", "rn", ":lua vim.lsp.util.rename()", opts) --> rename old_fname to new_fname + buf_set_keymap("n", "ca", ":lua vim.lsp.buf.code_action()", opts) --> selects a code action available at the current cursor position + buf_set_keymap("n", "gd", ":lua vim.lsp.buf.definition()", opts) --> jumps to the definition of the symbol under the cursor + buf_set_keymap("n", "gi", ":lua vim.lsp.buf.implementation()", opts) --> lists all the implementations for the symbol under the cursor in the quickfix window + buf_set_keymap("n", "gr", ":lua vim.lsp.buf.references()", opts) --> lists all the references to the symbl under the cursor in the quickfix window + buf_set_keymap("n", "ld", ":lua vim.diagnostic.open_float()", opts) + buf_set_keymap("n", "[d", ":lua vim.diagnostic.goto_prev()", opts) + buf_set_keymap("n", "]d", ":lua vim.diagnostic.goto_next()", opts) + buf_set_keymap("n", "lq", ":lua vim.diagnostic.setloclist()", opts) + buf_set_keymap("n", "lf", ":lua vim.lsp.buf.formatting()", opts) --> formats the current buffer end ---@diagnostic disable-next-line: undefined-global local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) -require("lspconfig")["clangd"].setup({ +--lspconfig x cmp_nvim_lsp +-- Set up lspconfig. +-- require("lspconfig")["clangd"].setup({ +lspconfig.clangd.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["pyright"].setup({ +lspconfig.pyright.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["bashls"].setup({ +lspconfig.bashls.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["cssls"].setup({ +lspconfig.cssls.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["gopls"].setup({ +lspconfig.gopls.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["html"].setup({ +lspconfig.html.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["lua_ls"].setup({ +lspconfig.lua_ls.setup({ on_attach = on_attach, capabilities = capabilities, + settings = { + Lua = { + runtime = { version = 'LuaJIT',}, + diagnostics = { + globals = {'vim','require',},}, + workspace = { library = vim.api.nvim_get_runtime_file("", true),}, + telemetry = {enable = false,}, + }, + }, }) -require("lspconfig")["marksman"].setup({ +lspconfig.marksman.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["rust_analyzer"].setup({ +lspconfig.rust_analyzer.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["tsserver"].setup({ +lspconfig.tsserver.setup({ on_attach = on_attach, capabilities = capabilities, }) -require("lspconfig")["yamlls"].setup({ +lspconfig.yamlls.setup({ on_attach = on_attach, capabilities = capabilities, }) -- cgit v1.2.3