diff --git a/nvim/dpp.ts b/nvim/dpp.ts new file mode 100644 index 0000000..bfe5c4a --- /dev/null +++ b/nvim/dpp.ts @@ -0,0 +1,193 @@ +import { + BaseConfig, + ContextBuilder, + Dpp, + Plugin, +} from "https://deno.land/x/dpp_vim@v0.0.5/types.ts"; +import { Denops, fn } from "https://deno.land/x/dpp_vim@v0.0.5/deps.ts"; + +export class Config extends BaseConfig { + override async config(args: { + denops: Denops; + contextBuilder: ContextBuilder; + basePath: string; + dpp: Dpp; + }): Promise<{ + plugins: Plugin[]; + stateLines: string[]; + }> { + args.contextBuilder.setGlobal({ + protocols: ["git"], + }); + + type Toml = { + hooks_file?: string; + ftplugins?: Record; + plugins?: Plugin[]; + }; + + type LazyMakeStateResult = { + plugins: Plugin[]; + stateLines: string[]; + }; + + const [context, options] = await args.contextBuilder.get(args.denops); + const dotfilesDir = "~/.config/nvim/"; + + const tomls: Toml[] = []; + tomls.push( + await args.dpp.extAction( + args.denops, + context, + options, + "toml", + "load", + { + path: await fn.expand(args.denops, dotfilesDir + "tomls/dein.toml"), + options: { + lazy: false, + }, + }, + ) as Toml, + ); + + tomls.push( + await args.dpp.extAction( + args.denops, + context, + options, + "toml", + "load", + { + path: await fn.expand(args.denops, dotfilesDir + "tomls/dein_lazy.toml"), + options: { + lazy: true, + }, + }, + ) as Toml, + ); + + tomls.push( + await args.dpp.extAction( + args.denops, + context, + options, + "toml", + "load", + { + path: await fn.expand(args.denops, dotfilesDir + "tomls/ddu.toml"), + options: { + lazy: true, + }, + }, + ) as Toml, + ); + + tomls.push( + await args.dpp.extAction( + args.denops, + context, + options, + "toml", + "load", + { + path: await fn.expand(args.denops, dotfilesDir + "tomls/treesitter.toml"), + options: { + lazy: false, + }, + }, + ) as Toml, + ); + + tomls.push( + await args.dpp.extAction( + args.denops, + context, + options, + "toml", + "load", + { + path: await fn.expand(args.denops, dotfilesDir + "tomls/go.toml"), + options: { + lazy: true, + }, + }, + ) as Toml, + ); + + tomls.push( + await args.dpp.extAction( + args.denops, + context, + options, + "toml", + "load", + { + path: await fn.expand(args.denops, dotfilesDir + "tomls/theme.toml"), + options: { + lazy: true, + }, + }, + ) as Toml, + ); + + tomls.push( + await args.dpp.extAction( + args.denops, + context, + options, + "toml", + "load", + { + path: await fn.expand(args.denops, dotfilesDir + "tomls/cmp.toml"), + options: { + lazy: true, + }, + }, + ) as Toml, + ); + + const recordPlugins: Record = {}; + const ftplugins: Record = {}; + const hooksFiles: string[] = []; + + tomls.forEach((toml) => { + + for (const plugin of toml.plugins) { + recordPlugins[plugin.name] = plugin; + } + + if (toml.ftplugins) { + for (const filetype of Object.keys(toml.ftplugins)) { + if (ftplugins[filetype]) { + ftplugins[filetype] += `\n${toml.ftplugins[filetype]}`; + } else { + ftplugins[filetype] = toml.ftplugins[filetype]; + } + } + } + + if (toml.hooks_file) { + hooksFiles.push(toml.hooks_file); + } + }); + + const lazyResult = await args.dpp.extAction( + args.denops, + context, + options, + "lazy", + "makeState", + { + plugins: Object.values(recordPlugins), + }, + ) as LazyMakeStateResult; + + console.log(lazyResult); + + return { + plugins: lazyResult.plugins, + stateLines: lazyResult.stateLines, + }; + } +} diff --git a/nvim/init.lua b/nvim/init.lua index ba6c29f..2ff109f 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,6 +1,5 @@ -vim.loader.enable() +-- vim.loader.enable() --- {{{ general options local options = { -- file encoding encoding = "utf-8", @@ -61,1171 +60,81 @@ for k, v in pairs(options) do end local global_options = { - loaded_gzip = 1, - loaded_tar = 1, - loaded_tarPlugin = 1, - loaded_zip = 1, - loaded_zipPlugin = 1, - loaded_rrhelper = 1, - loaded_2html_plugin = 1, - loaded_vimball = 1, - loaded_vimballPlugin = 1, - loaded_getscript = 1, - loaded_getscriptPlugin = 1, + loaded_2html_plugin = true, + loaded_gzip = true, + loaded_tar = true, + loaded_tarPlugin = true, + loaded_zip = true, + loaded_zipPlugin = true, + loaded_vimball = true, + loaded_vimballPlugin = true, + loaded_netrw = true, + loaded_netrwPlugin = true, + loaded_netrwSettings = true, + loaded_netrwFileHandlers = true, + loaded_getscript = true, + loaded_getscriptPlugin = true, + loaded_man = true, + loaded_matchit = true, + loaded_matchparen = true, + loaded_shada_plugin = true, + loaded_spellfile_plugin = true, + loaded_tutor_mode_plugin = true, + did_install_default_menus = true, + did_install_syntax_menu = true, + skip_loading_mswin = true, + did_indent_on = true, + did_load_ftplugin = true, + loaded_rrhelper = true, } + for k, v in pairs(global_options) do vim.g[k] = v end --- }}} - --- {{{ plugin - -local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) - vim.cmd [[packadd packer.nvim]] - return true - end - return false -end - -local packer_bootstrap = ensure_packer() -require('packer').startup(function(use) - use 'wbthomason/packer.nvim' - - use { - "Shougo/ddu.vim", - -- event = { "VimEnter" }, - requires = { - -- source - "Shougo/ddu-source-file", - "Shougo/ddu-source-file_rec", - "Shougo/ddu-source-action", - "matsui54/ddu-source-file_external", - "shun/ddu-source-rg", - "4513ECHO/ddu-source-colorscheme", - -- kind - "Shougo/ddu-kind-file", - -- ui - "Shougo/ddu-ui-ff", - -- filter - "Shougo/ddu-filter-matcher_substring", - "uga-rosa/ddu-filter-converter_devicon", - "yuki-yano/ddu-filter-fzf", - -- etc - "Shougo/ddu-commands.vim", - }, - config = function() - vim.fn["ddu#custom#patch_global"]({ - ui = "ff", - uiParams = { - ff = { - filterFloatingPosition = "bottom", - filterSplitDirection = "floating", - floatingBorder = "rounded", - previewFloating = true, - previewFloatingBorder = "rounded", - previewFloatingTitle = "Preview", - previewSplit = "horizontal", - prompt = "> ", - split = "floating", - startFilter = true, - } - }, - sourceOptions = { - _ = { - matchers = { "matcher_fzf" }, - sorters = { "sorter_fzf" }, - converters = { "converter_devicon" }, - ignoreCase = true, - }, - }, - kindOptions = { - action = { - defaultAction = "do", - }, - }, - }) - vim.fn["ddu#custom#patch_local"]("file_recursive", { - sources = { - { - name = { "file_rec" }, - options = { - converters = { - "converter_devicon", - }, - }, - params = { - ignoredDirectories = { "node_modules", ".git", ".vscode" }, - }, - }, - }, - kindOptions = { - file = { - defaultAction = "open", - }, - }, - }) - vim.fn["ddu#custom#patch_local"]("grep", { - sourceParams = { - rg = { - args = { "--column", "--no-heading", "--color", "never" }, - }, - }, - kindOptions = { - file = { - defaultAction = "open", - }, - }, - uiParams = { - ff = { - startFilter = false, - previewFloating = false, - previewSplit = "vertical", - }, - }, - }) - vim.api.nvim_create_autocmd("FileType",{ - pattern = "ddu-ff", - callback = function() - local opts = { noremap = true, silent = true, buffer = true } - vim.keymap.set({ "n" }, "q", [[call ddu#ui#do_action("quit")]], opts) - vim.keymap.set({ "n" }, "a", [[call ddu#ui#do_action("chooseAction")]], opts) - vim.keymap.set({ "n" }, "", [[call ddu#ui#do_action("itemAction")]], opts) - vim.keymap.set({ "n" }, "", [[call ddu#ui#do_action("itemAction", {'params': {'command': 'vsplit'}})]], opts) - vim.keymap.set({ "n" }, "", [[call ddu#ui#do_action("itemAction", {'params': {'command': 'split'}})]], opts) - vim.keymap.set({ "n" }, "i", [[call ddu#ui#do_action("openFilterWindow")]], opts) - vim.keymap.set({ "n" }, "P", [[call ddu#ui#do_action("togglePreview")]], opts) - end, - }) - vim.api.nvim_create_autocmd("FileType",{ - pattern = "ddu-ff-filter", - callback = function() - local opts = { noremap = true, silent = true, buffer = true } - vim.keymap.set({ "n", "i" }, "", [[close]], opts) - end, - }) - vim.fn["ddu#custom#patch_local"]("colorscheme", { - sources = { - { - name = { "colorscheme" }, - }, - }, - kindOptions = { - colorscheme = { - defaultAction = "set", - } - } - }) - - vim.keymap.set("n", "ff", "call ddu#start(#{name:'file_recursive'})") - vim.keymap.set("n", "g", "call ddu#start(#{name:'grep', sources: [#{ name: 'rg', params: #{ input: expand('') } }]})") - end, - } - - -- etc - use { - "navarasu/onedark.nvim", - event = { "VimEnter" }, - config = function() - require("onedark").setup { - style = "warmer", - transparent = true, -- Show/hide background - term_colors = true, -- Change terminal color as per the selected theme style - ending_tildes = false, -- Show the end-of-buffer tildes. By default they are hidden - cmp_itemkind_reverse = false, -- reverse item kind highlights in cmp menu - - code_style = { - comments = 'italic', - keywords = 'none', - functions = 'none', - strings = 'none', - variables = 'none' - }, - - -- Custom Highlights -- - colors = {}, -- Override default colors - highlights = {}, -- Override highlight groups - - -- Plugins Config -- - diagnostics = { - darker = true, -- darker colors for diagnostic - undercurl = true, -- use undercurl instead of underline for diagnostics - background = true, -- use background color for virtual text - }, - } - require("onedark").load() - end - } - use { "ntpeters/vim-better-whitespace", event = { "VimEnter" } } - use { "simeji/winresizer", event = { "VimEnter" } } - use { "markonm/traces.vim", opt = true } - use { - "cohama/lexima.vim", - event = { "InsertEnter" }, - } - use "Shougo/context_filetype.vim" - use { - "mattn/vim-sonictemplate", - cmd = { - "Template", - }, - setup = function() - vim.g.sonictemplate_vim_template_dir = { "$HOME/.vim/template" } - end - } - use { - "numToStr/FTerm.nvim", - event = { "VimEnter" }, - module = { "FTerm" }, - setup = function() - vim.keymap.set("n", "T", 'lua require("FTerm").toggle()') - end, - config = function() - require 'FTerm'.setup({ - border = 'double', - dimensions = { - height = 0.9, - width = 0.9, - }, - }) - end - } - use { - "unblevable/quick-scope", - config = function() - vim.cmd [[ - augroup qs_colors - autocmd! - autocmd ColorScheme * highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=155 cterm=underline - autocmd ColorScheme * highlight QuickScopeSecondary guifg='#5fffff' gui=underline ctermfg=81 cterm=underline - augroup END - ]] - end, - setup = function() - vim.g.qs_hi_priority = 2 - vim.g.qs_max_chars = 80 - vim.g.qs_lazy_highlight = 0 - vim.g.qs_buftype_blacklist = { "terminal", "nofile" } - end, - } - use { - "nvim-tree/nvim-tree.lua", - cmd = "NvimTreeToggle", - setup = function() - --vim.keymap.set("n", "", 'NvimTreeToggle') - end, - config = function() - vim.g.loaded_netrw = 1 - vim.g.loaded_netrwPlugin = 1 - - require("nvim-tree").setup({ - sort_by = "case_sensitive", - renderer = { - group_empty = true, - }, - filters = { - dotfiles = true, - }, - }) - end - } - use { - "almo7aya/openingh.nvim", - cmd = { "OpenInGHFile", "OpenInGHRepo" }, - } - use { - "tpope/vim-fugitive", - event = "InsertEnter", - } - use { - "lewis6991/gitsigns.nvim", - event = { "FocusLost", "CursorHold", "VimEnter" }, - config = function() - require('gitsigns').setup { - signs = { - add = { text = '│' }, - change = { text = '│' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - untracked = { text = '┆' }, - }, - signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` - numhl = false, -- Toggle with `:Gitsigns toggle_numhl` - linehl = false, -- Toggle with `:Gitsigns toggle_linehl` - word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` - watch_gitdir = { - follow_files = true - }, - attach_to_untracked = true, - current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` - current_line_blame_opts = { - virt_text = true, - virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' - delay = 1000, - ignore_whitespace = false, - }, - current_line_blame_formatter = ', - ', - sign_priority = 6, - update_debounce = 100, - status_formatter = nil, -- Use default - max_file_length = 40000, -- Disable if file is longer than this (in lines) - preview_config = { - -- Options passed to nvim_open_win - border = 'double', - style = 'minimal', - relative = 'cursor', - row = 0, - col = 1 - }, - yadm = { - enable = false - }, - } - end - } - use { - "jackMort/ChatGPT.nvim", - cmd = { "ChatGPT", "ChatGPTRun", "ChatGPTActAs", "ChatGPTEditWithInstructions" }, - config = function() - require("chatgpt").setup({ - api_key_cmd = "op read op://personal/OpenAI_API_Key/api_key --no-newline", - }) - end, - requires = { - "MunifTanjim/nui.nvim", - "nvim-lua/plenary.nvim", - "nvim-telescope/telescope.nvim" - }, - } - use { - "tpope/vim-surround", - 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, - -- "} - use { - "kamykn/spelunker.vim", - -- event = { "VimEnter" }, - config = function() - vim.cmd [[ - highlight SpelunkerSpellBad cterm=underline ctermfg=247 gui=underline guifg=#9e9e9e - highlight SpelunkerComplexOrCompoundWord cterm=underline ctermfg=NONE gui=underline guifg=NONE - ]] - - vim.g.enable_spelunker_vim = 1 - vim.g.spelunker_check_type = 2 - end - } - - -- nvim-cmp - 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 = "emoji", priority = 1 }, - }, - 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/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' } - }, - { - 'hrsh7th/cmp-emoji', event = { 'InsertEnter' }, - }, - { - 'onsails/lspkind.nvim', event = { 'InsertEnter' } - }, - { - 'hrsh7th/cmp-vsnip', - event = { 'InsertEnter' }, - requires = { - { - 'hrsh7th/vim-vsnip', - event = { 'VimEnter' }, - setup = function() - vim.g.vsnip_snippet_dir = "$HOME/.config/nvim/snippets" - -- vim.g.vsnip_filetypes = {} - end, - config = function() - vim.cmd [[ - autocmd User PumCompleteDone call vsnip_integ#on_complete_done(g:pum#completed_item) - autocmd BufWritePre lua vim.lsp.buf.format({}, 10000) - ]] - end - }, - }, - }, - { - "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, - }, - }, - } +local dpp_base = "$XDG_CACHE_HOME/dpp/" +local dpp_repo = dpp_base .. "repos/" +local dpp_src = dpp_repo .. "github.com/Shougo/dpp.vim" +vim.opt.runtimepath:prepend(dpp_src) - -- treesitter - use { - "nvim-treesitter/nvim-treesitter", - event = { "VimEnter" }, - run = ":TSUpdate", - config = function() - require 'nvim-treesitter.configs'.setup { - ensure_installed = { "lua", "go", "python", "bash", "typescript", "yaml", "toml", "json", "vim", "hcl" }, - sync_install = false, - auto_install = true, - highlight = { - enable = true, - -- filesize で現状そんなに問題がないので一旦コメントアウトして様子を見る。問題なかったら完全に消す。 - -- disable = function(_, 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 - -- return true - -- end - -- end, - additional_vim_regex_highlighting = false, - }, - indent = { - enable = true, - } - } - vim.cmd("hi TreesitterContextBottom gui=underline guisp=Grey") - end, - requires = { - { - "m-demare/hlargs.nvim", - event = { "VimEnter" }, - config = function() - require('hlargs').setup() - end - }, - { - "nvim-treesitter/nvim-treesitter-context", - event = { "VimEnter" }, - config = function() - require 'treesitter-context'.setup { - patterns = { - default = { - 'class', - 'function', - 'method', - 'interface', - 'struct', - }, - haskell = { - 'adt' - }, - rust = { - 'impl_item', +local dpp = require("dpp") - }, - terraform = { - 'block', - 'object_elem', - 'attribute', - }, - markdown = { - 'section', - }, - json = { - 'pair', - }, - typescript = { - 'export_statement', - }, - yaml = { - 'block_mapping_pair', - }, - }, - } - end - }, - } - } - - -- 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 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", "gvd", ":vsplua vim.lsp.buf.definition()", opts) - buf_set_keymap("n", "gsd", ":splua 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 = "ℹ" } - 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) - local opt = { - on_attach = on_attach, - capabilities = capabilities, - } - if server_name == "gopls" then - opt.settings = { - gopls = { - env = { GOFLAGS = "-tags=integration,!integration,wireinject" }, - gofumpt = true, - }, - } - elseif server_name == "tsserver" then - -- package.json と deno.json があるディレクトリ場合は tsserver を使う - opt.root_dir = nvim_lsp.util.root_pattern("package.json") - elseif server_name == "denols" then - opt.root_dir = nvim_lsp.util.root_pattern("deno.json") - end - nvim_lsp[server_name].setup(opt) - end - } - end - } - - -- go - use { "kyoh86/vim-go-coverage", ft = "go" } - use { "mattn/vim-goaddtags", ft = "go" } - use { "mattn/vim-goimpl", ft = "go" } - use { "mattn/vim-gomod", ft = "go" } - use { - "mattn/vim-goimports", - ft = "go", - setup = function() - vim.g.goimports = 1 - end, - } - - -- Automatically set up your configuration after cloning packer.nvim - -- Put this at the end after all plugins - if packer_bootstrap then - require('packer').sync() - end -end) - ---- }}} - --- {{{ keybind - -local keymap = vim.keymap -keymap.set("n", "s", ":FuzzyMotion") -keymap.set("n", "", ":q!") - --- buffer -keymap.set("n", ",", ":bprev") -keymap.set("n", ".", ":bnext") - --- tab -keymap.set("n", "tl", ":tabn") -keymap.set("n", "th", ":tabp") -keymap.set("n", "", ":tabnew") - --- window -keymap.set("n", "", "h") -keymap.set("n", "", "j") -keymap.set("n", "", "k") -keymap.set("n", "", "l") - --- terminal mode -keymap.set("t", "", "") -keymap.set("t", "", "exit") -keymap.set("t", "", "") - --- custom script -keymap.set("n", "got", ":lua go_test()") - --- }}} - --- {{{ autocmd - -vim.api.nvim_create_user_command("Sterm", function() vim.cmd(":split | resize 20 | term ") end, {}) -vim.api.nvim_create_user_command("Vterm", function() vim.cmd [[ :vsplit | term ]] end, {}) - -vim.api.nvim_create_autocmd("FileType", { - pattern = { "*.py" }, - command = "set tabstop=4 shiftwidth=4 expandtab", -}) -vim.api.nvim_create_autocmd("FileType", { - pattern = { "*.go" }, - command = "setl ts=4 sw=4 noet", -}) - -vim.cmd [[ - autocmd FileType go setl ts=4 sw=4 noet -]] - --- }}} - --- {{{ go-test -function get_split_window_type() - local id = vim.fn.win_getid() - local width = vim.fn.winwidth(id) - local height = vim.fn.winheight(id) * 2.1 +local dpp_exts = { + "github.com/Shougo/dpp-ext-toml", + "github.com/Shougo/dpp-ext-lazy", + "github.com/Shougo/dpp-ext-installer", + "github.com/Shougo/dpp-protocol-git", +} - if height > width then - return "split" - else - return "vsplit" - end +for _, ext in ipairs(dpp_exts) do + vim.opt.runtimepath:append(dpp_repo .. ext) end -function get_cursor_byte_offset() - return vim.fn.line2byte(vim.fn.line('.')) + (vim.fn.col('.') - 2) -end +vim.g["denops#debug"] = 1 -- note: cmdheight=0 のときはEnterで進めないといけない -function go_test() - local test_info = vim.fn.json_decode( - vim.fn.system( - string.format("go-test-name -pos %d -file %s", get_cursor_byte_offset(), vim.fn.expand("%")) - ) - ) - for _, v in ipairs(vim.api.nvim_list_bufs()) do - if vim.fn.bufname(v) == "vim-go-test-func" then - vim.fn.execute(string.format("bwipe! %d", v)) - end - end +if dpp.load_state(dpp_base) then + local denops_src = dpp_repo .. "github.com/vim-denops/denops.vim" + vim.opt.runtimepath:prepend(denops_src) - local dir = vim.fn.expand("%:p:h") - if #(test_info["sub_test_names"]) > 0 then - -- TODO: Investigate why sub test name is nil when accessed by sub_test_name[0] - local sub_test_name = "" - for _, v in ipairs(test_info["sub_test_names"]) do - sub_test_name = v + local dpp_config = "$XDG_CONFIG_HOME/nvim/dpp.ts" + vim.api.nvim_create_autocmd("User", { + pattern = "DenopsReady", + callback = function () + vim.notify("failed to load_state") + dpp.make_state(dpp_base, dpp_config) end - cmd = string.format( - "go test -coverprofile='/tmp/go-coverage.out' -json -v -count=1 -v -race -run='^%s$'/'^%s$' $(go list %s) 2>&1 | tee /tmp/gotest.log | gotestfmt" - , test_info.test_func_name, sub_test_name, dir - ) - else - cmd = string.format( - "go test -coverprofile='/tmp/go-coverage.out' -json -v -count=1 -v -race -run='^%s$' $(go list %s) 2>&1 | tee /tmp/gotest.log | gotestfmt" - , test_info.test_func_name, dir - ) - end - - local st = get_split_window_type() - vim.fn.execute(string.format("%s gotest", st)) - - if split == "split" then - vim.cmd [[ - execute(printf('resize %s', floor(&lines * 0.3))) - ]] - end - - vim.call("termopen", cmd) - vim.cmd [[ - setlocal bufhidden=delete - setlocal noswapfile - setlocal nobuflisted - file vim-go-test-func - wincmd p - ]] + }) 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 +local function install() + vim.fn["dpp#async_ext_action"]('installer', 'install') end --- }}} +local function update() + vim.fn["dpp#async_ext_action"]('installer', 'update') +end --- vim.cmd [[ --- set runtimepath^=~/.ghq/github.com/ucpr/denops-covcolor --- --- let g:denops#debug = 1 --- ]] +vim.api.nvim_create_user_command('DppInstall', install, {}) +vim.api.nvim_create_user_command('DppUpdate', update, {}) diff --git a/nvim/tomls/cmp.toml b/nvim/tomls/cmp.toml new file mode 100644 index 0000000..f970d50 --- /dev/null +++ b/nvim/tomls/cmp.toml @@ -0,0 +1,545 @@ +[[plugins]] +repo = 'hrsh7th/nvim-cmp' +on_event = 'VimEnter' +lua_source = ''' + 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 + + 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 + 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 + + 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 = "emoji", priority = 1 }, + }, + 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' } + }) + }) +''' + +[[plugins]] +repo = 'hrsh7th/cmp-nvim-lsp' +on_event = 'VimEnter' + +[[plugins]] +repo = 'hrsh7th/cmp-buffer' +on_event = 'VimEnter' + +[[plugins]] +repo = 'hrsh7th/cmp-path' +on_event = 'VimEnter' + +[[plugins]] +repo = 'hrsh7th/cmp-cmdline' +on_event = 'VimEnter' + +[[plugins]] +repo = 'hrsh7th/cmp-nvim-lsp-signature-help' +on_event = 'VimEnter' + +[[plugins]] +repo = 'hrsh7th/cmp-nvim-lsp-document-symbol' +on_event = 'VimEnter' + +[[plugins]] +repo = 'onsails/lspkind.nvim' +on_event = 'VimEnter' + +[[plugins]] +repo = 'hrsh7th/vim-vsnip' +on_event = 'VimEnter' +lua_source = ''' + vim.g.vsnip_snippet_dir = "$HOME/.config/nvim/snippets" +''' +lua_post_source = ''' + vim.cmd [[ + autocmd User PumCompleteDone call vsnip_integ#on_complete_done(g:pum#completed_item) + autocmd BufWritePre lua vim.lsp.buf.format({}, 10000) + ]] +''' + +[[plugins]] +repo = 'hrsh7th/cmp-vsnip' +on_event = 'VimEnter' + +[[plugins]] +repo = 'github/copilot.vim' +on_event = 'VimEnter' +lua_source = ''' + vim.g.copilot_filetypes = { + gitcommit = true, + markdown = true, + yaml = true, + text = true, + } + vim.g.copilot_no_tab_map = true + + vim.keymap.set( + "i", + "", + 'copilot#Accept()', + { silent = true, expr = true, script = true, replace_keycodes = false } + ) + vim.keymap.set( + "i", + "", + '(copilot-dismiss)' + ) +''' +lua_post_source = ''' + 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() + ]] +''' + +[[plugins]] +repo = 'williamboman/mason-lspconfig.nvim' +on_event = 'VimEnter' + +[[plugins]] +repo = 'williamboman/mason.nvim' +on_event = 'VimEnter' +lua_post_source = ''' + require("mason").setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } + }) +''' + +[[plugins]] +repo = 'neovim/nvim-lspconfig' +on_event = 'VimEnter' +depends = ['mason-lspconfig.nvim', 'cmp-nvim-lsp'] +lua_post_source = ''' + local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(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", "gvd", ":vsplua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "gsd", ":splua 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-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,!integration,wireinject" }, + gofumpt = true, + }, + } + elseif server_name == "tsserver" then + -- package.json と deno.json があるディレクトリ場合は tsserver を使う + opt.root_dir = nvim_lsp.util.root_pattern("package.json") + elseif server_name == "denols" then + opt.root_dir = nvim_lsp.util.root_pattern("deno.json") + end + nvim_lsp[server_name].setup(opt) + end + } +''' diff --git a/nvim/tomls/ddu.toml b/nvim/tomls/ddu.toml new file mode 100644 index 0000000..209b303 --- /dev/null +++ b/nvim/tomls/ddu.toml @@ -0,0 +1,167 @@ +[[plugins]] +repo = 'Shougo/ddu.vim' +on_event = 'VimEnter' +lua_add = ''' + vim.fn["ddu#custom#patch_global"]({ + ui = "ff", + uiParams = { + ff = { + filterFloatingPosition = "bottom", + filterSplitDirection = "floating", + floatingBorder = "rounded", + previewFloating = true, + previewFloatingBorder = "rounded", + previewFloatingTitle = "Preview", + previewSplit = "horizontal", + prompt = "> ", + split = "floating", + startFilter = true, + } + }, + sourceOptions = { + _ = { + matchers = { "matcher_fzf" }, + sorters = { "sorter_fzf" }, + converters = { "converter_devicon" }, + ignoreCase = true, + }, + }, + kindOptions = { + action = { + defaultAction = "do", + }, + }, + }) + vim.fn["ddu#custom#patch_local"]("file_recursive", { + sources = { + { + name = { "file_rec" }, + options = { + converters = { + "converter_devicon", + }, + }, + params = { + ignoredDirectories = { "node_modules", ".git", ".vscode" }, + }, + }, + }, + kindOptions = { + file = { + defaultAction = "open", + }, + }, + }) + vim.fn["ddu#custom#patch_local"]("grep", { + sourceParams = { + rg = { + args = { "--column", "--no-heading", "--color", "never" }, + }, + }, + kindOptions = { + file = { + defaultAction = "open", + }, + }, + uiParams = { + ff = { + startFilter = false, + previewFloating = false, + previewSplit = "vertical", + }, + }, + }) + vim.api.nvim_create_autocmd("FileType",{ + pattern = "ddu-ff", + callback = function() + local opts = { noremap = true, silent = true, buffer = true } + vim.keymap.set({ "n" }, "q", [[call ddu#ui#do_action("quit")]], opts) + vim.keymap.set({ "n" }, "a", [[call ddu#ui#do_action("chooseAction")]], opts) + vim.keymap.set({ "n" }, "", [[call ddu#ui#do_action("itemAction")]], opts) + vim.keymap.set({ "n" }, "", [[call ddu#ui#do_action("itemAction", {'params': {'command': 'vsplit'}})]], opts) + vim.keymap.set({ "n" }, "", [[call ddu#ui#do_action("itemAction", {'params': {'command': 'split'}})]], opts) + vim.keymap.set({ "n" }, "i", [[call ddu#ui#do_action("openFilterWindow")]], opts) + vim.keymap.set({ "n" }, "P", [[call ddu#ui#do_action("togglePreview")]], opts) + end, + }) + vim.api.nvim_create_autocmd("FileType",{ + pattern = "ddu-ff-filter", + callback = function() + local opts = { noremap = true, silent = true, buffer = true } + vim.keymap.set({ "n", "i" }, "", [[close]], opts) + end, + }) + vim.fn["ddu#custom#patch_local"]("colorscheme", { + sources = { + { + name = { "colorscheme" }, + }, + }, + kindOptions = { + colorscheme = { + defaultAction = "set", + } + } + }) + + vim.keymap.set("n", "ff", "call ddu#start(#{name:'file_recursive'})") + vim.keymap.set("n", "g", "call ddu#start(#{name:'grep', sources: [#{ name: 'rg', params: #{ input: expand('') } }]})") +''' + +### DDU SOURCE ### + +[[plugins]] +repo = 'Shougo/ddu-source-file' +on_source = 'ddu.vim' + +[[plugins]] +repo = 'Shougo/ddu-source-file_rec' +on_source = 'ddu.vim' + +[[plugins]] +repo = 'Shougo/ddu-source-action' +on_source = 'ddu.vim' + +[[plugins]] +repo = 'matsui54/ddu-source-file_external' +on_source = 'ddu.vim' + +[[plugins]] +repo = 'shun/ddu-source-rg' +on_source = 'ddu.vim' + +[[plugins]] +repo = '4513ECHO/ddu-source-colorscheme' +on_source = 'ddu.vim' + +### DDU KIND ### + +[[plugins]] +repo = 'Shougo/ddu-kind-file' +on_source = 'ddu.vim' + +### DDU UI ### + +[[plugins]] +repo = 'Shougo/ddu-ui-ff' +on_source = 'ddu.vim' + +### DDU FILTER ### + +[[plugins]] +repo = 'Shougo/ddu-filter-matcher_substring' +on_source = 'ddu.vim' + +[[plugins]] +repo = 'uga-rosa/ddu-filter-converter_devicon' +on_source = 'ddu.vim' + +[[plugins]] +repo = 'yuki-yano/ddu-filter-fzf' +on_source = 'ddu.vim' + +### ETC ### + +[[plugins]] +repo = 'Shougo/ddu-commands.vim' +on_source = 'ddu.vim' diff --git a/nvim/tomls/dein.toml b/nvim/tomls/dein.toml new file mode 100644 index 0000000..0524e1d --- /dev/null +++ b/nvim/tomls/dein.toml @@ -0,0 +1,5 @@ +[[plugins]] +repo = 'Shougo/context_filetype.vim' + +[[plugins]] +repo = 'vim-denops/denops.vim' diff --git a/nvim/tomls/dein_lazy.toml b/nvim/tomls/dein_lazy.toml new file mode 100644 index 0000000..7d8bdc6 --- /dev/null +++ b/nvim/tomls/dein_lazy.toml @@ -0,0 +1,144 @@ +[[plugins]] +repo = 'cohama/lexima.vim' +on_event = 'InsertEnter' + +[[plugins]] +repo = 'ntpeters/vim-better-whitespace' +on_event = 'BufEnter' + +[[plugins]] +repo = 'simeji/winresizer' +on_event = 'BufEnter' + +[[plugins]] +repo = 'markonm/traces.vim' +on_event = 'BufEnter' + +[[plugins]] +repo = 'mattn/vim-sonictemplate' +on_cmd = 'Template' +lua_post_source = ''' + vim.g.sonictemplate_vim_template_dir = { "$HOME/.vim/template" } +''' + +[[plugins]] +repo = 'almo7aya/openingh.nvim' +on_cmd = ['OpenInGHFile', 'OpenInGHRepo'] + +[[plugins]] +repo = 'tpope/vim-fugitive' +on_event = 'InsertEnter' + +[[plugins]] +repo = 'yuki-yano/fuzzy-motion.vim' +on_event = 'BufEnter' + +[[plugins]] +repo = 'lambdalisue/guise.vim' +on_event = 'BufEnter' + +[[plugins]] +repo = 'unblevable/quick-scope' +on_event = 'BufEnter' +hook_add = ''' + augroup qs_colors + autocmd! + autocmd ColorScheme * highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=155 cterm=underline + autocmd ColorScheme * highlight QuickScopeSecondary guifg='#5fffff' gui=underline ctermfg=81 cterm=underline + augroup END +''' +lua_post_source = ''' + vim.g.qs_hi_priority = 2 + vim.g.qs_max_chars = 80 + vim.g.qs_lazy_highlight = 0 + vim.g.qs_buftype_blacklist = { "terminal", "nofile" } +''' + +[[plugins]] +repo = 'nvim-tree/nvim-tree.lua' +on_cmd = ["NvimTreeToggle"] +lua_post_source = ''' + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + + require("nvim-tree").setup({ + sort_by = "case_sensitive", + renderer = { + group_empty = true, + }, + filters = { + dotfiles = true, + }, + }) +''' + +[[plugins]] +repo = 'lewis6991/gitsigns.nvim' +on_event = ["FocusLost", "CursorHold", "VimEnter"] +lua_post_source = ''' + require('gitsigns').setup { + signs = { + add = { text = '│' }, + change = { text = '│' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + untracked = { text = '┆' }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + follow_files = true + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter = ', - ', + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, -- Disable if file is longer than this (in lines) + preview_config = { + -- Options passed to nvim_open_win + border = 'double', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + yadm = { + enable = false + }, + } +''' + +[[plugins]] +repo = 'numToStr/FTerm.nvim' +on_event = 'BufEnter' +lua_add = ''' + vim.keymap.set("n", "T", 'lua require("FTerm").toggle()') +''' +lua_post_source = ''' + require 'FTerm'.setup({ + border = 'double', + dimensions = { + height = 0.9, + width = 0.9, + }, + }) +''' + +[[plugins]] +repo = 'kamykn/spelunker.vim' +on_event = 'BufEnter' +lua_add = ''' + vim.g.enable_spelunker_vim = 1 + vim.g.spelunker_check_type = 2 +''' diff --git a/nvim/tomls/go.toml b/nvim/tomls/go.toml new file mode 100644 index 0000000..708cb50 --- /dev/null +++ b/nvim/tomls/go.toml @@ -0,0 +1,22 @@ +[[plugins]] +repo = 'kyoh86/vim-go-coverage' +on_ft = ['go'] + +[[plugins]] +repo = 'mattn/vim-goaddtags' +on_ft = ['go'] + +[[plugins]] +repo = 'mattn/vim-goimpl' +on_ft = ['go'] + +[[plugins]] +repo = 'mattn/vim-gomod' +on_ft = ['go'] + +[[plugins]] +repo = 'mattn/vim-goimports' +on_ft = ['go'] +#lua_add = ''' +# vim.g.goimports = 1 +#''' diff --git a/nvim/tomls/theme.toml b/nvim/tomls/theme.toml new file mode 100644 index 0000000..1091c27 --- /dev/null +++ b/nvim/tomls/theme.toml @@ -0,0 +1,32 @@ +[[plugins]] +repo = 'navarasu/onedark.nvim' +on_event = 'VimEnter' +lua_source = ''' + require("onedark").setup { + style = "warmer", + transparent = true, -- Show/hide background + term_colors = true, -- Change terminal color as per the selected theme style + ending_tildes = false, -- Show the end-of-buffer tildes. By default they are hidden + cmp_itemkind_reverse = false, -- reverse item kind highlights in cmp menu + + code_style = { + comments = 'italic', + keywords = 'none', + functions = 'none', + strings = 'none', + variables = 'none' + }, + + -- Custom Highlights -- + colors = {}, -- Override default colors + highlights = {}, -- Override highlight groups + + -- Plugins Config -- + diagnostics = { + darker = true, -- darker colors for diagnostic + undercurl = true, -- use undercurl instead of underline for diagnostics + background = true, -- use background color for virtual text + }, + } + require("onedark").load() +''' diff --git a/nvim/tomls/treesitter.toml b/nvim/tomls/treesitter.toml new file mode 100644 index 0000000..3c40ceb --- /dev/null +++ b/nvim/tomls/treesitter.toml @@ -0,0 +1,74 @@ +[[plugins]] +repo = 'nvim-treesitter/nvim-treesitter' +hook_post_update = 'TSUpdate' +lua_source = ''' + require 'nvim-treesitter.configs'.setup { + ensure_installed = { "lua", "go", "python", "bash", "typescript", "yaml", "toml", "json", "vim", "hcl", "rust" }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + -- filesize で現状そんなに問題がないので一旦コメントアウトして様子を見る。問題なかったら完全に消す。 + -- disable = function(_, 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 + -- return true + -- end + -- end, + additional_vim_regex_highlighting = false, + }, + indent = { + enable = true, + } + } +''' + +[[plugins]] +repo = 'm-demare/hlargs.nvim' +depends = ['nvim-treesitter'] +lua_post_source = ''' + require('hlargs').setup() +''' + +[[plugins]] +repo = 'nvim-treesitter/nvim-treesitter-context' +depends = ['nvim-treesitter'] +lua_source = ''' + vim.cmd("hi TreesitterContextBottom gui=underline guisp=Grey") + require 'treesitter-context'.setup { + patterns = { + default = { + 'class', + 'function', + 'method', + 'interface', + 'struct', + }, + haskell = { + 'adt' + }, + rust = { + 'impl_item', + + }, + terraform = { + 'block', + 'object_elem', + 'attribute', + }, + markdown = { + 'section', + }, + json = { + 'pair', + }, + typescript = { + 'export_statement', + }, + yaml = { + 'block_mapping_pair', + }, + }, + } +'''