From 776b0cb644a6eba9847c61835c3fa8bd2d7bc253 Mon Sep 17 00:00:00 2001 From: ucpr Date: Sat, 29 Jul 2023 01:25:30 +0900 Subject: [PATCH] chore: fix use cmp --- nvim/init.lua | 1141 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 751 insertions(+), 390 deletions(-) diff --git a/nvim/init.lua b/nvim/init.lua index fec28b3..da7bfd9 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -38,8 +38,8 @@ local options = { laststatus = 2, showtabline = 2, statusline = '%f %y%m %r%h%w%=[%{&fileencoding!=""?&fileencoding:&encoding},%{&ff}] [Pos %02l,%02c] [%p%%/%L]', - pumblend = 10, - winblend = 10, + -- pumblend = 1, + -- winblend = 10, -- syntax tabstop = 2, shiftwidth = 2, @@ -95,11 +95,6 @@ local packer_bootstrap = ensure_packer() require('packer').startup(function(use) use 'wbthomason/packer.nvim' - -- denops - use "vim-denops/denops.vim" - use "yuki-yano/fuzzy-motion.vim" - use "lambdalisue/guise.vim" - -- telescope use "nvim-lua/plenary.nvim" use { @@ -183,384 +178,6 @@ require('packer').startup(function(use) end } - -- ddc.vim - use { - "Shougo/ddc.vim", - -- event = { "InsertEnter", "CursorHold", "CmdlineEnter", "VimEnter" }, - requires = { - -- ui - use { "Shougo/ddc-ui-pum" }, - use { - "Shougo/pum.vim", - config = function() - vim.fn["pum#set_option"]({ - border = 'double', - item_orders = { "abbr", "kind", "menu" }, - padding = true, - }) - end, - }, - - -- sources - use { "Shougo/ddc-source-around" }, - use { "matsui54/ddc-buffer" }, - use { "LumaKernel/ddc-file" }, - use { "Shougo/ddc-source-nvim-lsp" }, - use { "uga-rosa/ddc-source-vsnip" }, - use { "Shougo/ddc-source-cmdline" }, - - -- filters - use { "tani/ddc-fuzzy" }, - use { "Shougo/ddc-filter-sorter_rank" }, - use { "Shougo/ddc-converter_remove_overlap" }, - - -- etc - use { "matsui54/denops-popup-preview.vim" }, - use { "matsui54/denops-signature_help" }, - use { - 'hrsh7th/vim-vsnip', - event = { "InsertEnter" }, - config = function() - vim.g.vsnip_snippet_dir = "$HOME/.config/nvim/snippets" - - vim.cmd [[ - autocmd BufWritePre lua vim.lsp.buf.format({}, 10000) - ]] - end - }, - }, - config = function() - vim.fn["ddc#custom#patch_global"]("ui", "pum") - vim.fn["ddc#custom#patch_global"]("sources", { - "vsnip", - "nvim-lsp", - "file", - "around", - "buffer", - }) - vim.fn["ddc#custom#patch_global"]('sourceOptions', { - _ = { - matchers = { 'matcher_fuzzy' }, - sorters = { 'sorter_rank' }, - converters = { "converter_remove_overlap" }, - minAutoCompleteLength = 1, - }, - file = { - mark = '[file]', - isVolatile = true, - forceCompletionPattern = '\\S/\\S*' - }, - around = { - mark = '[around]', - }, - buffer = { - mark = "[buffer]", - }, - vsnip = { - mark = '[snip]', - keywordPattern = "\\S*", - minAutoCompleteLength = 1, - }, - ['nvim-lsp'] = { - mark = '[lsp]', - forceCompletionPattern = [[\.\w*|:\w*|->\w*]], - dup = "force", - }, - }) - - vim.fn["ddc#custom#patch_global"]('sourceParams', { - around = { maxSize = 100 }, - vsnip = { menu = false }, - buffer = { - requireSameFiletype = false, - limitBytes = 500000, - fromAltBuf = true, - forceCollect = true, - }, - ['nvim-lsp'] = { - snippetEngine = vim.fn['denops#callback#register'](function(body) - return vim.fn['vsnip#anonymous'](body) - end), - enableResolveItem = true, - enableAdditionalTextEdit = true, - confirmBehavior = "replace", - }, - }) - - -- TODO: trans to lua code - vim.cmd [[ - inoremap - \ pum#visible() ? 'call pum#map#insert_relative(+1)' : - \ (col('.') <= 1 getline('.')[col('.') - 2] =~# '\s') ? - \ '' : ddc#manual_complete() - inoremap call pum#map#insert_relative(-1) - inoremap call pum#map#confirm() - - call ddc#custom#patch_global('autoCompleteEvents', [ - \ 'InsertEnter', 'TextChangedI', 'TextChangedP', - \ 'CmdlineEnter', 'CmdlineChanged', - \ ]) - - nnoremap : call CommandlinePre(): - nnoremap ;; call CommandlinePre(): - - function! CommandlinePre() abort - cnoremap call pum#map#insert_relative(+1) - cnoremap call pum#map#insert_relative(-1) - cnoremap call pum#map#confirm() - - if !exists('b:prev_buffer_config') - let b:prev_buffer_config = ddc#custom#get_buffer() - endif - call ddc#custom#patch_buffer('cmdlinesources', - \ ['neovim', 'around']) - - autocmd User DDCCmdlineLeave ++once call CommandlinePost() - autocmd InsertEnter ++once call CommandlinePost() - call ddc#enable_cmdline_completion() - endfunction - - function! CommandlinePost() abort - silent! cunmap - silent! cunmap - silent! cunmap - - if exists('b:prev_buffer_config') - call ddc#custom#set_buffer(b:prev_buffer_config) - unlet b:prev_buffer_config - else - call ddc#custom#set_buffer({}) - endif - endfunction - ]] - - -- local has_words_before = function() - -- unpack = unpack or table.unpack - -- local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - -- return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - -- end - -- local complete_or_select = function(n) - -- if vim.fn["pum#visible"]() then - -- vim.fn["pum#map#insert_relative"](n) - -- return "" - -- elseif has_words_before() then - -- vim.fn['ddc#map#manual_complete']() - -- return "" - -- elseif vim.fn.col "." <= 1 or vim.fn.getline("."):sub(col - 1):match "%s" then - -- return "" - -- else - -- vim.fn['ddc#map#manual_complete']() - -- return "" - -- end - -- end - -- vim.keymap.set({ "i", "c" }, '', function() complete_or_select(1) end, { silent = true, expr = true }) - -- vim.keymap.set({ "i", "c" }, '', function() complete_or_select(-1) end, { silent = true, expr = true }) - -- vim.keymap.set({ "i", "c" }, "", function() vim.fn["pum#map#confirm"]() end) - - vim.g.signature_help_config = { - contentsStyle = "full", - viewStyle = "floating" - } - vim.g.popup_preview_config = { - border = false, - supportVsnip = true, - supportInfo = true, - delay = 60, - } - - -- enable ddc - vim.fn["ddc#enable"]() - vim.fn["popup_preview#enable"]() - vim.fn["signature_help#enable"]() - - -- setup cmdline - vim.cmd [[ - nnoremap : call CommandlinePre(): - - function! CommandlinePre() abort - let s:prev_buffer_config = ddc#custom#get_buffer() - call ddc#custom#patch_buffer('sources', ['cmdline']) - call ddc#custom#patch_buffer('autoCompleteEvents', ['CmdlineChanged']) - call ddc#custom#patch_buffer('sourceOptions', #{ - \ _: #{ - \ ignoreCase: v:true, - \ matchers: ['matcher_fuzzy'], - \ sorters: ['sorter_fuzzy'], - \ converters: ['converter_fuzzy'] - \ }, - \ cmdline: #{ mark: '[cmd]' }, - \ }) - - autocmd CmdlineLeave ++once call CommandlinePost() - call ddc#enable_cmdline_completion() - endfunction - function! CommandlinePost() abort - call ddc#custom#set_buffer(s:prev_buffer_config) - endfunction - ]] - - -- なんか動かなくなるので後で直す - -- local command_line_post = function(prev_buffer_config) - -- vim.fn["ddc#custom#set_buffer"](prev_buffer_config) - -- end - -- local command_line_pre = function() - -- local prev_buffer_config = vim.fn["ddc#custom#get_buffer"]() - -- vim.fn["ddc#custom#patch_buffer"]("sources", { "cmdline", "cmdline-history" }) - -- vim.fn["ddc#custom#patch_buffer"]("autoCompleteEvents", { "CmdlineChanged" }) - -- vim.fn["ddc#custom#patch_buffer"]("sourceOptions", { - -- _ = { - -- ignoreCase = true, - -- matchers = { "matcher_fuzzy" }, - -- sorters = { "sorter_fuzzy" }, - -- converters = { "converter_fuzzy" }, - -- }, - -- cmdline = { - -- mark = '[cmd]', - -- }, - -- ["cmdline-history"] = { - -- mark = '[history]', - -- }, - -- }) - -- vim.cmd [[ autocmd CmdlineLeave ++once lua command_line_post(prev_buffer_config) ]] - - -- vim.api.nvim_create_autocmd("CmdlineLeave", { - -- pattern = '*', - -- -- once = true, - -- callback = function() - -- command_line_post(prev_buffer_config) - -- end, - -- }) - -- end - -- vim.keymap.set("n", ":", function() command_line_pre() end) - end, - } - - use { - "github/copilot.vim", - event = { "InsertEnter" }, - setup = function() - vim.g.copilot_filetypes = { - gitcommit = true, - markdown = true, - yaml = true, - text = true, - } - vim.g.copilot_no_tab_map = true - end, - config = function() - local keymap = vim.keymap - keymap.set( - "i", - "", - 'copilot#Accept()', - { silent = true, expr = true, script = true, replace_keycodes = false } - ) - keymap.set( - "i", - "", - '(copilot-dismiss)' - ) - -- keymap("i", "", "(copilot-next)") - -- keymap("i", "", "(copilot-previous)") - -- keymap("i", "", "(copilot-dismiss)") - -- keymap("i", "", "(copilot-suggest)") - - local function append_diff() - -- Get the Git repository root directory - local git_dir = vim.fn.FugitiveGitDir() - local git_root = vim.fn.fnamemodify(git_dir, ':h') - -- Get the diff of the staged changes relative to the Git repository root - local diff = vim.fn.system('git -C ' .. git_root .. ' diff --cached') - -- Add a comment character to each line of the diff - local comment_diff = table.concat(vim.tbl_map(function(line) - return '# ' .. line - end, vim.split(diff, '\n')), "\n") - -- Append the diff to the commit message - vim.api.nvim_buf_set_lines(0, -1, -1, false, vim.split(comment_diff, '\n')) - end - vim.api.nvim_create_autocmd({ "BufReadPost" }, { - pattern = "COMMIT_EDITMSG", - callback = append_diff, - }) - end, - } - - -- lsp - use { - "neovim/nvim-lspconfig", - -- event = { "VimEnter" }, - requires = { - { - "williamboman/mason-lspconfig.nvim", - }, - { - "williamboman/mason.nvim", - module = { "lspconfig" }, - } - }, - config = function() - local on_attach = function(_, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - local opts = { noremap = true, silent = true } - buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) - buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) - buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) - buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) - buf_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) - buf_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) - buf_set_keymap("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) - buf_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", opts) - buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) - buf_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) - buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) - buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) - buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) - buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) - buf_set_keymap("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) - buf_set_keymap("n", "f", "lua vim.lsp.buf.format()", opts) - end - - -- local capabilities = vim.lsp.protocol.make_client_capabilities() - local capabilities = require("ddc_nvim_lsp").make_client_capabilities() - capabilities.textDocument.completion.completionItem.snippetSupport = true - - local nvim_lsp = require("lspconfig") - require("mason").setup({ - ui = { - icons = { - package_installed = "✓", - package_pending = "➜", - package_uninstalled = "✗" - } - } - }) - require("mason-lspconfig").setup() - require("mason-lspconfig").setup_handlers { - function(server_name) - local opt = { - on_attach = on_attach, - capabilities = capabilities, - } - if server_name == "gopls" then - opt.settings = { - gopls = { - env = { GOFLAGS = "-tags=integration,wireinject" }, - gofumpt = true, - }, - } - elseif server_name == "denols" then - opt.root_dir = nvim_lsp.util.root_pattern("deno.json") - elseif server_name == "tsserver" then - opt.root_dir = nvim_lsp.util.root_pattern("package.json") - end - nvim_lsp[server_name].setup(opt) - end - } - end - } - -- etc use { "navarasu/onedark.nvim", @@ -681,7 +298,274 @@ require('packer').startup(function(use) "tpope/vim-fugitive", event = "InsertEnter", } + -- denops + use "vim-denops/denops.vim" + use "yuki-yano/fuzzy-motion.vim" + use "lambdalisue/guise.vim" + -- use { + -- "vim-skk/skkeleton", + -- event = { 'InsertEnter' }, + -- config = function() + -- vim.cmd [[ + -- "call skkeleton#config({ 'globalJisyo': '/Users/s11591/.skk/SKK-JISYO.L' }) + + -- "imap (skkeleton-toggle) + -- "cmap (skkeleton-toggle) + -- ]] + -- end, + -- } + -- "use { + -- " "delphinus/skkeleton_indicator.nvim", + -- " config = function() + -- " require 'skkeleton_indicator'.setup {} + -- " end, + -- "} + + -- nvim-cmp + + use { + 'hrsh7th/vim-vsnip', + -- event = { 'InsertEnter' }, + config = function() + vim.cmd [[ + let g:vsnip_snippet_dir = "$HOME/.config/nvim/snippets" + autocmd User PumCompleteDone call vsnip_integ#on_complete_done(g:pum#completed_item) + imap vsnip#jumpable(-1) ? "(vsnip-jump-prev)" : "" + smap vsnip#jumpable(-1) ? "(vsnip-jump-prev)" : "" + + imap vsnip#expandable() ? "(vsnip-expand)" : "" + smap vsnip#expandable() ? "(vsnip-expand)" : "" + imap vsnip#jumpable(1) ? "(vsnip-jump-next)" : "" + smap vsnip#jumpable(1) ? "(vsnip-jump-next)" : "" + imap vsnip#jumpable(-1) ? "(vsnip-jump-prev)" : "" + smap vsnip#jumpable(-1) ? "(vsnip-jump-prev)" : "" + let g:vsnip_filetypes = {} + autocmd BufWritePre lua vim.lsp.buf.format({}, 10000) + ]] + end + } + use { + "hrsh7th/nvim-cmp", + config = function() + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + local icn = icons() + local kind_icons = icn.kind + + local cmp = require("cmp") + cmp.setup({ + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = kind_icons[vim_item.kind] + + if entry.source.name == "copilot" then + vim_item.kind = icn.git.Octoface + vim_item.kind_hl_group = "CmpItemKindCopilot" + end + + if entry.source.name == "emoji" then + vim_item.kind = icn.misc.Smiley + vim_item.kind_hl_group = "CmpItemKindEmoji" + end + + if entry.source.name == "crates" then + vim_item.kind = icn.misc.Package + vim_item.kind_hl_group = "CmpItemKindCrate" + end + + if entry.source.name == "lab.quick_data" then + vim_item.kind = icn.misc.CircuitBoard + vim_item.kind_hl_group = "CmpItemKindConstant" + end + + -- NOTE: order matters + vim_item.menu = ({ + nvim_lsp = "", + nvim_lua = "", + luasnip = "", + buffer = "", + path = "", + emoji = "", + })[entry.source.name] + return vim_item + end, + }, + window = { + completion = cmp.config.window.bordered({ + border = 'double' + }), + documentation = cmp.config.window.bordered({ + border = 'double' + }), + }, + sources = { + { name = "nvim_lsp", priority = 10 }, + { name = 'vsnip', priority = 9 }, + { name = "path", priority = 8 }, + { name = "buffer", priority = 7 }, + { name = "nvim_lsp_signature_help", priority = 6 }, + -- { name = 'copilot', priority = 5 }, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.confirm { select = true }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, { "i", "s" }), + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + }), + experimental = { + ghost_text = true, + }, + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { 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' } + }) + }) + end, + requires = { + -- { + -- 'hrsh7th/nvim-cmp', event = { 'InsertEnter', 'CmdlineEnter' } + -- }, + { + 'hrsh7th/cmp-nvim-lsp', + }, + { + 'hrsh7th/cmp-buffer', event = { 'InsertEnter' } + }, + { + 'hrsh7th/cmp-path', event = { 'InsertEnter' } + }, + { + 'hrsh7th/cmp-cmdline', event = { 'ModeChanged' } + }, + { + 'hrsh7th/cmp-nvim-lsp-signature-help', event = { 'InsertEnter' } + }, + { + 'hrsh7th/cmp-nvim-lsp-document-symbol', event = { 'InsertEnter' } + }, + { + 'hrsh7th/cmp-calc', event = { 'InsertEnter' } + }, + { + 'onsails/lspkind.nvim', event = { 'InsertEnter' } + }, + { + 'hrsh7th/cmp-vsnip', event = { 'InsertEnter' }, + }, + { + "github/copilot.vim", + event = { "InsertEnter" }, + setup = function() + vim.g.copilot_filetypes = { + gitcommit = true, + markdown = true, + yaml = true, + text = true, + } + vim.g.copilot_no_tab_map = true + end, + config = function() + local keymap = vim.keymap + keymap.set( + "i", + "", + 'copilot#Accept()', + { silent = true, expr = true, script = true, replace_keycodes = false } + ) + keymap.set( + "i", + "", + '(copilot-dismiss)' + ) + -- keymap("i", "", "(copilot-next)") + -- keymap("i", "", "(copilot-previous)") + -- keymap("i", "", "(copilot-dismiss)") + -- keymap("i", "", "(copilot-suggest)") + + local function append_diff() + -- Get the Git repository root directory + local git_dir = vim.fn.FugitiveGitDir() + local git_root = vim.fn.fnamemodify(git_dir, ':h') + -- Get the diff of the staged changes relative to the Git repository root + local diff = vim.fn.system('git -C ' .. git_root .. ' diff --cached') + -- Add a comment character to each line of the diff + local comment_diff = table.concat(vim.tbl_map(function(line) + return '# ' .. line + end, vim.split(diff, '\n')), "\n") + -- Append the diff to the commit message + vim.api.nvim_buf_set_lines(0, -1, -1, false, vim.split(comment_diff, '\n')) + end + vim.cmd [[ + autocmd BufReadPost COMMIT_EDITMSG call lua append_diff() + ]] + end, + }, + -- { + -- "hrsh7th/cmp-copilot", + -- event = { "InsertEnter" }, + -- }, + }, + } -- treesitter use { "nvim-treesitter/nvim-treesitter", @@ -694,7 +578,7 @@ require('packer').startup(function(use) highlight = { enable = true, -- disable = { "c", "rust" }, - disable = function(_, buf) + disable = function(lang, buf) local max_filesize = 100 * 1024 -- 100 KB local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) if ok and stats and stats.size > max_filesize then @@ -733,6 +617,7 @@ require('packer').startup(function(use) }, rust = { 'impl_item', + }, terraform = { 'block', @@ -768,7 +653,7 @@ require('packer').startup(function(use) disable_virtual_lines_ft = { 'yaml' }, min_rows = 1, min_rows_ft = {}, - custom_parser = function(node, _, _) + custom_parser = function(node, ft, opts) local utils = require('nvim_context_vt.utils') if node:type() == 'function' then @@ -778,7 +663,7 @@ require('packer').startup(function(use) return '--> ' .. utils.get_node_text(node)[1] end, - custom_validator = function(node, ft, _) + custom_validator = function(node, ft, opts) local default_validator = require('nvim_context_vt.utils').default_validator if default_validator(node, ft) then if node:type() == 'function' then @@ -789,7 +674,7 @@ require('packer').startup(function(use) return true end, - custom_resolver = function(nodes, _, _) + custom_resolver = function(nodes, ft, opts) return nodes[#nodes] end, }) @@ -798,6 +683,253 @@ require('packer').startup(function(use) } } + -- lsp + use { + "neovim/nvim-lspconfig", + requires = { + { + "williamboman/mason-lspconfig.nvim", + }, + { + "williamboman/mason.nvim", + module = { "lspconfig" }, + } + }, + config = function() + local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + local opts = { noremap = true, silent = true } + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) + buf_set_keymap('n', 'gt', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap("n", "gn", "lua vim.lsp.buf.rename()", opts) + buf_set_keymap("n", "gf", "lua vim.lsp.buf.format { async = true }", opts) + buf_set_keymap('n', 'ge', 'lua vim.diagnostic.open_float()', opts) + buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) + buf_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) + buf_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) + buf_set_keymap("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) + buf_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) + buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) + buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) + buf_set_keymap("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) + end + + local capabilities = require('cmp_nvim_lsp').default_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + underline = true, + virtual_text = true, + signs = true, + update_in_insert = false, + } + ) + -- diagnostic sign setting + local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) + end + + local nvim_lsp = require("lspconfig") + require("mason").setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } + }) + require("mason-lspconfig").setup() + require("mason-lspconfig").setup_handlers { + function(server_name) + if server_name == "gopls" then + nvim_lsp[server_name].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }, + settings = { + gopls = { + env = { GOFLAGS = "-tags=integration,wireinject" }, + gofumpt = true, + }, + }, + } + -- elseif server_name == "denols" then + -- nvim_lsp[server_name].setup({ + -- root_dir = lspconfig.util.root_pattern("deno.json"), + -- init_options = { + -- lint = true, + -- unstable = true, + -- suggest = { + -- imports = { + -- hosts = { + -- ["https://deno.land"] = true, + -- ["https://cdn.nest.land"] = true, + -- ["https://crux.land"] = true, + -- }, + -- }, + -- }, + -- }, + -- }) + -- elseif server_name == "tsserver" then + -- nvim_lsp[server_name].setup({ + -- root_dir = lspconfig.util.root_pattern("package.json"), + -- autostart = false, + -- }) + else + nvim_lsp[server_name].setup { + on_attach = on_attach, + } + end + end + } + function OrgImports(wait_ms) + local params = vim.lsp.util.make_range_params() + params.context = { only = { "source.organizeImports" } } + local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, wait_ms) + for _, res in pairs(result or {}) do + for _, r in pairs(res.result or {}) do + if r.edit then + vim.lsp.util.apply_workspace_edit(r.edit, "UTF-8") + else + vim.lsp.buf.execute_command(r.command) + end + end + end + end + + vim.cmd [[ + autocmd User PumCompleteDone call vsnip_integ#on_complete_done(g:pum#completed_item) + ]] + end + } + + -- nvim-dap + use { + "mfussenegger/nvim-dap", + requires = { + { + "rcarriga/nvim-dap-ui", + config = function() + require("dapui").setup({ + icons = { expanded = "▾", collapsed = "▸", current_frame = "▸" }, + mappings = { + -- Use a table to apply multiple mappings + expand = { "", "<2-LeftMouse>" }, + open = "o", + remove = "d", + edit = "e", + repl = "r", + toggle = "t", + }, + -- Expand lines larger than the window + -- Requires >= 0.7 + expand_lines = vim.fn.has("nvim-0.7") == 1, + -- Layouts define sections of the screen to place windows. + -- The position can be "left", "right", "top" or "bottom". + -- The size specifies the height/width depending on position. It can be an Int + -- or a Float. Integer specifies height/width directly (i.e. 20 lines/columns) while + -- Float value specifies percentage (i.e. 0.3 - 30% of available lines/columns) + -- Elements are the elements shown in the layout (in order). + -- Layouts are opened in order so that earlier layouts take priority in window sizing. + layouts = { + { + elements = { + -- Elements can be strings or table with id and size keys. + { id = "scopes", size = 0.25 }, + "breakpoints", + "stacks", + "watches", + }, + size = 40, -- 40 columns + position = "left", + }, + { + elements = { + "repl", + }, + size = 0.25, -- 25% of total lines + position = "bottom", + }, + }, + controls = { + -- Requires Neovim nightly (or 0.8 when released) + enabled = true, + -- Display controls in this element + element = "repl", + icons = { + pause = "", + play = "", + step_into = "", + step_over = "", + step_out = "", + step_back = "", + run_last = "↻", + terminate = "□", + }, + }, + floating = { + max_height = nil, -- These can be integers or a float between 0 and 1. + max_width = nil, -- Floats will be treated as percentage of your screen. + border = "single", -- Border style. Can be "single", "double" or "rounded" + mappings = { + close = { "q", "" }, + }, + }, + windows = { indent = 1 }, + render = { + max_type_length = nil, -- Can be integer or nil. + max_value_lines = 100, -- Can be integer or nil. + } + }) + end, + }, + { + "leoluz/nvim-dap-go", + config = function() + require("dap-go").setup { + dap_configurations = { + { + -- Must be "go" or it will be ignored by the plugin + type = "go", + name = "Attach remote", + mode = "remote", + request = "attach", + }, + }, + -- delve configurations + delve = { + -- the path to the executable dlv which will be used for debugging. + -- by default, this is the "dlv" executable on your PATH. + path = "dlv", + -- time to wait for delve to initialize the debug session. + -- default to 20 seconds + initialize_timeout_sec = 20, + -- a string that defines the port to start delve debugger. + -- default to string "${port}" which instructs nvim-dap + -- to start the process in a random available port + port = "${port}", + -- additional args to pass to dlv + args = {} + }, + } + end, + }, + }, + } + -- go use { "kyoh86/vim-go-coverage", ft = "go" } use { "mattn/vim-goaddtags", ft = "go" } @@ -825,7 +957,6 @@ end) local keymap = vim.keymap keymap.set("n", "s", ":FuzzyMotion") keymap.set("n", "", ":q!") -keymap.set("n", "", ":w") -- buffer keymap.set("n", ",", ":bprev") @@ -940,6 +1071,236 @@ end -- }}} +-- {{{ icons + +vim.g.use_nerd_icons = false +function icons() + if vim.fn.has "mac" == 1 or vim.g.use_nerd_icons then + return { + kind = { + -- Text = "", + Text = "✏︎", + Method = "m", + Function = "λ", + Constructor = "", + -- Method = "", + -- Function = "", + -- Constructor = "", + Field = "", + -- Variable = "", + Variable = "", + -- Class = "", + Class = "c", + Interface = "", + Module = "", + -- Module = "", + Property = "", + Unit = "", + -- Value = "", + Value = "v", + Enum = "", + -- Keyword = "", + Keyword = "", + Snippet = "", + -- Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", + }, + type = { + -- Array = "", + Array = "🗃", + Number = "", + -- String = "", + String = "📖", + Boolean = "蘒", + -- Object = "", + Object = "🗂", + }, + documents = { + File = "", + Files = "", + Folder = "", + OpenFolder = "", + }, + git = { + Add = "", + Mod = "", + Remove = "", + Ignore = "", + Rename = "", + Diff = "", + Repo = "", + Octoface = "", + }, + ui = { + ArrowClosed = "", + ArrowOpen = "", + Lock = "", + Circle = "", + BigCircle = "", + BigUnfilledCircle = "", + Close = "", + NewFile = "", + Search = "", + Lightbulb = "", + Project = "", + Dashboard = "", + History = "", + Comment = "", + Bug = "", + Code = "", + Telescope = "", + Gear = "", + Package = "", + List = "", + SignIn = "", + SignOut = "", + Check = "", + Fire = "", + Note = "", + BookMark = "", + Pencil = "", + -- ChevronRight = "", + ChevronRight = ">", + Table = "", + Calendar = "", + CloudDownload = "", + }, + diagnostics = { + Error = "", + Warning = "", + Information = "", + Question = "", + Hint = "", + }, + misc = { + Robot = "ﮧ", + Squirrel = "", + Tag = "", + Watch = "", + Smiley = "ﲃ", + Package = "", + CircuitBoard = "", + }, + } + else + --   פּ ﯟ   蘒練 some other good icons + return { + kind = { + 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 = " ", + Misc = " ", + }, + type = { + Array = " ", + Number = " ", + String = " ", + Boolean = " ", + Object = " ", + }, + documents = { + File = " ", + Files = " ", + Folder = " ", + OpenFolder = " ", + }, + git = { + Add = " ", + Mod = " ", + Remove = " ", + Ignore = " ", + Rename = " ", + Diff = " ", + Repo = " ", + Octoface = " ", + }, + ui = { + ArrowClosed = "", + ArrowOpen = "", + Lock = " ", + Circle = " ", + BigCircle = " ", + BigUnfilledCircle = " ", + Close = " ", + NewFile = " ", + Search = " ", + Lightbulb = " ", + Project = " ", + Dashboard = " ", + History = " ", + Comment = " ", + Bug = " ", + Code = " ", + Telescope = " ", + Gear = " ", + Package = " ", + List = " ", + SignIn = " ", + SignOut = " ", + NoteBook = " ", + Check = " ", + Fire = " ", + Note = " ", + BookMark = " ", + Pencil = " ", + ChevronRight = "", + Table = " ", + Calendar = " ", + CloudDownload = " ", + }, + diagnostics = { + Error = " ", + Warning = " ", + Information = " ", + Question = " ", + Hint = " ", + }, + misc = { + Robot = " ", + Squirrel = " ", + Tag = " ", + Watch = " ", + Smiley = " ", + Package = " ", + CircuitBoard = " ", + }, + } + end +end + +-- }}} + -- vim.cmd [[ -- set runtimepath^=~/.ghq/github.com/ucpr/denops-covcolor -- -- knotmirror 0.0.1