add cpp custom snippet and tone down diagnostics

This commit is contained in:
mintycube 2024-04-29 15:07:37 +05:00
parent 44c76af6c6
commit cfce3cf614
4 changed files with 216 additions and 178 deletions

View File

@ -1,186 +1,194 @@
return { return {
{ {
"VonHeikemen/lsp-zero.nvim", "VonHeikemen/lsp-zero.nvim",
branch = "v3.x", branch = "v3.x",
lazy = true, lazy = true,
config = false, config = false,
init = function() init = function()
vim.g.lsp_zero_extend_cmp = 0 vim.g.lsp_zero_extend_cmp = 0
vim.g.lsp_zero_extend_lspconfig = 0 vim.g.lsp_zero_extend_lspconfig = 0
end, end,
}, },
-- autocompletion -- autocompletion
{ {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
event = "InsertEnter", event = "InsertEnter",
dependencies = { dependencies = {
{ "L3MON4D3/LuaSnip" }, { "L3MON4D3/LuaSnip" },
{ "hrsh7th/cmp-buffer" }, { "hrsh7th/cmp-buffer" },
{ "https://codeberg.org/FelipeLema/cmp-async-path" }, { "https://codeberg.org/FelipeLema/cmp-async-path" },
{ "hrsh7th/cmp-nvim-lsp" }, { "hrsh7th/cmp-nvim-lsp" },
{ "saadparwaiz1/cmp_luasnip" }, { "saadparwaiz1/cmp_luasnip" },
{ "rafamadriz/friendly-snippets" }, { "rafamadriz/friendly-snippets" },
{ "onsails/lspkind.nvim" }, { "onsails/lspkind.nvim" },
{ "hrsh7th/cmp-calc" }, { "hrsh7th/cmp-calc" },
{ "f3fora/cmp-spell" }, { "f3fora/cmp-spell" },
{ "micangl/cmp-vimtex" }, { "micangl/cmp-vimtex" },
{ "Jezda1337/nvim-html-css" }, { "Jezda1337/nvim-html-css" },
}, },
config = function() config = function()
local lsp_zero = require("lsp-zero") local lsp_zero = require("lsp-zero")
lsp_zero.extend_cmp() lsp_zero.extend_cmp()
local cmp = require("cmp") local cmp = require("cmp")
local cmp_action = lsp_zero.cmp_action() local cmp_action = lsp_zero.cmp_action()
-- Lazy load snippets from VSCode -- Lazy load snippets from VSCode
require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
require("luasnip.loaders.from_vscode").lazy_load({ paths = { "./lua/snippets" } }) require("luasnip.loaders.from_vscode").lazy_load({ paths = { "./lua/snippets" } })
cmp.setup({ cmp.setup({
sources = { sources = {
{ name = "luasnip" }, { name = "luasnip" },
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "buffer" }, { name = "buffer" },
{ name = "async_path" }, { name = "async_path" },
{ name = "calc" }, { name = "calc" },
{ name = "html-css" }, { name = "html-css" },
{ name = "vimtex" }, { name = "vimtex" },
{ {
name = "spell", name = "spell",
option = { option = {
keep_all_entries = false, keep_all_entries = false,
enable_in_context = function() enable_in_context = function()
return true return true
end, end,
}, },
}, },
}, },
preselect = "item", preselect = "item",
completion = { completion = {
completeopt = "menu,menuone,noinsert", completeopt = "menu,menuone,noinsert",
}, },
window = { window = {
completion = cmp.config.window.bordered(), completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(),
}, },
formatting = { formatting = {
maxwidth = 30, maxwidth = 30,
fields = { "abbr", "kind" }, fields = { "abbr", "kind" },
format = require("lspkind").cmp_format({ format = require("lspkind").cmp_format({
mode = "symbol_text", mode = "symbol_text",
maxwidth = 30, maxwidth = 30,
ellipsis_char = "", ellipsis_char = "",
}), }),
}, },
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(), ["<C-Space>"] = cmp.mapping.complete(),
["<C-u>"] = cmp.mapping.scroll_docs(-4), ["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4), ["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-f>"] = cmp_action.luasnip_jump_forward(), ["<C-f>"] = cmp_action.luasnip_jump_forward(),
["<C-b>"] = cmp_action.luasnip_jump_backward(), ["<C-b>"] = cmp_action.luasnip_jump_backward(),
["<CR>"] = cmp.mapping.confirm({ select = false }), ["<CR>"] = cmp.mapping.confirm({ select = false }),
["<Tab>"] = cmp_action.luasnip_supertab(), ["<Tab>"] = cmp_action.luasnip_supertab(),
["<S-Tab>"] = cmp_action.luasnip_shift_supertab(), ["<S-Tab>"] = cmp_action.luasnip_shift_supertab(),
}), }),
snippet = { snippet = {
expand = function(args) expand = function(args)
require("luasnip").lsp_expand(args.body) require("luasnip").lsp_expand(args.body)
end, end,
}, },
}) })
end, end,
}, },
-- lsp -- lsp
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
cmd = { "LspInfo", "LspInstall", "LspStart" }, cmd = { "LspInfo", "LspInstall", "LspStart" },
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
dependencies = { dependencies = {
{ {
"williamboman/mason.nvim", "williamboman/mason.nvim",
config = true, config = true,
}, },
{ "hrsh7th/cmp-nvim-lsp" }, { "hrsh7th/cmp-nvim-lsp" },
{ "williamboman/mason-lspconfig.nvim" }, { "williamboman/mason-lspconfig.nvim" },
}, },
config = function() config = function()
local lsp_zero = require("lsp-zero") local lsp_zero = require("lsp-zero")
lsp_zero.extend_lspconfig() lsp_zero.extend_lspconfig()
lsp_zero.on_attach(function(client, bufnr) lsp_zero.on_attach(function(client, bufnr)
lsp_zero.default_keymaps({ lsp_zero.default_keymaps({
buffer = bufnr, buffer = bufnr,
-- exclude = { 'gl', 'K' }, -- exclude = { 'gl', 'K' },
}) })
end) end)
lsp_zero.set_sign_icons({ lsp_zero.set_sign_icons({
error = "", error = "",
warn = "", warn = "",
hint = "󰌵", hint = "󰌵",
info = "", info = "",
}) })
require("mason-lspconfig").setup({ vim.diagnostic.config({
ensure_installed = { underline = false,
"clangd", virtual_text = false,
"ruff_lsp", signs = true,
"marksman", update_in_insert = false,
"html", severity_sort = true,
"cssls", })
"lua_ls",
"bashls", require("mason-lspconfig").setup({
"texlab", ensure_installed = {
"jsonls", "clangd",
"eslint", "ruff_lsp",
}, "marksman",
handlers = { "html",
lsp_zero.default_setup, "cssls",
lua_ls = function() "lua_ls",
require("lspconfig").lua_ls.setup({ "bashls",
settings = { "texlab",
Lua = { "jsonls",
workspace = { checkThirdParty = false }, "eslint",
telemetry = { enable = false }, },
}, handlers = {
}, lsp_zero.default_setup,
}) lua_ls = function()
end, require("lspconfig").lua_ls.setup({
clangd = function() settings = {
require("lspconfig").clangd.setup({ Lua = {
capabilities = { offsetEncoding = "utf-16" }, workspace = { checkThirdParty = false },
-- cmd = { telemetry = { enable = false },
-- "clangd", },
-- "--background-index", },
-- "--clang-tidy", })
-- "--header-insertion=iwyu", end,
-- "--completion-style=detailed", clangd = function()
-- "--function-arg-placeholders", require("lspconfig").clangd.setup({
-- "--fallback-style=llvm", capabilities = { offsetEncoding = "utf-16" },
-- }, -- cmd = {
-- init_options = { -- "clangd",
-- usePlaceholders = true, -- "--background-index",
-- completeUnimported = true, -- "--clang-tidy",
-- clangdFileStatus = true, -- "--header-insertion=iwyu",
-- }, -- "--completion-style=detailed",
}) -- "--function-arg-placeholders",
end, -- "--fallback-style=llvm",
-- ltex = function() -- },
-- require("lspconfig").ltex.setup({ -- init_options = {
-- settings = { -- usePlaceholders = true,
-- ltex = { -- completeUnimported = true,
-- language = {"en-US"}, -- clangdFileStatus = true,
-- -- dictionary = {":~/.config/nvim/spell/en.utf-8.add"}, -- },
-- disabledRules = { ['en-US'] = { 'MORFOLOGIK_RULE_EN_US' } }, })
-- }, end,
-- }, -- ltex = function()
-- }) -- require("lspconfig").ltex.setup({
-- end, -- settings = {
}, -- ltex = {
}) -- language = {"en-US"},
end, -- -- dictionary = {":~/.config/nvim/spell/en.utf-8.add"},
}, -- disabledRules = { ['en-US'] = { 'MORFOLOGIK_RULE_EN_US' } },
-- },
-- },
-- })
-- end,
},
})
end,
},
} }

View File

@ -29,6 +29,18 @@ return {
hl.DiagnosticVirtualTextWarn = { hl.DiagnosticVirtualTextWarn = {
fg = colors.comment fg = colors.comment
} }
hl.DiagnosticSignError = {
fg = colors.comment
}
hl.DiagnosticSignHint = {
fg = colors.comment
}
hl.DiagnosticSignInfo = {
fg = colors.comment
}
hl.DiagnosticSignWarn = {
fg = colors.comment
}
end, end,
}) })
vim.cmd.colorscheme("tokyonight") vim.cmd.colorscheme("tokyonight")
@ -349,14 +361,14 @@ return {
end, end,
}, },
winopts = { winopts = {
height = 0.3, height = 0.4,
width = 0.5, width = 0.5,
}, },
}) })
end), end),
dashboard.button("f", " Find file", ":lua require('fzf-lua').files()<CR>"), -- dashboard.button("f", " Find file", ":lua require('fzf-lua').files()<CR>"),
dashboard.button("t", "󱎸 Find text", ":lua require('fzf-lua').live_grep_native()<CR>"), -- dashboard.button("t", "󱎸 Find text", ":lua require('fzf-lua').live_grep_native()<CR>"),
dashboard.button("s", " Restore Session", ":lua require('persistence').load()<CR>"), dashboard.button("s", " Restore Session", ":lua require('persistence').load()<CR>"),
dashboard.button("n", "󰠮 Notes", ":lua require('fzf-lua').files({cwd =[[~/notes]]})<CR>"), dashboard.button("n", "󰠮 Notes", ":lua require('fzf-lua').files({cwd =[[~/notes]]})<CR>"),
dashboard.button("c", " Configuration", ":e $MYVIMRC <CR>"), dashboard.button("c", " Configuration", ":e $MYVIMRC <CR>"),

View File

@ -0,0 +1,14 @@
{
"Hello World": {
"prefix": "hello",
"body": [
"#include <iostream>",
"",
"int main () {",
"\t$1",
"\treturn 0;",
"}"
],
"description": "starter template"
}
}

View File

@ -15,6 +15,10 @@
"all" "all"
], ],
"path": "./global.json" "path": "./global.json"
},
{
"language": "cpp",
"path": "./cpp.json"
} }
] ]
} }