From 5aacff03453e505ee6e5181e3247676239570dbc Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Fri, 1 Mar 2024 18:05:15 +0530 Subject: plugins/lsp: init --- lazy-lock.json | 18 ++++++-- lua/plugins/init.lua | 78 ++++++++++++++++++++++++++++++--- lua/plugins/maps.lua | 1 - lua/plugins/opts/cmp.lua | 96 +++++++++++++++++++++++++++++++++++++++++ lua/plugins/opts/lspconfig.lua | 35 +++++++++++++++ lua/plugins/opts/lualine.lua | 4 +- lua/plugins/opts/misc.lua | 11 +++++ lua/plugins/opts/treesitter.lua | 2 +- 8 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 lua/plugins/opts/cmp.lua create mode 100644 lua/plugins/opts/lspconfig.lua diff --git a/lazy-lock.json b/lazy-lock.json index f2f937b..84d1ce5 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,11 +1,21 @@ { "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "f3b3d3446bcbfa62d638b1903ff00a78b2b730a1" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" }, "gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" }, - "lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" }, + "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "009ace7a0ca360d9299ff7eb33364b5c16556561" }, "lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" }, - "nvim-treesitter": { "branch": "master", "commit": "62b0bb4f24ad09f535efe44cc9d088f90dcd2498" }, - "nvim-web-devicons": { "branch": "master", "commit": "0bb67ef952ea3eb7b1bac9c011281471d99a27bc" }, - "tokyodark.nvim": { "branch": "master", "commit": "fe5847e379b3d1c52896fa69ff8faf20cde483cc" }, + "nvim-autopairs": { "branch": "master", "commit": "c6139ca0d5ad7af129ea6c89cb4c56093f2c034a" }, + "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, + "nvim-lspconfig": { "branch": "master", "commit": "9553725789be682ecd945a527ec552e489ea8534" }, + "nvim-treesitter": { "branch": "master", "commit": "c2a265156d5799adbd9f9e7d5385735fa5d21776" }, + "tokyonight.nvim": { "branch": "main", "commit": "610179f7f12db3d08540b6cc61434db2eaecbcff" }, "vim-fugitive": { "branch": "master", "commit": "2e88f14a585c014691904ba8fe39e6ea851c9422" }, "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" } } \ No newline at end of file diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 59da877..07d7639 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -10,24 +10,25 @@ require("lazy").setup({ { "nvim-lualine/lualine.nvim", - dependencies = { 'nvim-tree/nvim-web-devicons' }, opts = require "plugins.opts.lualine", }, { - "tiagovla/tokyodark.nvim", + "folke/tokyonight.nvim", lazy = false, + priority = 1000, - opts = { transparent_background = true }, + opts = { transparent = true, }, config = function(_, opts) - require("tokyodark").setup(opts) - vim.cmd.colorscheme "tokyodark" + require("tokyonight").setup(opts) + vim.cmd.colorscheme "tokyonight-night" end, }, { - "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", event = { "BufReadPost", "BufNewFile" }, cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, @@ -37,4 +38,69 @@ require("lazy").setup({ end, }, + { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + lazy = true, + + config = false, + init = function() + -- Disable automatic setup, we are doing it manually + vim.g.lsp_zero_extend_cmp = 0 + vim.g.lsp_zero_extend_lspconfig = 0 + end, + }, + + { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + { + 'L3MON4D3/LuaSnip', + dependencies = "rafamadriz/friendly-snippets", + + config = function(_, opts) + require("plugins.opts.misc").luasnip(opts) + end, + }, + { + "windwp/nvim-autopairs", + + opts = { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, + }, + config = function(_, opts) + require("nvim-autopairs").setup(opts) + + -- setup cmp for autopairs + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }, + -- cmp sources plugins + { + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + }, + }, + + opts = function() + return require "plugins.opts.cmp" + end, + + }, + + { + 'neovim/nvim-lspconfig', + cmd = 'LspInfo', + event = { 'BufReadPre', 'BufNewFile' }, + + config = function() + require "plugins.opts.lspconfig" + end, + }, }) diff --git a/lua/plugins/maps.lua b/lua/plugins/maps.lua index ab10383..7c5f29b 100644 --- a/lua/plugins/maps.lua +++ b/lua/plugins/maps.lua @@ -4,7 +4,6 @@ local maps = {} maps.gitsigns = { n = { ["gb"] = { - -- TODO: remov fun function() package.loaded.gitsigns.blame_line() end, diff --git a/lua/plugins/opts/cmp.lua b/lua/plugins/opts/cmp.lua new file mode 100644 index 0000000..c423a31 --- /dev/null +++ b/lua/plugins/opts/cmp.lua @@ -0,0 +1,96 @@ +local cmp = require "cmp" +local lspzero_cmp_act = require('lsp-zero').cmp_action() + +local function border(hl_name) + return { + { "╭", hl_name }, + { "─", hl_name }, + { "╮", hl_name }, + { "│", hl_name }, + { "╯", hl_name }, + { "─", hl_name }, + { "╰", hl_name }, + { "│", hl_name }, + } +end + +local options = { + completion = { + completeopt = "menu,menuone", + }, + + window = { + completion = { + border = border "CmpBorder", + winhighlight = "Normal:CmpPmenu,CursorLine:CmpSel,CursorLine:PmenuSel", + scrollbar = false, + }, + documentation = { + border = border "CmpDocBorder", + winhighlight = "Normal:CmpDoc", + }, + }, + + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + + formatting = { + fields = { "abbr", "kind", "menu" }, + + format = function(_, item) + local icons = { + Text = " ", + Method = " ", + Function = " ", + Constructor = " ", + Field = " ", + Variable = " ", + Class = " ", + Interface = " ", + Module = " ", + Property = " ", + Unit = " ", + Value = " ", + Enum = " ", + Keyword = " ", + Snippet = " ", + Color = " ", + File = " ", + Reference = " ", + Folder = " ", + EnumMember = " ", + Constant = " ", + Struct = " ", + Event = " ", + Operator = " ", + TypeParameter = " ", + } + + local icon = icons[item.kind] or "" + item.kind = string.format(" %s %s", icon, item.kind) + + return item + end, + }, + + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = lspzero_cmp_act.luasnip_jump_forward(), + [''] = lspzero_cmp_act.luasnip_jump_backward(), + }), + + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "path" }, + }, +} + +return options diff --git a/lua/plugins/opts/lspconfig.lua b/lua/plugins/opts/lspconfig.lua new file mode 100644 index 0000000..798e6c8 --- /dev/null +++ b/lua/plugins/opts/lspconfig.lua @@ -0,0 +1,35 @@ +local lspconfig = require "lspconfig" +local lsp_zero = require "lsp-zero" + +lsp_zero.extend_lspconfig() +lsp_zero.set_sign_icons({ + error = "󰅚 ", + warn = "󰀪 ", + info = "󰋽 ", + hint = "󰌶 " +}) +lsp_zero.on_attach(function(_, bufnr) + lsp_zero.default_keymaps({buffer = bufnr}) +end) + +lspconfig.lua_ls.setup(lsp_zero.nvim_lua_ls({ + settings = { + Lua = { + diagnostics = { + globals = { 'mp' } -- mpv global + } + } + } +})) + +lspconfig.ccls.setup { + init_options = { + cache = { + directory = vim.fn.stdpath('cache') .. '/ccls' + } + } +} + +lspconfig.bashls.setup {} +lspconfig.nil_ls.setup {} +lspconfig.pyright.setup {} diff --git a/lua/plugins/opts/lualine.lua b/lua/plugins/opts/lualine.lua index e72c632..456fa37 100644 --- a/lua/plugins/opts/lualine.lua +++ b/lua/plugins/opts/lualine.lua @@ -4,8 +4,8 @@ return { lualine_b = { "branch", "diff" }, lualine_c = {{ "buffers", mode = 2 }}, - lualine_x = {}, - lualine_y = { "diagnostics", "progress" }, + lualine_x = { "diagnostics" }, + lualine_y = { "progress" }, lualine_z = {}, }, diff --git a/lua/plugins/opts/misc.lua b/lua/plugins/opts/misc.lua index 952dc4f..e228023 100644 --- a/lua/plugins/opts/misc.lua +++ b/lua/plugins/opts/misc.lua @@ -16,4 +16,15 @@ M.gitsigns = { end, } +M.luasnip = function (opts) + require("luasnip").config.set_config(opts) + + -- vscode format + require("luasnip.loaders.from_vscode").lazy_load() + -- snipmate format + require("luasnip.loaders.from_snipmate").lazy_load() + -- lua format + require("luasnip.loaders.from_lua").lazy_load() +end + return M diff --git a/lua/plugins/opts/treesitter.lua b/lua/plugins/opts/treesitter.lua index c9f9a59..fbc2a71 100644 --- a/lua/plugins/opts/treesitter.lua +++ b/lua/plugins/opts/treesitter.lua @@ -1,5 +1,5 @@ return { - ensure_installed = { "lua", "c", "bash"}, + ensure_installed = { "lua", "c", "bash", "nix", "python", "markdown" }, sync_install = false, indent = { enable = true }, -- cgit v1.2.3