From a1ef89b3c9f2fa7c9e1a79f23dd2d0e9cd15b3da Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Sun, 24 Mar 2024 22:45:52 +0100 Subject: [PATCH] Added LSP and cmp --- lazy-lock.json | 7 +- lua/barink/init.lua | 209 ++++++++++++++++++++++++++++++-------------- 2 files changed, 148 insertions(+), 68 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 550f84a..54ce946 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,8 +1,13 @@ { "LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "fidget.nvim": { "branch": "main", "commit": "933db4596e4bab1b09b6d48a10e21819e4cc458f" }, "lazy.nvim": { "branch": "main", "commit": "af6afefbb46ab29a8a1db69536b04290a9403876" }, - "lsp-zero.nvim": { "branch": "v3.x", "commit": "ac86dd9f874a6fc0c4e4785da34c6e9bf13a2192" }, + "mason-lspconfig": { "branch": "main", "commit": "9dfcf2036c223920826140f0151d929a43f9eceb" }, + "mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" }, "nvim-cmp": { "branch": "main", "commit": "97dc716fc914c46577a4f254035ebef1aa72558a" }, "nvim-lspconfig": { "branch": "master", "commit": "6e5c78ebc9936ca74add66bda22c566f951b6ee5" }, "nvim-treesitter": { "branch": "master", "commit": "5e4f959d5979730ddb2ee9ae60f5133081502b23" }, diff --git a/lua/barink/init.lua b/lua/barink/init.lua index f2cc3bf..50cb88b 100644 --- a/lua/barink/init.lua +++ b/lua/barink/init.lua @@ -1,74 +1,150 @@ local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ - { - "folke/tokyonight.nvim", - lazy = false, - priority = 1000, - opts = {}, - config = function () + { + "folke/tokyonight.nvim", + lazy = false, + priority = 1000, + opts = {}, + config = function() require("tokyonight").setup({ - style="night", - light_style="day", - transparent=true, - terminal_colors=true, - dim_inactive=false, - lualine_bold=false, + style = "night", + light_style = "day", + transparent = true, + terminal_colors = true, + dim_inactive = false, + lualine_bold = false, }) - -- make transparent BG --- vim.api.nvim_set_hl(0, "Normal", {bg = "none"}) --- vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none"}) - - vim.cmd[[colorscheme tokyonight]] + vim.cmd [[colorscheme tokyonight]] end - }, - { - "nvim-telescope/telescope.nvim", - dependencies = { 'nvim-lua/plenary.nvim'} - }, - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - config = function () - local configs = require("nvim-treesitter.configs") + }, + { + "nvim-telescope/telescope.nvim", + dependencies = { 'nvim-lua/plenary.nvim' } + }, + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + local configs = require("nvim-treesitter.configs") - configs.setup({ - ensure_installed = {"c", "lua", "vim", "vimdoc", "bash"}, - sync_install = false, - highlight = { enable = true }, - indent = { enable = true }, - }) - end - }, - {"mbbill/undotree"}, - { 'VonHeikemen/lsp-zero.nvim', branch='v3.x'}, - {'neovim/nvim-lspconfig'}, - {'hrsh7th/cmp-nvim-lsp'}, - {'hrsh7th/nvim-cmp'}, - {'L3MON4D3/LuaSnip'}, - {'tpope/vim-fugitive'}, + configs.setup({ + ensure_installed = { "c", "lua", "vim", "vimdoc", "bash" }, + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + }) + end + }, + { "mbbill/undotree" }, + { + 'neovim/nvim-lspconfig', + dependencies = { + "williamboman/mason-lspconfig", + "williamboman/mason.nvim", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/nvim-cmp", + 'L3MON4D3/LuaSnip', + }, + config = function() + require("mason").setup() + require("mason-lspconfig").setup({ + ensure_installed = { "lua_ls", "bashls", "rust_analyzer" } + }) + local cmp = require('cmp') + cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + 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 = 'luasnip' }, + }, { + { name = 'buffer' }, + }) + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git). + }, { + { 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' } + }), + matching = { disallow_symbol_nonprefix_matching = false } + }) + + -- Set up lspconfig. + local capabilities = require('cmp_nvim_lsp').default_capabilities() + + require('lspconfig')['asm_lsp'].setup({ + capabilities = capabilities + }) + + local lsp = require("lspconfig") + lsp.lua_ls.setup({ + capabilities = require('cmp_nvim_lsp').default_capabilities(), + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } + }) + end + }, + { 'tpope/vim-fugitive' }, + { + "j-hui/fidget.nvim", + config = function() + require('fidget').setup({}) + end + } }, {}) -local lsp_zero = require('lsp-zero') - -lsp_zero.on_attach(function(client, bufnr) - -- see :help lsp-zero-keybindings - -- to learn the available actions - lsp_zero.default_keymaps({buffer = bufnr}) -end) - -- Set basic vim options vim.opt.guicursor = "" @@ -92,8 +168,8 @@ vim.opt.termguicolors = true vim.opt.scrolloff = 8 --- Keymaps -vim.g.mapleader = " " +-- Keymaps +vim.g.mapleader = " " local builtin = require('telescope.builtin') @@ -104,13 +180,12 @@ vim.keymap.set('n', '', vim.cmd.UndotreeToggle) vim.keymap.set('n', 'p', [["_dP]]) vim.keymap.set('n', 'f', vim.lsp.buf.format) - -osname = vim.loop.os_uname().sysname -if osname == "Windows_NT" then +vim.keymap.set('n', 'm', ":Mason") +local osname = vim.loop.os_uname().sysname +if osname == "Windows_NT" then print("Windows Detected!!") - vim.keymap.set('n', 'x', function() print("sorry this is windows!")end) -elseif osname == "Linux" then + vim.keymap.set('n', 'x', function() print("sorry this is windows!") end) +elseif osname == "Linux" then -- Linux only!! - vim.keymap.set('n', 'x', "!chmod +x %", { silent =true }) + vim.keymap.set('n', 'x', "!chmod +x %", { silent = true }) end -