From cfce3cf614bfd31bd7c33ed7f15e72644a208c78 Mon Sep 17 00:00:00 2001 From: mintycube <90507714+mintycube@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:07:37 +0500 Subject: [PATCH] add cpp custom snippet and tone down diagnostics --- .config/nvim/lua/plugins/lsp.lua | 358 +++++++++++++------------ .config/nvim/lua/plugins/ui.lua | 18 +- .config/nvim/lua/snippets/cpp.json | 14 + .config/nvim/lua/snippets/package.json | 4 + 4 files changed, 216 insertions(+), 178 deletions(-) create mode 100644 .config/nvim/lua/snippets/cpp.json diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index 6428764..c351d77 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -1,186 +1,194 @@ return { - { - "VonHeikemen/lsp-zero.nvim", - branch = "v3.x", - lazy = true, - config = false, - init = function() - vim.g.lsp_zero_extend_cmp = 0 - vim.g.lsp_zero_extend_lspconfig = 0 - end, - }, + { + "VonHeikemen/lsp-zero.nvim", + branch = "v3.x", + lazy = true, + config = false, + init = function() + vim.g.lsp_zero_extend_cmp = 0 + vim.g.lsp_zero_extend_lspconfig = 0 + end, + }, - -- autocompletion - { - "hrsh7th/nvim-cmp", - event = "InsertEnter", - dependencies = { - { "L3MON4D3/LuaSnip" }, - { "hrsh7th/cmp-buffer" }, - { "https://codeberg.org/FelipeLema/cmp-async-path" }, - { "hrsh7th/cmp-nvim-lsp" }, - { "saadparwaiz1/cmp_luasnip" }, - { "rafamadriz/friendly-snippets" }, - { "onsails/lspkind.nvim" }, - { "hrsh7th/cmp-calc" }, - { "f3fora/cmp-spell" }, - { "micangl/cmp-vimtex" }, - { "Jezda1337/nvim-html-css" }, - }, - config = function() - local lsp_zero = require("lsp-zero") - lsp_zero.extend_cmp() + -- autocompletion + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + { "L3MON4D3/LuaSnip" }, + { "hrsh7th/cmp-buffer" }, + { "https://codeberg.org/FelipeLema/cmp-async-path" }, + { "hrsh7th/cmp-nvim-lsp" }, + { "saadparwaiz1/cmp_luasnip" }, + { "rafamadriz/friendly-snippets" }, + { "onsails/lspkind.nvim" }, + { "hrsh7th/cmp-calc" }, + { "f3fora/cmp-spell" }, + { "micangl/cmp-vimtex" }, + { "Jezda1337/nvim-html-css" }, + }, + config = function() + local lsp_zero = require("lsp-zero") + lsp_zero.extend_cmp() - local cmp = require("cmp") - local cmp_action = lsp_zero.cmp_action() + local cmp = require("cmp") + local cmp_action = lsp_zero.cmp_action() - -- Lazy load snippets from VSCode - require("luasnip.loaders.from_vscode").lazy_load() - require("luasnip.loaders.from_vscode").lazy_load({ paths = { "./lua/snippets" } }) + -- Lazy load snippets from VSCode + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_vscode").lazy_load({ paths = { "./lua/snippets" } }) - cmp.setup({ - sources = { - { name = "luasnip" }, - { name = "nvim_lsp" }, - { name = "buffer" }, - { name = "async_path" }, - { name = "calc" }, - { name = "html-css" }, - { name = "vimtex" }, - { - name = "spell", - option = { - keep_all_entries = false, - enable_in_context = function() - return true - end, - }, - }, - }, - preselect = "item", - completion = { - completeopt = "menu,menuone,noinsert", - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - formatting = { + cmp.setup({ + sources = { + { name = "luasnip" }, + { name = "nvim_lsp" }, + { name = "buffer" }, + { name = "async_path" }, + { name = "calc" }, + { name = "html-css" }, + { name = "vimtex" }, + { + name = "spell", + option = { + keep_all_entries = false, + enable_in_context = function() + return true + end, + }, + }, + }, + preselect = "item", + completion = { + completeopt = "menu,menuone,noinsert", + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { maxwidth = 30, - fields = { "abbr", "kind" }, - format = require("lspkind").cmp_format({ - mode = "symbol_text", - maxwidth = 30, - ellipsis_char = "", - }), - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp_action.luasnip_jump_forward(), - [""] = cmp_action.luasnip_jump_backward(), - [""] = cmp.mapping.confirm({ select = false }), - [""] = cmp_action.luasnip_supertab(), - [""] = cmp_action.luasnip_shift_supertab(), - }), - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - }) - end, - }, + fields = { "abbr", "kind" }, + format = require("lspkind").cmp_format({ + mode = "symbol_text", + maxwidth = 30, + ellipsis_char = "", + }), + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp_action.luasnip_jump_forward(), + [""] = cmp_action.luasnip_jump_backward(), + [""] = cmp.mapping.confirm({ select = false }), + [""] = cmp_action.luasnip_supertab(), + [""] = cmp_action.luasnip_shift_supertab(), + }), + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + }) + end, + }, - -- lsp - { - "neovim/nvim-lspconfig", - cmd = { "LspInfo", "LspInstall", "LspStart" }, - event = { "BufReadPre", "BufNewFile" }, - dependencies = { - { - "williamboman/mason.nvim", - config = true, - }, - { "hrsh7th/cmp-nvim-lsp" }, - { "williamboman/mason-lspconfig.nvim" }, - }, - config = function() - local lsp_zero = require("lsp-zero") - lsp_zero.extend_lspconfig() + -- lsp + { + "neovim/nvim-lspconfig", + cmd = { "LspInfo", "LspInstall", "LspStart" }, + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + { + "williamboman/mason.nvim", + config = true, + }, + { "hrsh7th/cmp-nvim-lsp" }, + { "williamboman/mason-lspconfig.nvim" }, + }, + config = function() + local lsp_zero = require("lsp-zero") + lsp_zero.extend_lspconfig() - lsp_zero.on_attach(function(client, bufnr) - lsp_zero.default_keymaps({ - buffer = bufnr, - -- exclude = { 'gl', 'K' }, - }) - end) + lsp_zero.on_attach(function(client, bufnr) + lsp_zero.default_keymaps({ + buffer = bufnr, + -- exclude = { 'gl', 'K' }, + }) + end) - lsp_zero.set_sign_icons({ - error = "", - warn = "", - hint = "󰌵", - info = "", - }) + lsp_zero.set_sign_icons({ + error = "", + warn = "", + hint = "󰌵", + info = "", + }) - require("mason-lspconfig").setup({ - ensure_installed = { - "clangd", - "ruff_lsp", - "marksman", - "html", - "cssls", - "lua_ls", - "bashls", - "texlab", - "jsonls", - "eslint", - }, - handlers = { - lsp_zero.default_setup, - lua_ls = function() - require("lspconfig").lua_ls.setup({ - settings = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - }, - }, - }) - end, - clangd = function() - require("lspconfig").clangd.setup({ - capabilities = { offsetEncoding = "utf-16" }, - -- cmd = { - -- "clangd", - -- "--background-index", - -- "--clang-tidy", - -- "--header-insertion=iwyu", - -- "--completion-style=detailed", - -- "--function-arg-placeholders", - -- "--fallback-style=llvm", - -- }, - -- init_options = { - -- usePlaceholders = true, - -- completeUnimported = true, - -- clangdFileStatus = true, - -- }, - }) - end, - -- ltex = function() - -- require("lspconfig").ltex.setup({ - -- settings = { - -- ltex = { - -- language = {"en-US"}, - -- -- dictionary = {":~/.config/nvim/spell/en.utf-8.add"}, - -- disabledRules = { ['en-US'] = { 'MORFOLOGIK_RULE_EN_US' } }, - -- }, - -- }, - -- }) - -- end, - }, - }) - end, - }, + vim.diagnostic.config({ + underline = false, + virtual_text = false, + signs = true, + update_in_insert = false, + severity_sort = true, + }) + + require("mason-lspconfig").setup({ + ensure_installed = { + "clangd", + "ruff_lsp", + "marksman", + "html", + "cssls", + "lua_ls", + "bashls", + "texlab", + "jsonls", + "eslint", + }, + handlers = { + lsp_zero.default_setup, + lua_ls = function() + require("lspconfig").lua_ls.setup({ + settings = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, + }) + end, + clangd = function() + require("lspconfig").clangd.setup({ + capabilities = { offsetEncoding = "utf-16" }, + -- cmd = { + -- "clangd", + -- "--background-index", + -- "--clang-tidy", + -- "--header-insertion=iwyu", + -- "--completion-style=detailed", + -- "--function-arg-placeholders", + -- "--fallback-style=llvm", + -- }, + -- init_options = { + -- usePlaceholders = true, + -- completeUnimported = true, + -- clangdFileStatus = true, + -- }, + }) + end, + -- ltex = function() + -- require("lspconfig").ltex.setup({ + -- settings = { + -- ltex = { + -- language = {"en-US"}, + -- -- dictionary = {":~/.config/nvim/spell/en.utf-8.add"}, + -- disabledRules = { ['en-US'] = { 'MORFOLOGIK_RULE_EN_US' } }, + -- }, + -- }, + -- }) + -- end, + }, + }) + end, + }, } diff --git a/.config/nvim/lua/plugins/ui.lua b/.config/nvim/lua/plugins/ui.lua index 91bd922..38c10fc 100644 --- a/.config/nvim/lua/plugins/ui.lua +++ b/.config/nvim/lua/plugins/ui.lua @@ -29,6 +29,18 @@ return { hl.DiagnosticVirtualTextWarn = { fg = colors.comment } + hl.DiagnosticSignError = { + fg = colors.comment + } + hl.DiagnosticSignHint = { + fg = colors.comment + } + hl.DiagnosticSignInfo = { + fg = colors.comment + } + hl.DiagnosticSignWarn = { + fg = colors.comment + } end, }) vim.cmd.colorscheme("tokyonight") @@ -349,14 +361,14 @@ return { end, }, winopts = { - height = 0.3, + height = 0.4, width = 0.5, }, }) end), - dashboard.button("f", " Find file", ":lua require('fzf-lua').files()"), - dashboard.button("t", "󱎸 Find text", ":lua require('fzf-lua').live_grep_native()"), + -- dashboard.button("f", " Find file", ":lua require('fzf-lua').files()"), + -- dashboard.button("t", "󱎸 Find text", ":lua require('fzf-lua').live_grep_native()"), dashboard.button("s", " Restore Session", ":lua require('persistence').load()"), dashboard.button("n", "󰠮 Notes", ":lua require('fzf-lua').files({cwd =[[~/notes]]})"), dashboard.button("c", " Configuration", ":e $MYVIMRC "), diff --git a/.config/nvim/lua/snippets/cpp.json b/.config/nvim/lua/snippets/cpp.json new file mode 100644 index 0000000..a982022 --- /dev/null +++ b/.config/nvim/lua/snippets/cpp.json @@ -0,0 +1,14 @@ +{ + "Hello World": { + "prefix": "hello", + "body": [ + "#include ", + "", + "int main () {", + "\t$1", + "\treturn 0;", + "}" + ], + "description": "starter template" + } +} diff --git a/.config/nvim/lua/snippets/package.json b/.config/nvim/lua/snippets/package.json index 52e7911..d20f67a 100644 --- a/.config/nvim/lua/snippets/package.json +++ b/.config/nvim/lua/snippets/package.json @@ -15,6 +15,10 @@ "all" ], "path": "./global.json" + }, + { + "language": "cpp", + "path": "./cpp.json" } ] }