diff options
| author | srdusr <trevorgray@srdusr.com> | 2022-10-18 23:58:06 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2022-10-18 23:58:06 +0200 |
| commit | 8242c19f6427996a94e6f6079b11ccebdb003cf2 (patch) | |
| tree | 9af756db5b293c4e96372d77e3f7bb91d2cf2736 /lua | |
| parent | 2d2c18e3b61a1883190fcd3c9dd9ab86002ddeab (diff) | |
| download | dotfiles-8242c19f6427996a94e6f6079b11ccebdb003cf2.tar.gz dotfiles-8242c19f6427996a94e6f6079b11ccebdb003cf2.zip | |
Updated Cmp and lsp
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/keys.lua | 10 | ||||
| -rw-r--r-- | lua/opts.lua | 5 | ||||
| -rw-r--r-- | lua/pack.lua | 82 | ||||
| -rw-r--r-- | lua/plugins/cmp.lua | 232 | ||||
| -rw-r--r-- | lua/plugins/colorscheme.lua | 2 | ||||
| -rw-r--r-- | lua/plugins/lsp.lua | 356 | ||||
| -rw-r--r-- | lua/plugins/lspsaga.lua | 14 | ||||
| -rw-r--r-- | lua/plugins/telescope.lua | 36 |
8 files changed, 539 insertions, 198 deletions
diff --git a/lua/keys.lua b/lua/keys.lua index 55e24ac..c8f796d 100644 --- a/lua/keys.lua +++ b/lua/keys.lua @@ -38,6 +38,10 @@ map("n", "<leader>n", ":bn<cr>", opts) map("n", "<leader>p", ":bp<cr>", opts) map("n", "<leader>d", ":bd<cr>", opts) +-- Disable default completion. +map('i', '<C-n>', '<Nop>', opts) +map('i', '<C-p>', '<Nop>', opts) + -- Set alt + j/k to switch lines of texts or simply move them map("n", "<A-k>", ':let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>', opts) map("n", "<A-j>", ':let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>', opts) @@ -190,6 +194,7 @@ map( map("n", "<leader>fg", "<cmd>lua require('telescope.builtin').live_grep()<cr>", opts) map("n", "<leader>fb", "<cmd>lua require('telescope.builtin').current_buffer_fuzzy_find()<cr>", opts) + map("n", "<leader>fd", "<cmd>lua require('telescope.builtin').diagnostics()<cr>", opts) --map("n", "<leader>fz", ":FZF<CR>", opts) --map("t", [[<Esc><Esc>]], [[<C-\><C-N>]], opts) --map("n", "ff", ":NvimTreeToggle<CR>", {}) @@ -197,9 +202,9 @@ map("n", "<leader>f", ":NvimTreeToggle<CR>", {}) -- This <Esc><Esc> avoids crashing fzf menu running in TERMINAL MODE (:q if you do) -- Find files in config dirs --key_map("n", "<leader>e", ":lua require('plugins.telescope').find_configs()<CR>", opts) -map("n", "<leader>f.", "<cmd>lua require('plugins.telescope').find_configs({})<cr>", opts) +--map("n", "<leader>f.", "<cmd>lua require('plugins.telescope').find_configs({})<cr>", opts) map("n", "<leader>ft", "<cmd>lua require('plugins.telescope').file_explorer({})<cr>", opts) -map("n", "<leader>fd", "<cmd>lua require('plugins.telescope').find_notes({})<cr>", opts) +--map("n", "<leader>fd", "<cmd>lua require('plugins.telescope').find_notes({})<cr>", opts) map("n", "<leader>fm", "<cmd>lua require('telescope').extensions.media_files.media_files({})<cr>", opts) -- registers picker map("n", "<leader>r", "<cmd>lua require('telescope.builtin').registers({})<CR>", opts) @@ -475,7 +480,6 @@ vim.cmd([[ -- desc = "Search symbols", -- } -- maps.n["<leader>lR"] = { function() require("telescope.builtin").lsp_references() end, desc = "Search references" } --- maps.n["<leader>lD"] = { function() require("telescope.builtin").diagnostics() end, desc = "Search diagnostics" } --end -- ---- Terminal diff --git a/lua/opts.lua b/lua/opts.lua index 2bc70d6..51b3628 100644 --- a/lua/opts.lua +++ b/lua/opts.lua @@ -118,9 +118,10 @@ vim.opt.ignorecase = true -- ignore case in search patterns UNLESS /C or capital vim.opt.smartcase = true -- smart case vim.opt.synmaxcol = 200 -- Only highlight the first 200 columns. vim.opt.winblend = 30 +--vim.opt.winblend = 5 vim.opt.wildoptions = "pum" -- ---vim.opt.pumblend = 5 -- -vim.opt.pumblend=15 +vim.opt.pumblend = 5 -- +--vim.opt.pumblend=15 vim.opt.pumheight = 10 -- pop up menu height -- Better Completion diff --git a/lua/pack.lua b/lua/pack.lua index 48db169..840baf2 100644 --- a/lua/pack.lua +++ b/lua/pack.lua @@ -1,4 +1,3 @@ -local utils = require("utils") local fn = vim.fn -- Automatically install packer @@ -60,33 +59,46 @@ return packer.startup(function(use) "pylsp", "pyright", "clangd", - "vim-language-server", - "bash-language-server", - "lua-language-server", + --"vim-language-server", + --"bash-language-server", + --"lua-language-server", "sumneko_lua", } }) - use { "j-hui/fidget.nvim", + use({ "j-hui/fidget.nvim", config = function() require("fidget").setup() end - } - use { "folke/trouble.nvim", - config = function() - require("trouble").setup() - end - } - use({ - "https://git.sr.ht/~whynothugo/lsp_lines.nvim", -- See also: https://github.com/Maan2003/lsp_lines.nvim - config = function() - require("lsp_lines").setup() - - -- disable virtual_text since it's redundant due to lsp_lines. - vim.diagnostic.config({ - virtual_text = false, - }) - end, }) + --use({ "folke/trouble.nvim", + -- config = function() + -- require("trouble").setup({ position = "right", }) + -- end + --}) + --use({ + --"folke/trouble.nvim", + --requires = "kyazdani42/nvim-web-devicons", + --config = function() + -- require("trouble").setup({ + -- postion = "top", + -- -- your configuration comes here + -- -- or leave it empty to use the default settings + -- -- refer to the configuration section below + -- }) + --end, + --}) + + --use({ + -- "https://git.sr.ht/~whynothugo/lsp_lines.nvim", -- See also: https://github.com/Maan2003/lsp_lines.nvim + -- config = function() + -- require("lsp_lines").setup() + + -- -- disable virtual_text since it's redundant due to lsp_lines. + -- vim.diagnostic.config({ + -- virtual_text = false, + -- }) + -- end, + --}) use { "simrat39/symbols-outline.nvim", config = function() require("symbols-outline").setup({ @@ -95,7 +107,7 @@ return packer.startup(function(use) end } use { "kosayoda/nvim-lightbulb", requires = { "antoinemadec/FixCursorHold.nvim" } } - use "folke/lsp-colors.nvim" + --use("folke/lsp-colors.nvim") use "mfussenegger/nvim-lint" use "weilbith/nvim-code-action-menu" use "simrat39/rust-tools.nvim" @@ -105,10 +117,10 @@ return packer.startup(function(use) require("crates").setup() end, } - use "lvimuser/lsp-inlayhints.nvim" -- rust-tools already provides this feature, but gopls doesn't + --use "lvimuser/lsp-inlayhints.nvim" -- rust-tools already provides this feature, but gopls doesn't -- null-ls - use { "jose-elias-alvarez/null-ls.nvim", + use({ "jose-elias-alvarez/null-ls.nvim", config = function() require("null-ls").setup({ sources = { @@ -116,7 +128,7 @@ return packer.startup(function(use) } }) end - } + }) use({ "SmiteshP/nvim-navic", requires = "neovim/nvim-lspconfig", @@ -138,17 +150,17 @@ return packer.startup(function(use) --use("williamboman/nvim-lsp-installer") --use("glepnir/lspsaga.nvim") --use("nvim-lua/lsp-status.nvim") - use({ - "glepnir/lspsaga.nvim", - branch = "main", - config = function() - local saga = require("lspsaga") + --use({ + -- "glepnir/lspsaga.nvim", + -- branch = "main", + -- config = function() + -- local saga = require("lspsaga") - saga.init_lsp_saga({ - -- your configuration - }) - end, - }) + -- saga.init_lsp_saga({ + -- -- your configuration + -- }) + -- end, + --}) -- use("nvim-lua/popup.nvim") --use("SmiteshP/nvim-gps") -- autocomplete plugins diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index fcec30f..122524c 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,12 +1,12 @@ -- Setup nvim-cmp. -vim.opt.completeopt = "menu,menuone,noselect" - +--vim.opt.completeopt = "menu,menuone,noselect" +vim.g.completeopt = "menu,menuone,noselect,noinsert" local cmp_status_ok, cmp = pcall(require, "cmp") if not cmp_status_ok then return end - +local WIDE_HEIGHT = 40 local opts = { -- whether to highlight the currently hovered symbol @@ -14,63 +14,60 @@ local opts = { -- or you just hate the highlight -- default: true highlight_hovered_item = true, - - -- whether to show outline guides - -- default: true show_guides = true, } require("symbols-outline").setup(opts) -local snippets_paths = function() - local plugins = { "friendly-snippets" } - local paths = {} - local path - local root_path = vim.env.HOME .. "/.vim/plugged/" - for _, plug in ipairs(plugins) do - path = root_path .. plug - if vim.fn.isdirectory(path) ~= 0 then - table.insert(paths, path) - end - end - return paths -end -require("luasnip.loaders.from_vscode").lazy_load({ - paths = snippets_paths(), - include = nil, -- Load all languages - exclude = {}, -}) +--local snippets_paths = function() +-- local plugins = { "friendly-snippets" } +-- local paths = {} +-- local path +-- local root_path = vim.env.HOME .. "/.vim/plugged/" +-- for _, plug in ipairs(plugins) do +-- path = root_path .. plug +-- if vim.fn.isdirectory(path) ~= 0 then +-- table.insert(paths, path) +-- end +-- end +-- return paths +--end +-- +--require("luasnip.loaders.from_vscode").lazy_load({ +-- paths = snippets_paths(), +-- include = nil, -- Load all languages +-- exclude = {}, +--}) +require("luasnip.loaders.from_vscode").lazy_load() local lspkind = require("lspkind") - ---local kind_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 kind_icons = { + Text = "", + Method = "m", --"", + Function = "", + Constructor = "", --"⚙️", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} cmp.setup({ snippet = { expand = function(args) @@ -84,20 +81,45 @@ cmp.setup({ -- }), ['<C-y>'] = cmp.mapping.confirm({ select = true }), ["<C-e>"] = cmp.mapping.close(), + --['<CR>'] = cmp.config.disable, ["<C-u>"] = cmp.mapping.scroll_docs(-4), ["<C-d>"] = cmp.mapping.scroll_docs(4), ["<C-Space>"] = cmp.mapping.complete(), + ['<C-o>'] = function(fallback) + if cmp.visible() then + cmp.mapping.confirm({ select = true })(fallback) + else + cmp.mapping.complete()(fallback) + end + end }), + sources = cmp.config.sources({ + { name = "path" }, + { name = "nvim_lsp", keyword_length = 3 }, + { name = "luasnip", keyword_length = 4 }, + --{ name = "buffer", keyword_length = 3 }, + { name = "buffer", option = { get_bufnrs = function() + return vim.api.nvim_list_bufs() + end + }}, + --{ name = 'treesitter' }, + { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, + --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this + { name = "cmp_git"}, + --{name = 'luasnip', keyword_length = 2}, + }), formatting = { - fields = { "abbr", "kind", "menu" }, + --formatting = { format = function(entry, vim_item) - -- Kind icons + --format = function(entry, vim_item,) + --local icons = kind_icons --vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) - vim_item.kind = lspkind.presets.default[vim_item.kind] - -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + -- vim_item.kind = lspkind.presets.default[vim_item.kind] + vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + --vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) vim_item.menu = ({ - nvim_lsp = "LSP", + nvim_lsp = "Lsp", luasnip = "Snip", buffer = "Buf", path = "Path", @@ -105,38 +127,80 @@ cmp.setup({ })[entry.source.name] return vim_item end, - }, - sources = cmp.config.sources({ - { name = "path" }, - { name = "nvim_lsp", keyword_length = 3 }, - { name = "luasnip", keyword_length = 4 }, - { name = "buffer", keyword_length = 3 }, - --{ name = 'treesitter' }, - { name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=], keyword_length = 3 }, - --{ name = "cmdline", keyword_pattern = [=[[^[:blank:]\!]*]=] }, --exclamation mark hangs a bit without this - --{name = 'luasnip', keyword_length = 2}, - }), + --}, + + -- + -- + --fields = { "abbr", "kind", "menu" }, + -- format = lspkind.cmp_format({ + -- mode = 'symbol_text', -- show only symbol annotations + -- maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) + -- }) + --format = require('lspkind').cmp_format { + -- with_text = true, + -- menu = { + -- luasnip = "Snip", + -- buffer = "Buf", + -- nvim_lsp = "LSP", + -- path = "Path", + -- cmdline = "Cmd", + -- cmp_git = "Git", + -- }, + --}, + }, + --format = function(entry, vim_item) + -- -- Kind icons + -- --vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = lspkind.presets.default[vim_item.kind] + -- -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + -- vim_item.menu = ({ + -- nvim_lsp = "LSP", + -- luasnip = "Snip", + -- buffer = "Buf", + -- path = "Path", + -- cmdline = "Cmd", + -- })[entry.source.name] + -- return vim_item + --end, confirm_opts = { behavior = cmp.ConfirmBehavior.Replace, select = false, }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - --documentation = { - -- border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - --}, - }, --- experimental = { --- ghost_text = true, --- native_menu = true, --- --native_menu = false, --- --view = { --- -- entries = "native" --- --}, --- }, + + + event = {}, + + experimental = { + ghost_text = true, + hl_group = 'Nontext', + }, + + view = { + entries = { name = 'custom', selection_order = 'top_down' }, + }, + + window = { + --completion = cmp.config.window.bordered(), + completion = { + border = { '', '', '', ' ', '', '', '', ' ' }, + --border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + --border = { '', '', '', '', '', '', '', '' }, + --border = "CmpBorder", + --winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None', + winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", + }, + --documentation = cmp.config.window.bordered(), + documentation = { + max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)), + max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))), + border = { '', '', '', ' ', '', '', '', ' ' }, + --border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + winhighlight = 'FloatBorder:NormalFloat', + }, + }, }) + cmp.setup.cmdline("/", { mapping = cmp.mapping.preset.cmdline(), sources = { diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua index 11d8834..35e4f47 100644 --- a/lua/plugins/colorscheme.lua +++ b/lua/plugins/colorscheme.lua @@ -20,8 +20,8 @@ vim.api.nvim_command("highlight StatusLine guibg=#333842 gui=bold") vim.api.nvim_command("highlight TabLineSel guibg=#333842 gui=bold") vim.api.nvim_command("highlight TabLineFill guibg=none gui=bold") vim.api.nvim_command("highlight WinBar guibg=none gui=bold") ---vim.api.nvim_command("highlight PmenuSel guibg=none") vim.api.nvim_command("highlight NormalFloat guibg=none") +--vim.api.nvim_command("highlight PmenuSel guibg=none") --vim.api.nvim_command("highlight winblend guibg=none") --vim.api.nvim_command("highlight StatusLine guibg=none gui=bold") --vim.api.nvim_command("highlight StatusLineNC guibg=none gui=bold") diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index bf9f771..323b864 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -19,16 +19,16 @@ local custom_attach = function(client, bufnr) --map("n", "gd", "<Cmd>Lspsaga lsp_finder<CR>") -- Press "o" to open the reference location --map("n", "gp", "<Cmd>Lspsaga peek_definition<CR>") -- --map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) --- map("n", "<C-]>", vim.lsp.buf.definition) + map("n", "<C-]>", vim.lsp.buf.definition) -- map("n", "K", vim.lsp.buf.hover) -- map("n", "<C-k>", vim.lsp.buf.signature_help) -- map("n", "<leader>rn", vim.lsp.buf.rename, { desc = "varialble rename" }) -- map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) -- map("n", "[d", vim.diagnostic.goto_prev, { desc = "previous diagnostic" }) -- map("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic" }) --- map("n", "<leader>q", function() --- vim.diagnostic.setqflist({ open = true }) --- end, { desc = "put diagnostic to qf" }) + map("n", "<leader>q", function() + vim.diagnostic.setqflist({ open = true }) + end, { desc = "put diagnostic to qf" }) -- --map.('n', '<space>q', vim.diagnostic.setloclist) -- map("n", "ga", vim.lsp.buf.code_action, { desc = "LSP code action" }) -- map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) @@ -42,10 +42,44 @@ local custom_attach = function(client, bufnr) -- map("n", "gt", ":lua vim.lsp.buf.type_definition()<cr>") -- map("n", "gD", ":lua vim.lsp.buf.declaration()<cr>") -- most lsp servers don't implement textDocument/Declaration, so gD is useless for now. -- map("n", "gi", ":lua vim.lsp.buf.implementation()<cr>") --- map("n", "go", ":lua vim.diagnostic.open_float()<cr>") + map("n", "go", ":lua vim.diagnostic.open_float()<cr>") -- map("n", "gk", "<Cmd>Lspsaga diagnostic_jump_prev<CR>") -- map("n", "gj", "<Cmd>Lspsaga diagnostic_jump_next<CR>") +vim.g.diagnostics_visible = true +function _G.toggle_diagnostics() + if vim.g.diagnostics_visible then + vim.g.diagnostics_visible = false + vim.diagnostic.disable() + else + vim.g.diagnostics_visible = true + vim.diagnostic.enable() + end +end +map('n', '<Leader>m', ':call v:lua.toggle_diagnostics()<CR>') +--vim.g.diagnostics_active = true +--function _G.toggle_diagnostics() +-- if vim.g.diagnostics_active then +-- vim.g.diagnostics_active = false +-- vim.lsp.diagnostic.clear(0) +-- vim.cmd([[exe "normal ii\<Esc>x"]]) +-- vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end +-- else +-- vim.g.diagnostics_active = true +-- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( +-- vim.lsp.diagnostic.on_publish_diagnostics, { +-- virtual_text = true, +-- signs = true, +-- underline = true, +-- update_in_insert = false, +-- } +-- ) +-- end +--end +-- +--map("n", "<leader>i", ":call v:lua.toggle_diagnostics()<CR>") + + -- Set some key bindings conditional on server capabilities if client.server_capabilities.documentFormattingProvider then map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" }) @@ -57,33 +91,48 @@ local custom_attach = function(client, bufnr) map("n", "<leader>ra", "<cmd>RustHoverAction<CR>") end +--For diagnostics for specific cursor position +--vim.api.nvim_create_autocmd("CursorHold", { +-- buffer = bufnr, +-- callback = function() +-- local opts = { +-- focusable = false, +-- close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, +-- border = 'rounded', +-- source = 'always', +-- prefix = ' ', +-- scope = 'cursor', +-- } +-- vim.diagnostic.open_float(nil, opts) +-- end +--}) -- Diagnostic position - vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - local float_opts = { - focusable = false, - close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = "rounded", - source = "always", -- show source in diagnostic popup window - prefix = " ", - } - - if not vim.b.diagnostics_pos then - vim.b.diagnostics_pos = { nil, nil } - end - - local cursor_pos = vim.api.nvim_win_get_cursor(0) - if - (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) - and #vim.diagnostic.get() > 0 - then - vim.diagnostic.open_float(nil, float_opts) - end - - vim.b.diagnostics_pos = cursor_pos - end, - }) +-- vim.api.nvim_create_autocmd("CursorHold", { +-- buffer = bufnr, +-- callback = function() +-- local float_opts = { +-- focusable = false, +-- close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, +-- border = "rounded", +-- source = "always", -- show source in diagnostic popup window +-- prefix = " ", +-- } +-- +-- if not vim.b.diagnostics_pos then +-- vim.b.diagnostics_pos = { nil, nil } +-- end +-- +-- local cursor_pos = vim.api.nvim_win_get_cursor(0) +-- if +-- (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) +-- and #vim.diagnostic.get() > 0 +-- then +-- vim.diagnostic.open_float(nil, float_opts) +-- end +-- +-- vim.b.diagnostics_pos = cursor_pos +-- end, +-- }) -- The below command will highlight the current variable and its usages in the buffer. if client.server_capabilities.documentHighlightProvider then @@ -106,7 +155,7 @@ local custom_attach = function(client, bufnr) end local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) +capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.offsetEncoding = { "utf-16" } @@ -226,31 +275,98 @@ require("lspconfig").rust_analyzer.setup{ } end +--vim.diagnostic.config({ +-- virtual_text = false, +-- underline = true, +--}) +vim.diagnostic.config({ + underline = false, + signs = true, + virtual_text = false, + float = { + show_header = true, + source = 'if_many', + border = 'rounded', + focusable = false, + }, + update_in_insert = false, -- default to false + severity_sort = false, -- default to false +}) +-- Show line diagnostics automatically in hover window +vim.o.updatetime = 250 +vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]] + +--local diagnostics_active = true +--local toggle_diagnostics = function() +-- diagnostics_active = not diagnostics_active +-- if diagnostics_active then +-- vim.o.updatetime = 250 +-- vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]] +-- --vim.diagnostic.open_float(nil, {focus=false}) +-- else +-- --vim.diagnostic.hide() +-- vim.diagnostic.disable() +-- end +--end +--vim.keymap.set("n", "<leader>a", toggle_diagnostics) + +-- Toogle diagnostics +local diagnostics_active = true +local toggle_diagnostics = function() + diagnostics_active = not diagnostics_active + if diagnostics_active then + vim.api.nvim_echo({ { "Show diagnostics" } }, false, {}) + vim.diagnostic.enable() + else + vim.api.nvim_echo({ { "Disable diagnostics" } }, false, {}) + vim.diagnostic.disable() + end +end +vim.keymap.set("n", "<leader>a", toggle_diagnostics) + +--vim.cmd [[autocmd CursorHold * lua vim.diagnostic.open_float(0, {scope="cursor", close_events = {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre", "WinLeave"}})]] + +--function LspDiagnosticsFocus() +-- vim.api.nvim_command('set eventignore=WinLeave') +-- vim.api.nvim_command('autocmd CursorMoved <buffer> ++once set eventignore=""') +-- vim.diagnostic.open_float(nil, {focusable = false, scope = 'line', close_events = {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre", "WinLeave"}}) +--end +--vim.api.nvim_set_keymap('', '<Leader>a', '<Cmd>lua LspDiagnosticsFocus()<CR>', {silent = true}) +--local diagnostics_active = true +--map('n', '<leader>a', function() +-- diagnostics_active = not diagnostics_active +-- if diagnostics_active then +-- vim.diagnostic.show() +-- else +-- vim.diagnostic.hide() +-- end +--end) -- Global config for diagnostic -vim.diagnostic.config({ - underline = false, - virtual_text = true, - signs = true, - severity_sort = true, - float = { - focusable = true, -- - style = "minimal", -- - --border = "rounded", - border = "shadow", - source = "always", - header = "", - prefix = "", - }, -}) +--vim.diagnostic.config({ +-- underline = false, +-- virtual_text = false, +-- signs = true, +-- severity_sort = true, +-- float = { +-- focusable = true, -- +-- style = "minimal", -- +-- --border = "rounded", +-- border = "shadow", +-- source = "always", +-- header = "", +-- prefix = "", +-- }, +--}) vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - underline = false, + underline = true, virtual_text = false, signs = true, update_in_insert = false, }) + --vim.lsp.buf.definition --vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) @@ -265,3 +381,147 @@ for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end + + +---- Location information about the last message printed. The format is +---- `(did print, buffer number, line number)`. +--local last_echo = { false, -1, -1 } +-- +---- The timer used for displaying a diagnostic in the commandline. +--local echo_timer = nil +-- +---- The timer after which to display a diagnostic in the commandline. +--local echo_timeout = 250 +-- +---- The highlight group to use for warning messages. +--local warning_hlgroup = 'WarningMsg' +-- +---- The highlight group to use for error messages. +--local error_hlgroup = 'ErrorMsg' +-- +---- If the first diagnostic line has fewer than this many characters, also add +---- the second line to it. +--local short_line_limit = 20 +-- +---- Shows the current line's diagnostics in a floating window. +--function show_line_diagnostics() +-- vim +-- .lsp +-- .diagnostic +-- .show_line_diagnostics({ severity_limit = 'Warning' }, vim.fn.bufnr('')) +--end +-- +---- Prints the first diagnostic for the current line. +--function echo_diagnostic() +-- if echo_timer then +-- echo_timer:stop() +-- end +-- +-- echo_timer = vim.defer_fn( +-- function() +-- local line = vim.fn.line('.') - 1 +-- local bufnr = vim.api.nvim_win_get_buf(0) +-- +-- if last_echo[1] and last_echo[2] == bufnr and last_echo[3] == line then +-- return +-- end +-- +-- local diags = vim +-- .lsp +-- .diagnostic +-- .get_line_diagnostics(bufnr, line, { severity_limit = 'Warning' }) +-- +-- if #diags == 0 then +-- -- If we previously echo'd a message, clear it out by echoing an empty +-- -- message. +-- if last_echo[1] then +-- last_echo = { false, -1, -1 } +-- +-- vim.api.nvim_command('echo ""') +-- end +-- +-- return +-- end +-- +-- last_echo = { true, bufnr, line } +-- +-- local diag = diags[1] +-- local width = vim.api.nvim_get_option('columns') - 15 +-- local lines = vim.split(diag.message, "\n") +-- local message = lines[1] +-- local trimmed = false +-- +-- if #lines > 1 and #message <= short_line_limit then +-- message = message .. ' ' .. lines[2] +-- end +-- +-- if width > 0 and #message >= width then +-- message = message:sub(1, width) .. '...' +-- end +-- +-- local kind = 'warning' +-- local hlgroup = warning_hlgroup +-- +-- if diag.severity == vim.lsp.protocol.DiagnosticSeverity.Error then +-- kind = 'error' +-- hlgroup = error_hlgroup +-- end +-- +-- local chunks = { +-- { kind .. ': ', hlgroup }, +-- { message } +-- } +-- +-- vim.api.nvim_echo(chunks, false, {}) +-- end, +-- echo_timeout +-- ) +--end +--vim.cmd([[ +-- autocmd CursorMoved * :lua echo_diagnostic() +--]]) +-- Highlight line number instead of having icons in sign column + +-- See the properties of the signs with sign list. + +--vim.cmd [[ +-- highlight! DiagnosticLineNrError guibg=#51202A guifg=#FF0000 gui=bold +-- highlight! DiagnosticLineNrWarn guibg=#51412A guifg=#FFA500 gui=bold +-- highlight! DiagnosticLineNrInfo guibg=#1E535D guifg=#00FFFF gui=bold +-- highlight! DiagnosticLineNrHint guibg=#1E205D guifg=#0000FF gui=bold +-- +-- sign define DiagnosticSignError text= texthl=DiagnosticSignError linehl= numhl=DiagnosticLineNrError +-- sign define DiagnosticSignWarn text= texthl=DiagnosticSignWarn linehl= numhl=DiagnosticLineNrWarn +-- sign define DiagnosticSignInfo text= texthl=DiagnosticSignInfo linehl= numhl=DiagnosticLineNrInfo +-- sign define DiagnosticSignHint text= texthl=DiagnosticSignHint linehl= numhl=DiagnosticLineNrHint +--]] + +-- Highlight symbol under cursor + +-- Add the following to your on_attach (this allows checking server capabilities to avoid calling invalid commands. + +--if client.resolved_capabilities.document_highlight then +-- vim.cmd [[ +-- hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow +-- hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow +-- hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow +-- ]] +-- vim.api.nvim_create_augroup('lsp_document_highlight', { +-- clear = false +-- }) +-- vim.api.nvim_clear_autocmds({ +-- buffer = bufnr, +-- group = 'lsp_document_highlight', +-- }) +-- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { +-- group = 'lsp_document_highlight', +-- buffer = bufnr, +-- callback = vim.lsp.buf.document_highlight, +-- }) +-- vim.api.nvim_create_autocmd('CursorMoved', { +-- group = 'lsp_document_highlight', +-- buffer = bufnr, +-- callback = vim.lsp.buf.clear_references, +-- }) +--end + diff --git a/lua/plugins/lspsaga.lua b/lua/plugins/lspsaga.lua index aeff464..0bf1ec7 100644 --- a/lua/plugins/lspsaga.lua +++ b/lua/plugins/lspsaga.lua @@ -21,7 +21,7 @@ require "lspsaga".init_lsp_saga { enable = false, sign = false, sign_priority = 20, -- - virtual_text = true, + virtual_text = false, }, finder_icons = { def = " ", @@ -118,13 +118,13 @@ local opts = { noremap = true, silent = true } map("n", "gd", "<CMD>Lspsaga peek_definition<CR>", opts) --map("n", "gp", "<Cmd>Lspsaga peek_definition<CR>", opts) map("n", "gi", "<CMD>Lspsaga lsp_finder<CR>", opts) ---map("n", "gh", "<CMD>Lspsaga hover_doc<CR>", opts) +map("n", "gh", "<CMD>Lspsaga hover_doc<CR>", opts) map("n", "gs", "<CMD>Lspsaga signature_help<CR>", opts) -map("n", "ga", "<CMD>Lspsaga code_action<CR>", opts) -map("v", "ga", "<CMD><C-u>Lspsaga range_code_action<CR>", opts) -map("n", "gl", "<CMD>Lspsaga show_line_diagnostics<CR>", opts) -map("n", "go", "<CMD>Lspsaga open_floaterm fish<CR>", opts) -map("n", ";D", "<CMD>Lspsaga show_cursor_diagnostics<CR>", opts) +map("n", "ga", "<CMD>Lspsaga code_action<CR>", opts) +map("v", "ga", "<CMD><C-u>Lspsaga range_code_action<CR>", opts) +map("n", "gl", "<CMD>Lspsaga show_line_diagnostics<CR>", opts) +--map("n", "go", "<CMD>Lspsaga open_floaterm zsh<CR>", opts) +map("n", ";D", "<CMD>Lspsaga show_cursor_diagnostics<CR>", opts) map("n", "<gr>", "<CMD>Lspsaga rename<CR>", opts) map("n", "gk", "<CMD>Lspsaga diagnostic_jump_prev<CR>", opts) map("n", "gj", "<CMD>Lspsaga diagnostic_jump_next<CR>", opts) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index dcf6b9e..7e70bd5 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -142,12 +142,12 @@ telescope.setup({ telescope.load_extension("file_browser") -vim.keymap.set("n", ";f", function() - builtin.find_files({ - no_ignore = false, - hidden = true, - }) -end) +--vim.keymap.set("n", ";f", function() +-- builtin.find_files({ +-- no_ignore = false, +-- hidden = true, +-- }) +--end) vim.keymap.set("n", ";r", function() builtin.live_grep() end) @@ -163,15 +163,15 @@ end) vim.keymap.set("n", ";e", function() builtin.diagnostics() end) -vim.keymap.set("n", "sf", function() - telescope.extensions.file_browser.file_browser({ - path = "%:p:h", - cwd = telescope_buffer_dir(), - respect_gitignore = false, - hidden = true, - grouped = true, - previewer = false, - initial_mode = "normal", - layout_config = { height = 40 }, - }) -end) +--vim.keymap.set("n", "sf", function() +-- telescope.extensions.file_browser.file_browser({ +-- path = "%:p:h", +-- cwd = telescope_buffer_dir(), +-- respect_gitignore = false, +-- hidden = true, +-- grouped = true, +-- previewer = false, +-- initial_mode = "normal", +-- layout_config = { height = 40 }, +-- }) +--end) |
