From d43723ef43a2490a9d5a8ed43f8a9dc277ade6b3 Mon Sep 17 00:00:00 2001 From: luokai Date: Wed, 8 May 2024 19:43:42 +0800 Subject: [PATCH 001/320] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20nvchad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .stylua.toml | 2 +- .tasks.json | 9 - README.md | 127 +- init.lua | 72 +- lua/chadrc.lua | 24 + lua/configs/conform.lua | 18 + lua/configs/lazy.lua | 47 + lua/configs/lspconfig.lua | 60 + lua/kide/autocmds.lua | 52 + lua/kide/basic.lua | 226 --- lua/kide/config.lua | 32 - lua/kide/core/init.lua | 9 - lua/kide/core/keybindings.lua | 297 --- lua/kide/core/utils/godot.lua | 21 - lua/kide/core/utils/init.lua | 56 +- lua/kide/core/utils/jdtls.lua | 10 +- lua/kide/core/utils/maven.lua | 52 +- lua/kide/core/utils/plantuml.lua | 25 +- lua/kide/core/utils/url.lua | 532 ------ lua/kide/dap/codelldb.lua | 67 - lua/kide/dap/gdscript.lua | 20 - lua/kide/dap/init.lua | 9 - lua/kide/dap/zig.lua | 19 - lua/kide/icons/lspkind.lua | 43 + lua/kide/init.lua | 3 + lua/kide/lsp/clangd.lua | 1 - lua/kide/lsp/gdscript.lua | 6 - lua/kide/lsp/gopls.lua | 1 - lua/kide/lsp/html.lua | 1 - lua/kide/lsp/init.lua | 191 -- lua/kide/lsp/java.lua | 196 +- lua/kide/lsp/jsonls.lua | 1 - lua/kide/lsp/lemminx.lua | 8 +- lua/kide/lsp/lsp_ui.lua | 277 --- lua/kide/lsp/lua_ls.lua | 32 - lua/kide/lsp/metals.lua | 30 - lua/kide/lsp/pyright.lua | 26 +- lua/kide/lsp/rime_ls.lua | 95 - lua/kide/lsp/rust_analyzer.lua | 51 - lua/kide/lsp/sonarlint.lua | 16 +- lua/kide/lsp/sourcekit.lua | 8 - lua/kide/lsp/spring_boot.lua | 12 - lua/kide/lsp/sqlls.lua | 2 - lua/kide/lsp/tsserver.lua | 1 - lua/kide/lsp/utils/init.lua | 84 - lua/kide/lsp/utils/jdtls.lua | 187 -- lua/kide/lsp/yaml-language-server.lua | 1 - lua/kide/plugins/config/browse-nvim.lua | 53 - lua/kide/plugins/config/bufferline.lua | 81 - lua/kide/plugins/config/flutter-tools.lua | 29 - lua/kide/plugins/config/gitsigns-nvim.lua | 91 - lua/kide/plugins/config/indent-blankline.lua | 36 - lua/kide/plugins/config/lualine.lua | 156 -- lua/kide/plugins/config/null-ls.lua | 129 -- lua/kide/plugins/config/nvim-cmp.lua | 139 -- lua/kide/plugins/config/nvim-dap-ui.lua | 103 -- lua/kide/plugins/config/nvim-tree.lua | 108 -- lua/kide/plugins/config/pandoc.lua | 51 - lua/kide/plugins/config/symbols-outline.lua | 66 - lua/kide/plugins/config/telescope.lua | 151 -- .../plugins/config/telescope/actions/set.lua | 313 ---- .../config/telescope/buffer_previewer.lua | 1209 ------------- lua/kide/plugins/config/utils/treeutil.lua | 46 - lua/kide/plugins/config/vim-illuminate.lua | 54 - lua/kide/plugins/config/which-key.lua | 10 - lua/kide/plugins/config/zk-nvim.lua | 21 - lua/kide/plugins/init.lua | 5 - lua/kide/plugins/lazy-nvim.lua | 1599 ----------------- lua/kide/snippets/c.lua | 31 - lua/kide/snippets/init.lua | 11 - lua/kide/snippets/java.lua | 332 ---- lua/kide/theme/gruvbox.lua | 154 -- lua/lazy_bootstrap.lua | 12 - lua/mappings.lua | 50 + lua/options.lua | 41 + lua/plugins/init.lua | 268 +++ 76 files changed, 834 insertions(+), 7574 deletions(-) delete mode 100644 .tasks.json create mode 100644 lua/chadrc.lua create mode 100644 lua/configs/conform.lua create mode 100644 lua/configs/lazy.lua create mode 100644 lua/configs/lspconfig.lua create mode 100644 lua/kide/autocmds.lua delete mode 100644 lua/kide/basic.lua delete mode 100644 lua/kide/config.lua delete mode 100644 lua/kide/core/init.lua delete mode 100644 lua/kide/core/keybindings.lua delete mode 100644 lua/kide/core/utils/godot.lua delete mode 100644 lua/kide/core/utils/url.lua delete mode 100644 lua/kide/dap/codelldb.lua delete mode 100644 lua/kide/dap/gdscript.lua delete mode 100644 lua/kide/dap/init.lua delete mode 100644 lua/kide/dap/zig.lua create mode 100644 lua/kide/icons/lspkind.lua create mode 100644 lua/kide/init.lua delete mode 100644 lua/kide/lsp/clangd.lua delete mode 100644 lua/kide/lsp/gdscript.lua delete mode 100644 lua/kide/lsp/gopls.lua delete mode 100644 lua/kide/lsp/html.lua delete mode 100644 lua/kide/lsp/init.lua delete mode 100644 lua/kide/lsp/jsonls.lua delete mode 100644 lua/kide/lsp/lsp_ui.lua delete mode 100644 lua/kide/lsp/lua_ls.lua delete mode 100644 lua/kide/lsp/metals.lua delete mode 100644 lua/kide/lsp/rime_ls.lua delete mode 100644 lua/kide/lsp/rust_analyzer.lua delete mode 100644 lua/kide/lsp/sourcekit.lua delete mode 100644 lua/kide/lsp/spring_boot.lua delete mode 100644 lua/kide/lsp/sqlls.lua delete mode 100644 lua/kide/lsp/tsserver.lua delete mode 100644 lua/kide/lsp/utils/init.lua delete mode 100644 lua/kide/lsp/utils/jdtls.lua delete mode 100644 lua/kide/lsp/yaml-language-server.lua delete mode 100644 lua/kide/plugins/config/browse-nvim.lua delete mode 100644 lua/kide/plugins/config/bufferline.lua delete mode 100644 lua/kide/plugins/config/flutter-tools.lua delete mode 100644 lua/kide/plugins/config/gitsigns-nvim.lua delete mode 100644 lua/kide/plugins/config/indent-blankline.lua delete mode 100644 lua/kide/plugins/config/lualine.lua delete mode 100644 lua/kide/plugins/config/null-ls.lua delete mode 100644 lua/kide/plugins/config/nvim-cmp.lua delete mode 100644 lua/kide/plugins/config/nvim-dap-ui.lua delete mode 100644 lua/kide/plugins/config/nvim-tree.lua delete mode 100644 lua/kide/plugins/config/pandoc.lua delete mode 100644 lua/kide/plugins/config/symbols-outline.lua delete mode 100644 lua/kide/plugins/config/telescope.lua delete mode 100644 lua/kide/plugins/config/telescope/actions/set.lua delete mode 100644 lua/kide/plugins/config/telescope/buffer_previewer.lua delete mode 100644 lua/kide/plugins/config/utils/treeutil.lua delete mode 100644 lua/kide/plugins/config/vim-illuminate.lua delete mode 100644 lua/kide/plugins/config/which-key.lua delete mode 100644 lua/kide/plugins/config/zk-nvim.lua delete mode 100644 lua/kide/plugins/init.lua delete mode 100644 lua/kide/plugins/lazy-nvim.lua delete mode 100644 lua/kide/snippets/c.lua delete mode 100644 lua/kide/snippets/init.lua delete mode 100644 lua/kide/snippets/java.lua delete mode 100644 lua/kide/theme/gruvbox.lua delete mode 100644 lua/lazy_bootstrap.lua create mode 100644 lua/mappings.lua create mode 100644 lua/options.lua create mode 100644 lua/plugins/init.lua diff --git a/.stylua.toml b/.stylua.toml index 6090f425..ecb6dca5 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -3,4 +3,4 @@ line_endings = "Unix" indent_type = "Spaces" indent_width = 2 quote_style = "AutoPreferDouble" -call_parentheses = "Always" +call_parentheses = "None" diff --git a/.tasks.json b/.tasks.json deleted file mode 100644 index 3128dfc0..00000000 --- a/.tasks.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "tasks": [ - { - "name": "fmt", - "cmd": "stylua lua/**/*.lua ftplugin/*.lua init.lua", - "close_on_exit": true - } - ] -} diff --git a/README.md b/README.md index 750f9f45..fe28c595 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # NVIM IDE -可配置 `Java`, `Rust`, `C/C++`, `JavaScript` 等编程语言开发环境。 极速启动 (`startuptime` 15 ~ 60 ms)。 - -使用 [stable](https://github.com/neovim/neovim/releases/tag/stable) 和 [neovim-nightly](https://github.com/neovim/neovim/releases) 版本, [安装步骤](https://github.com/neovim/neovim/wiki/Installing-Neovim)。 +使用 [NvChad](https://github.com/NvChad/NvChad) 做为基础配置, `NvChad` 基础配置和快捷建未做修改, 建议先阅读 `NvChad` 相关的文档。 +主要添加了 `Java`, `Python`, `Rust` 语言的 `LSP`, `DAP` 配置 ## 安装 @@ -20,9 +19,6 @@ cd $env:LOCALAPPDATA git clone https://github.com/JavaHello/nvim.git ``` -- `nvim-telescope/telescope-fzf-native.nvim` 需要在`mingw`环境下编译 -- `L3MON4D3/LuaSnip` 需要在`mingw`环境下编译, 如果出现 `ld` 错误, 需要手动指定 `lua51.dll` 目录 - ## 依赖 - [ripgrep](https://github.com/BurntSushi/ripgrep) @@ -34,7 +30,7 @@ git clone https://github.com/JavaHello/nvim.git 其他依赖可选安装,使用 [mason.nvim](https://github.com/williamboman/mason.nvim) -> 此配置在 Linux, Mac, Windows 系统上长期使用, Windows 下推荐使用 [scoop](https://scoop.sh/) 安装依赖 +> 此配置在 Linux, Mac 系统上长期使用, Windows 下推荐使用 [scoop](https://scoop.sh/) 安装依赖 ## 快捷键 @@ -42,23 +38,19 @@ git clone https://github.com/JavaHello/nvim.git | :-----------------------------: | :------------------: | :-----------------------: | | 文件管理 | `Normal` | `e` | | 文件搜索 | `Normal` | `ff` | -| 全局搜索 | `Normal` or `Visual` | `fg` | +| 全局搜索 | `Normal` or `Visual` | `fw` | | 全局搜索替换 | `Normal` or `Visual` | `fr` | -| 搜索 symbols | `Normal` or `Visual` | `fs` | | Git 操作 | `Command` | `:Git` | | Outline | `Normal` | `o` | | 查看实现 | `Normal` | `gi` | | 查看引用 | `Normal` | `gr` | | 查看声明 | `Normal` | `gd` | -| 格式化(LSP 提供支持) | `Normal` or `Visual` | `=` | -| 重命名 | `Normal` | `rn` | +| 格式化(LSP 提供支持) | `Normal` or `Visual` | `fm` | +| 重命名 | `Normal` | `ra` | | Code Action | `Normal` | `ca` | -| Debug | `Normal` | `F5` or `:DapContinue` | +| Debug | `Normal` | `:DapContinue` | | 断点 | `Normal` | `db` | -| 内置终端 | `Command` | `:ToggleTerm` | -| Tasks 列表 | `Normal` | `ts` | -| 代码折叠 | `Normal` | `zc` | -| 代码展开 | `Normal` | `zo` | +| 内置终端 | `Command` | ` or ` | | Java: Junit Test Method | `Normal` | `dm` | | Java: Junit Test Class | `Normal` | `dc` | | Run Last | `Normal` | `dl` | @@ -66,113 +58,16 @@ git clone https://github.com/JavaHello/nvim.git | Java: 刷新 Main 方法 Debug 配置 | `Command` | `:JdtRefreshDebugConfigs` | | Java: 预览项目依赖 | `Command` | `:JavaProjects` | -更多配置参考 [keybindings](./lua/kide/core/keybindings.lua) 文件 +更多配置参考 [mappings](./lua/mappings.lua) 文件 ## Java 配置 -- 添加了`telescope`支持查找`jar` 包 `class` -- 美化 `lsp_hover/doc` 显示 - `maven pom.xml` 自动补全(目前需要[手动打包](https://www.bilibili.com/video/BV12N4y1f7Bh/)) -> 如果不使用 `Java` 语言开发,无需配置 - -[NVIM 打造 Java IDE](https://javahello.github.io/dev/tools/NVIM-LSP-Java-IDE-vscode.html) -更新了配置,全部使用 vscode 扩展,简化安装步骤。 - -- 如果使用长时间后感觉卡顿,关闭下所有`buffer`, `:%bw`。 -- 搜索依赖`jar`包`class`很慢的问题。在搜索框输入会频繁的请求`LSP server`导致内存和`CPU`提升,通常需要好几秒才会返回结果。建议复制类名称到搜索框,或者选择类名后按下`fs`, 这样会很快搜索出相关的`class`。 +- [NVIM 打造 Java IDE](https://javahello.github.io/dev/tools/NVIM-LSP-Java-IDE-vscode.html) 更新了配置,全部使用 vscode 扩展,简化安装步骤。 ### Spring Boot LS -依赖 vscode 插件 [VScode Spring Boot](https://marketplace.visualstudio.com/items?itemName=vmware.vscode-spring-boot),需要添加环境变量 `SPRING_BOOT_LS_ENABLE=Y` - +- 依赖 vscode 插件 [VScode Spring Boot](https://marketplace.visualstudio.com/items?itemName=vmware.vscode-spring-boot) - [x] 查找`symbols`,`bean`定义,`bean`引用,`bean`实现等。 - [x] `application.properties`, `application.yml` 文件提示 - -### 功能演示 - -
-启动页 - 启动页 -
- -
-查找文件 - 查找文件 -
- -
-全局搜索 - 全局搜索 -
- -
-全局搜索替换 - 全局搜索替换 -
- -
-文件管理 - 文件管理 -
- -
-大纲 - 大纲 -
- -
-查看引用 - 查看引用 -
- -
-查看实现 - 查看实现 -
- -
-搜索 symbols - 搜索`symbols` -
- -
-Debug - Debug -
- -
-JavaProjects - Debug -
- -
-Maven(pom.xml 自动补全) - Debug -
- -
-查找 Spring Boot symbols - Debug -
- -## 我的 VIM 插件列表 - -| 插件名称 | 插件描述 | 推荐等级 | 备注 | -| --------------------------------------------------------------------- | ---------------------- | -------- | ---- | -| [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) | LSP 代码提示插件 | 10 | | -| [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) | 模糊查找插件,窗口预览 | 10 | | -| [lualine.nvim](https://github.com/nvim-lualine/lualine.nvim) | 状态栏插件 | 8 | | -| [vim-table-mode](https://github.com/dhruvasagar/vim-table-mode) | table 模式插件 | 8 | | -| [toggletasks.nvim](https://github.com/jedrzejboczar/toggletasks.nvim) | 任务执行插件 | 8 | | - -## Neovim 插件列表 - -- Neovim 精选插件[yutkat/my-neovim-pluginlist](https://github.com/yutkat/my-neovim-pluginlist) -- Neovim 精选插件[rockerBOO/awesome-neovim](https://github.com/rockerBOO/awesome-neovim) -- Neovim 精选插件[neovimcraft](http://neovimcraft.com/) -- 推荐[NvChad](https://github.com/NvChad/NvChad), 部分插件和配置参考了 `NvChad` - -## 感谢使用 - -打造一个高效美观的终端环境。欢迎提供各种建议,插件推荐,快捷键定义,主题配色等。 diff --git a/init.lua b/init.lua index ba97e729..f1acda19 100644 --- a/init.lua +++ b/init.lua @@ -1,38 +1,40 @@ -vim.loader.enable() --- math.randomseed(os.time()) --- 判断终端是否配置了透明背景 -if vim.env["TRANSPARENT_MODE"] == "Y" then - vim.g.transparent_mode = true -else - vim.g.transparent_mode = false -end +vim.g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/" +vim.g.mapleader = " " + +-- bootstrap lazy and all plugins +local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" -if vim.g.neovide then - vim.g.transparent_mode = false - vim.g.neovide_cursor_vfx_mode = "railgun" - vim.opt_global.guifont = "CaskaydiaCove Nerd Font Mono:h15" - vim.g.neovide_fullscreen = false - vim.g.neovide_input_use_logo = true - local alpha = function() - return string.format("%x", math.floor(255 * (vim.g.transparency or 0.8))) - end - -- g:neovide_transparency should be 0 if you want to unify transparency of content and title bar. - vim.g.neovide_transparency = 0.0 - vim.g.transparency = 0.8 - vim.g.neovide_background_color = "#282828" .. alpha() - - vim.g.neovide_floating_blur_amount_x = 2.0 - vim.g.neovide_floating_blur_amount_y = 2.0 - - vim.g.neovide_hide_mouse_when_typing = true - - vim.g.neovide_profiler = false - vim.g.neovide_padding_top = 0 - vim.g.neovide_padding_bottom = 0 - vim.g.neovide_padding_right = 0 - vim.g.neovide_padding_left = 0 +if not vim.loop.fs_stat(lazypath) then + local repo = "https://github.com/folke/lazy.nvim.git" + vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath } end -require("kide.basic") -require("kide.core") -require("kide.plugins") +vim.opt.rtp:prepend(lazypath) + +local lazy_config = require "configs.lazy" + +-- load plugins +require("lazy").setup({ + { + "NvChad/NvChad", + lazy = false, + branch = "v2.5", + import = "nvchad.plugins", + config = function() + require "options" + end, + }, + + { import = "plugins" }, +}, lazy_config) + +-- load theme +dofile(vim.g.base46_cache .. "defaults") +dofile(vim.g.base46_cache .. "statusline") + +require "nvchad.autocmds" + +vim.schedule(function() + require "mappings" + require "kide" +end) diff --git a/lua/chadrc.lua b/lua/chadrc.lua new file mode 100644 index 00000000..5c308787 --- /dev/null +++ b/lua/chadrc.lua @@ -0,0 +1,24 @@ +-- This file needs to have same structure as nvconfig.lua +-- https://github.com/NvChad/NvChad/blob/v2.5/lua/nvconfig.lua + +---@type ChadrcConfig +local M = {} + +M.ui = { + theme = "gruvbox", + + hl_override = { + Comment = { italic = true }, + ["@comment"] = { italic = true }, + -- DiffDelete = { fg = nil, bg = "red" }, + -- DiffAdd = { fg = nil, bg = "green" }, + -- DiffChange = { fg = nil, bg = "blue" }, + -- DiffText = { fg = nil, bg = "blue" }, + + LspReferenceText = { fg = "orange", bg = "grey" }, + LspReferenceRead = { fg = "orange", bg = "grey" }, + LspReferenceWrite = { fg = "orange", bg = "grey" }, + }, +} +vim.fn.sign_define("DapBreakpoint", { text = "", texthl = "Debug", linehl = "", numhl = "" }) +return M diff --git a/lua/configs/conform.lua b/lua/configs/conform.lua new file mode 100644 index 00000000..eef8bcf4 --- /dev/null +++ b/lua/configs/conform.lua @@ -0,0 +1,18 @@ +local options = { + lsp_fallback = true, + formatters_by_ft = { + lua = { "stylua" }, + css = { "prettier" }, + html = { "prettier" }, + json = { "prettier" }, + markdown = { "prettier" }, + }, + + -- format_on_save = { + -- -- These options will be passed to conform.format() + -- timeout_ms = 500, + -- lsp_fallback = true, + -- }, +} + +require("conform").setup(options) diff --git a/lua/configs/lazy.lua b/lua/configs/lazy.lua new file mode 100644 index 00000000..cd170bd3 --- /dev/null +++ b/lua/configs/lazy.lua @@ -0,0 +1,47 @@ +return { + defaults = { lazy = true }, + install = { colorscheme = { "nvchad" } }, + + ui = { + icons = { + ft = "", + lazy = "󰂠 ", + loaded = "", + not_loaded = "", + }, + }, + + performance = { + rtp = { + disabled_plugins = { + "2html_plugin", + "tohtml", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", + }, + }, + }, +} diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua new file mode 100644 index 00000000..c06c24ab --- /dev/null +++ b/lua/configs/lspconfig.lua @@ -0,0 +1,60 @@ +-- EXAMPLE +local on_attach = require("nvchad.configs.lspconfig").on_attach +local on_init = require("nvchad.configs.lspconfig").on_init +local capabilities = require("nvchad.configs.lspconfig").capabilities + +if capabilities.textDocument.foldingRange then + capabilities.textDocument.foldingRange.dynamicRegistration = false + capabilities.textDocument.foldingRange.lineFoldingOnly = true +else + capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true, + } +end + +local lspconfig = require "lspconfig" +local servers = { "html", "cssls" } + +-- lsps with default config +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, + } +end + +-- typescript +lspconfig.tsserver.setup { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, +} + +require("kide.lsp.java").setup { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, +} +require("spring_boot").setup { + server = { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, + }, +} + +require("kide.lsp.lemminx").setup { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, +} + +require("kide.lsp.sonarlint").setup() + +require("kide.lsp.pyright").setup { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, +} diff --git a/lua/kide/autocmds.lua b/lua/kide/autocmds.lua new file mode 100644 index 00000000..c114bfec --- /dev/null +++ b/lua/kide/autocmds.lua @@ -0,0 +1,52 @@ +local autocmd = vim.api.nvim_create_autocmd +local function augroup(name) + return vim.api.nvim_create_augroup("kide" .. name, { clear = true }) +end +-- Highlight on yank +autocmd({ "TextYankPost" }, { + group = augroup "highlight_yank", + callback = function() + vim.highlight.on_yank() + end, +}) + +-- close some filetypes with +autocmd("FileType", { + group = augroup "close_with_q", + pattern = { + "PlenaryTestPopup", + "help", + "lspinfo", + "man", + "notify", + "qf", + "spectre_panel", + "startuptime", + "tsplayground", + "checkhealth", + "fugitive", + "git", + "dbui", + "dbout", + "httpResult", + }, + callback = function(event) + vim.bo[event.buf].buflisted = false + vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) + end, +}) + +autocmd({ "BufReadCmd" }, { + group = augroup "git_close_with_q", + pattern = "fugitive://*", + callback = function(event) + vim.bo[event.buf].buflisted = false + vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) + end, +}) + +autocmd({ "BufRead", "BufNewFile" }, { + group = augroup "spell", + pattern = "*.md", + command = "setlocal spell spelllang=en_us,cjk", +}) diff --git a/lua/kide/basic.lua b/lua/kide/basic.lua deleted file mode 100644 index 9f8e284d..00000000 --- a/lua/kide/basic.lua +++ /dev/null @@ -1,226 +0,0 @@ -local config = require("kide.config") -vim.g.mapleader = " " -vim.opt.title = true -vim.opt.exrc = true -vim.opt.secure = false -vim.opt.ttyfast = true --- 相见恨晚的参数... -vim.opt_global.jumpoptions = "stack" - -vim.opt.clipboard = "unnamedplus" - --- 禁用 netrw -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 - -if vim.fn.has("wsl") == 1 then - vim.g.clipboard = { - name = "win32yank-wsl", - copy = { - ["+"] = "win32yank.exe -i --crlf", - ["*"] = "win32yank.exe -i --crlf", - }, - paste = { - ["+"] = "win32yank.exe -o --lf", - ["*"] = "win32yank.exe -o --lf", - }, - cache_enabled = 0, - } -end - --- 行号 -vim.opt.number = true -vim.opt.relativenumber = true -vim.opt.numberwidth = 2 -vim.opt.ruler = false - --- 高亮所在行 -vim.opt.cursorline = true -vim.opt.cursorcolumn = true - --- 右侧参考线,超过表示代码太长了,考虑换行 -vim.opt.colorcolumn = "120" - --- 边搜索边高亮 -vim.opt.incsearch = true --- 忽悠大小写 -vim.opt.ignorecase = true --- 智能大小写 -vim.opt.smartcase = true - -vim.opt_global.encoding = "UTF-8" - -vim.opt.fileencoding = "UTF-8" --- jk移动时光标下上方保留8行 -vim.opt.scrolloff = 3 -vim.opt.sidescrolloff = 3 -vim.opt.pumheight = 20 --- 缩进配置 -vim.opt.tabstop = 4 -vim.opt.softtabstop = 4 --- > < 时移动长度 -vim.opt.shiftwidth = 4 - -if vim.fn.has("nvim-0.10") == 1 then - vim.opt.smoothscroll = true -end - -local autocmd = vim.api.nvim_create_autocmd -autocmd("FileType", { - pattern = { - "lua", - "javascript", - "json", - "css", - "html", - "xml", - "yaml", - "http", - "markdown", - "lisp", - "sh", - "dart", - }, - callback = function() - vim.opt_local.tabstop = 2 - vim.opt_local.shiftwidth = 2 - vim.opt_local.expandtab = true - end, -}) -autocmd("FileType", { - pattern = { - "gd", - "gdscript", - "gdscript3", - }, - callback = function() - vim.opt_local.tabstop = 4 - vim.opt_local.shiftwidth = 4 - vim.opt_local.expandtab = false - end, -}) - --- 新行对齐当前行,空格替代tab -vim.opt.expandtab = true -vim.opt.autoindent = true -vim.opt.smartindent = true - --- 使用增强状态栏后不再需要 vim 的模式提示 -vim.opt.showmode = false - --- 当文件被外部程序修改时,自动加载 -vim.opt.autoread = true - --- 禁止创建备份文件 -vim.opt.backup = false -vim.opt.writebackup = false -vim.opt.swapfile = false --- smaller updatetime -vim.opt.updatetime = 300 - --- split window 从下边和右边出现 -vim.opt.splitbelow = false -vim.opt.splitright = true - --- 样式 -vim.opt.background = "dark" -vim.opt.termguicolors = true - --- 补全增强 -vim.opt.wildmenu = true - -vim.opt.confirm = true - -vim.g.python3_host_prog = config.env.py_bin - -vim.opt.list = true -vim.opt.cul = true -- cursor line - -vim.opt.timeout = true -vim.opt.timeoutlen = 450 - -vim.opt.mouse = "a" - --- vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]] -vim.opt.foldcolumn = "0" -vim.opt.foldenable = true -vim.opt.signcolumn = "auto" - --- 默认不要折叠 --- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file -vim.opt.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value -vim.opt.foldlevelstart = 99 - -vim.opt_global.completeopt = "menu,menuone,noselect" - --- use ethanholz/nvim-lastplace --- autocmd("BufReadPost", { --- pattern = "*", --- callback = function() --- local l = vim.fn.line("'\"") --- if l > 1 and l <= vim.fn.line("$") then --- vim.fn.execute("normal! g'\"") --- end --- end, --- }) - -vim.opt_global.grepprg = "rg --vimgrep --no-heading --smart-case" -vim.opt_global.grepformat = "%f:%l:%c:%m,%f:%l:%m" - ---- see https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua -local function augroup(name) - return vim.api.nvim_create_augroup("kide" .. name, { clear = true }) -end --- Highlight on yank -autocmd({ "TextYankPost" }, { - group = augroup("highlight_yank"), - callback = function() - vim.highlight.on_yank() - end, -}) - --- close some filetypes with -autocmd("FileType", { - group = augroup("close_with_q"), - pattern = { - "PlenaryTestPopup", - "help", - "lspinfo", - "man", - "notify", - "qf", - "spectre_panel", - "startuptime", - "tsplayground", - "checkhealth", - "fugitive", - "git", - "dbui", - "dbout", - "httpResult", - }, - callback = function(event) - vim.bo[event.buf].buflisted = false - vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) - end, -}) - -autocmd({ "BufReadCmd" }, { - group = augroup("git_close_with_q"), - pattern = "fugitive://*", - callback = function(event) - vim.bo[event.buf].buflisted = false - vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) - end, -}) - -autocmd("FileType", { - group = augroup("gitcommit"), - pattern = { "gitcommit" }, - command = "setlocal spell spelllang=en_us,cjk", -}) -autocmd({ "BufRead", "BufNewFile" }, { - group = augroup("spell"), - pattern = "*.md", - command = "setlocal spell spelllang=en_us,cjk", -}) diff --git a/lua/kide/config.lua b/lua/kide/config.lua deleted file mode 100644 index a7d345de..00000000 --- a/lua/kide/config.lua +++ /dev/null @@ -1,32 +0,0 @@ -local function get_python_path() - if vim.env.VIRTUAL_ENV then - if vim.fn.has("nvim-0.10") == 1 then - return vim.fs.joinpath(vim.env.VIRTUAL_ENV, "bin", "python") - end - return vim.env.VIRTUAL_ENV .. "/bin" .. "/python" - end - if vim.env.PY_BIN then - return vim.env.PY_BIN - end - local python = vim.fn.exepath("python3") - if python == nil or python == "" then - python = vim.fn.exepath("python") - end - return python -end - -local M = { - env = { - py_bin = get_python_path(), - rime_ls_bin = vim.env["RIME_LS_BIN"], - }, - plugin = { - copilot = { - enable = vim.env["COPILOT_ENABLE"] == "Y" and true or false, - }, - codeium = { - enable = vim.env["CODEIUM_ENABLE"] == "Y" and true or false, - }, - }, -} -return M diff --git a/lua/kide/core/init.lua b/lua/kide/core/init.lua deleted file mode 100644 index e74b60d8..00000000 --- a/lua/kide/core/init.lua +++ /dev/null @@ -1,9 +0,0 @@ -vim.schedule(function() - require("kide.core.utils.plantuml").setup() - require("kide.core.utils.maven").setup() - require("kide.core.utils.jdtls").setup() - require("kide.core.utils.pandoc").setup() - require("kide.core.utils.godot").setup() - - vim.api.nvim_create_user_command("Date", "lua print(os.date())", {}) -end) diff --git a/lua/kide/core/keybindings.lua b/lua/kide/core/keybindings.lua deleted file mode 100644 index 1ef80d25..00000000 --- a/lua/kide/core/keybindings.lua +++ /dev/null @@ -1,297 +0,0 @@ --- vim.g.mapleader = ";" --- vim.g.maplocalleader = ";" - -local map = vim.api.nvim_set_keymap -local opt = { noremap = true, silent = true } -local keymap = vim.keymap.set -local M = {} - -M.setup = function() - -- Esc - -- map("i", "jk", "", opt) - -- n 模式下复制内容到系统剪切板 - -- map("n", "c", '"+yy', opt) - -- v 模式下复制内容到系统剪切板 - -- map("v", "c", '"+yy', opt) - -- n 模式下粘贴系统剪切板的内容 - -- map("n", "v", '"+p', opt) - -- 取消搜索高亮显示 - map("n", "", "nohlsearch", opt) - map("n", "", "nohlsearch", opt) - - keymap("n", "", "h", opt) - keymap("n", "", "j", opt) - keymap("n", "", "k", opt) - keymap("n", "", "l", opt) - - map("n", "", "res +5", opt) - map("n", "", "res -5", opt) - map("n", "", "res -5", opt) - map("n", "", "res +5", opt) - map("n", "", "vertical resize+5", opt) - map("n", "", "vertical resize-5", opt) - map("n", "", "vertical resize-5", opt) - map("n", "", "vertical resize+5", opt) - - vim.api.nvim_create_user_command("BufferCloseOther", function() - require("kide.core.utils").close_other_bufline() - end, {}) - map("n", "s", "write", opt) - map("n", "w", "bdelete", opt) - map("n", "W", "%bd", opt) - -- map("n", "q", "q", opt) - -- buffer - map("n", "n", "BufferLineCycleNext ", opt) - map("n", "p", "BufferLineCyclePrev ", opt) - -- window - map("n", "", "vertical resize +5 ", opt) - map("n", "", "vertical resize -5 ", opt) - - -- " 退出 terminal 模式 - map("t", "", "", opt) - -- map("t", "jk", "", opt) - - -- ToggleTerm - map("n", "", "ToggleTerm", opt) - map("t", "", "ToggleTerm", opt) - map("n", "tt", "ToggleTerm", opt) - map("v", "tt", "ToggleTermSendVisualSelection", opt) - -- map("t", "tt", ":ToggleTerm", opt) - - -- symbols-outline.nvim - map("n", "o", "SymbolsOutline", opt) - - -- Telescope - map("n", "ff", "Telescope find_files", opt) - keymap("v", "ff", function() - local tb = require("telescope.builtin") - local text = require("kide.core.utils").get_visual_selection() - tb.find_files({ default_text = text }) - end, opt) - map("n", "", "Telescope find_files", opt) - map("n", "fg", "Telescope live_grep", opt) - keymap("v", "fg", function() - local tb = require("telescope.builtin") - local text = require("kide.core.utils").get_visual_selection() - tb.live_grep({ default_text = text }) - end, opt) - map("n", "fb", "Telescope buffers", opt) - map("n", "fh", "Telescope help_tags", opt) - - -- camel_case - require("kide.core.utils").camel_case_init() - - -- nvim-dap - keymap("n", "", "lua require'dap'.continue()", opt) - keymap("n", "", "lua require'dap'.step_over()", opt) - keymap("n", "", "lua require'dap'.step_into()", opt) - keymap("n", "", "lua require'dap'.step_out()", opt) - keymap("n", "db", "lua require'dap'.toggle_breakpoint()", opt) - keymap("n", "dB", "lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))", opt) - keymap( - "n", - "dp", - "lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))", - opt - ) - keymap("n", "dr", "lua require'dap'.repl.open()", opt) - keymap("n", "dl", "lua require'dap'.run_last()", opt) - - -- nvim-dap-ui - keymap("n", "df", ':lua require("dapui").float_element(vim.Nil, { enter = true}) ', opt) - - -- bufferline.nvim - keymap("n", "1", "BufferLineGoToBuffer 1", opt) - keymap("n", "2", "BufferLineGoToBuffer 2", opt) - keymap("n", "3", "BufferLineGoToBuffer 3", opt) - keymap("n", "4", "BufferLineGoToBuffer 4", opt) - keymap("n", "5", "BufferLineGoToBuffer 5", opt) - keymap("n", "6", "BufferLineGoToBuffer 6", opt) - keymap("n", "7", "BufferLineGoToBuffer 7", opt) - keymap("n", "8", "BufferLineGoToBuffer 8", opt) - keymap("n", "9", "BufferLineGoToBuffer 9", opt) - - -- nvim-spectre - map("n", "S", "lua require('spectre').open()", opt) - -- search current word - map("n", "fr", "lua require('spectre').open_visual({select_word=true})", opt) - map("v", "fr", ":lua require('spectre').open_visual()", opt) - - -- ToggleTerm - map("n", "ft", "TermSelect", opt) - -- ToggleTask - map("n", "ts", "Telescope toggletasks spawn", opt) - - -- nvimTree - map("n", "e", "NvimTreeToggle", opt) - - -- set keybinds for both INSERT and VISUAL. - vim.api.nvim_set_keymap("i", "", "luasnip-next-choice", {}) - vim.api.nvim_set_keymap("s", "", "luasnip-next-choice", {}) - vim.api.nvim_set_keymap("i", "", "luasnip-prev-choice", {}) - vim.api.nvim_set_keymap("s", "", "luasnip-prev-choice", {}) - - -- todo-comments - vim.keymap.set("n", "]t", function() - require("todo-comments").jump_next() - end, { desc = "Next todo comment" }) - - vim.keymap.set("n", "[t", function() - require("todo-comments").jump_prev() - end, { desc = "Previous todo comment" }) -end --- lsp 回调函数快捷键设置 -M.maplsp = function(client, buffer, null_ls) - local bufopts = { noremap = true, silent = true, buffer = buffer } - vim.api.nvim_buf_set_keymap(buffer, "n", "K", "lua vim.lsp.buf.hover()", opt) - -- rename - vim.api.nvim_buf_set_keymap(buffer, "n", "rn", "lua vim.lsp.buf.rename()", opt) - -- mapbuf('n', 'rn', 'lua require("lspsaga.rename").rename()', opt) - -- code action - vim.api.nvim_buf_set_keymap(buffer, "n", "ca", "lua vim.lsp.buf.code_action()", opt) - vim.api.nvim_buf_set_keymap(buffer, "v", "ca", "lua vim.lsp.buf.code_action()", opt) - -- mapbuf('n', 'ca', 'lua require("lspsaga.codeaction").code_action()', opt) - -- diagnostic - vim.api.nvim_buf_set_keymap(buffer, "n", "go", "lua vim.diagnostic.open_float()", opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "[g", "lua vim.diagnostic.goto_prev()", opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "]g", "lua vim.diagnostic.goto_next()", opt) - vim.api.nvim_buf_set_keymap( - buffer, - "n", - "[e", - "lua vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.ERROR })", - opt - ) - vim.api.nvim_buf_set_keymap( - buffer, - "n", - "]e", - "lua vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR })", - opt - ) - - keymap("n", "=", function() - local bfn = vim.api.nvim_get_current_buf() - vim.lsp.buf.format({ - bufnr = bfn, - filter = function(c) - return require("kide.lsp.utils").filter_format_lsp_client(c, bfn) - end, - }) - end, bufopts) - vim.api.nvim_buf_set_keymap( - buffer, - "v", - "=", - 'lua require("kide.lsp.utils").format_range_operator()', - opt - ) - - vim.api.nvim_buf_set_keymap(buffer, "n", "xw", "Telescope diagnostics", opt) - vim.api.nvim_buf_set_keymap( - buffer, - "n", - "xe", - "lua require('telescope.builtin').diagnostics({ severity = vim.diagnostic.severity.ERROR })", - opt - ) - - -- -------- null_ls 不支持快捷键不绑定 ------------------------------- - if null_ls then - return - end - -- go xx - -- mapbuf('n', 'gd', 'lua vim.lsp.buf.definition()', opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "gD", "lua vim.lsp.buf.declaration()", opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "gt", "lua vim.lsp.buf.type_definition()", opt) - - if client.supports_method("textDocument/definition") then - vim.api.nvim_buf_set_keymap(buffer, "n", "gd", "Telescope lsp_definitions", opt) - else - vim.api.nvim_buf_set_keymap(buffer, "n", "gd", "lua vim.lsp.buf.definition()", opt) - end - - vim.api.nvim_buf_set_keymap(buffer, "n", "gh", "lua vim.lsp.buf.hover()", opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "gs", "lua vim.lsp.buf.signature_help()", opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "gi", "Telescope lsp_implementations", opt) - vim.api.nvim_buf_set_keymap( - buffer, - "n", - "gr", - "lua require('telescope.builtin').lsp_references({jump_type='never'})", - opt - ) - vim.api.nvim_buf_set_keymap(buffer, "n", "fs", "Telescope lsp_dynamic_workspace_symbols", opt) - keymap("v", "fs", function() - local tb = require("telescope.builtin") - local text = require("kide.core.utils").get_visual_selection() - tb.lsp_workspace_symbols({ default_text = text, query = text }) - end, opt) - - vim.api.nvim_buf_set_keymap(buffer, "n", "fo", "Telescope lsp_document_symbols", opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "cr", "lua vim.lsp.codelens.refresh()", opt) - vim.api.nvim_buf_set_keymap(buffer, "n", "ce", "lua vim.lsp.codelens.run()", opt) -end - --- nvim-cmp 自动补全 -M.cmp = function(cmp) - local luasnip = require("luasnip") - local has_words_before = function() - if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then - return false - end - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil - end - return { - -- [""] = cmp.mapping.scroll_docs(-4), - -- [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - -- select = true, - }), - - [""] = cmp.mapping(function(fallback) - local neogen = require("neogen") - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif neogen.jumpable() then - neogen.jump_next() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - - [""] = cmp.mapping(function(fallback) - local neogen = require("neogen") - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - elseif neogen.jumpable(true) then - neogen.jump_prev() - else - fallback() - end - end, { "i", "s" }), - } -end - -M.ufo_mapkey = function() - -- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself - vim.keymap.set("n", "zR", require("ufo").openAllFolds) - vim.keymap.set("n", "zM", require("ufo").closeAllFolds) -end - -return M diff --git a/lua/kide/core/utils/godot.lua b/lua/kide/core/utils/godot.lua deleted file mode 100644 index 54a7c122..00000000 --- a/lua/kide/core/utils/godot.lua +++ /dev/null @@ -1,21 +0,0 @@ -local M = {} -local utils = require("kide.core.utils") -local pipe = (function() - if utils.is_win then - return vim.env["TEMP"] .. "\\godot.pipe" - else - return "/tmp/godot.pipe" - end -end)() -M.setup = function() - -- serverstart([{address}]) - -- godot param: --server /tmp/godot.pipe --remote-send ":n {file}:call cursor({line},{col})" - vim.api.nvim_create_user_command("GododNvimServerStart", function() - print("start: " .. pipe) - vim.fn.serverstart(pipe) - end, {}) - vim.api.nvim_create_user_command("GododNvimServerStop", function() - vim.fn.serverstop(pipe) - end, {}) -end -return M diff --git a/lua/kide/core/utils/init.lua b/lua/kide/core/utils/init.lua index 1ccf38ea..9991f2a3 100644 --- a/lua/kide/core/utils/init.lua +++ b/lua/kide/core/utils/init.lua @@ -4,31 +4,26 @@ local M = {} -- 78 h "init.lua" 第 1 行 M.close_other_buf = function() -- local cur_winnr = vim.fn.winnr() - local cur_buf = vim.fn.bufnr("%") + local cur_buf = vim.fn.bufnr "%" if cur_buf == -1 then return end -- local bf_no = vim.fn.winbufnr(cur_winnr) - vim.fn.execute("bn") - local next_buf = vim.fn.bufnr("%") + vim.fn.execute "bn" + local next_buf = vim.fn.bufnr "%" -- print('cur_buf ' .. cur_buf) local count = 999 while next_buf ~= -1 and cur_buf ~= next_buf and count > 0 do -- print('next_buf ' .. next_buf) local bdel = "bdel " .. next_buf - vim.fn.execute("bn") + vim.fn.execute "bn" vim.fn.execute(bdel) - next_buf = vim.fn.bufnr("%") + next_buf = vim.fn.bufnr "%" count = count - 1 end end -M.close_other_bufline = function() - vim.fn.execute("BufferLineCloseLeft") - vim.fn.execute("BufferLineCloseRight") -end - M.is_upper = function(c) return c >= 65 and c <= 90 end @@ -54,7 +49,7 @@ M.camel_case = function(word) if word == "" or word == nil then return end - if word:find("_") then + if word:find "_" then return M.camel_case_c(word) else return M.camel_case_u(word) @@ -120,15 +115,15 @@ end M.camel_case_start = function(r, l1, l2) local word if r == 0 then - word = vim.fn.expand("") + word = vim.fn.expand "" local cw = M.camel_case(word) if cw then vim.fn.setreg('"', M.camel_case(word)) end elseif l1 == l2 then - word = vim.fn.getline(".") - local ln1 = vim.fn.getpos("'<") - local ln2 = vim.fn.getpos("'>") + word = vim.fn.getline "." + local ln1 = vim.fn.getpos "'<" + local ln2 = vim.fn.getpos "'>" local cs = ln1[3] local ce = ln2[3] local ecs = M.char_size(word:byte(ce)) @@ -136,9 +131,9 @@ M.camel_case_start = function(r, l1, l2) ce = ce + ecs - 1 end word = word:sub(cs, ce) - local reg_tmp = vim.fn.getreg("a") + local reg_tmp = vim.fn.getreg "a" vim.fn.setreg("a", M.camel_case(word)) - vim.cmd('normal! gv"ap') + vim.cmd 'normal! gv"ap' vim.fn.setreg("a", reg_tmp) else vim.notify("请选择单行字符", vim.log.levels.WARN) @@ -155,8 +150,8 @@ end -- print(M.camel_case("helloWorldAaAaAxC")) M.get_visual_selection = function() - vim.cmd('noau normal! "vy"') - local text = vim.fn.getreg("v") + vim.cmd 'noau normal! "vy"' + local text = vim.fn.getreg "v" vim.fn.setreg("v", {}) text = string.gsub(text, "\n", "") @@ -171,10 +166,6 @@ M.run_cmd = function(cmd) return vim.fn.system(cmd) end -M.or_default = function(a, v) - return a and a or v -end - M.Windows = "Windows" M.Linux = "Linux" M.Mac = "Mac" @@ -182,9 +173,9 @@ M.Mac = "Mac" M.os_type = function() local has = vim.fn.has local t = M.Linux - if has("win32") == 1 or has("win64") == 1 then + if has "win32" == 1 or has "win64" == 1 then t = M.Windows - elseif has("mac") == 1 then + elseif has "mac" == 1 then t = M.Mac end return t @@ -223,12 +214,12 @@ end M.open_fn = function(file) local ok, system_open = pcall(require, "nvim-tree.actions.node.system-open") if ok then - system_open.fn({ absolute_path = file }) + system_open.fn { absolute_path = file } end end M.get_filename = function(path) - local idx = path:match(".+()%.%w+$") + local idx = path:match ".+()%.%w+$" if idx then return path:sub(1, idx - 1) else @@ -237,12 +228,12 @@ M.get_filename = function(path) end M.get_extension = function(str) - return str:match(".+%.(%w+)$") + return str:match ".+%.(%w+)$" end M.tmpdir = function() if M.is_win then - return os.getenv("TEMP") + return os.getenv "TEMP" else return "/tmp" end @@ -266,7 +257,11 @@ M.get_cpu_thread_count = function() cmd = "echo %NUMBER_OF_PROCESSORS%" end local handle = io.popen(cmd) - local result = handle:read("*a") + if handle == nil then + M.cpu_thread_count = 8 + return M.cpu_thread_count + end + local result = handle:read "*a" handle:close() local c = tonumber(result) if c then @@ -274,6 +269,7 @@ M.get_cpu_thread_count = function() else M.cpu_thread_count = 8 end + return M.cpu_thread_count end M.java_bin = function() diff --git a/lua/kide/core/utils/jdtls.lua b/lua/kide/core/utils/jdtls.lua index 4155400a..53ff6c7a 100644 --- a/lua/kide/core/utils/jdtls.lua +++ b/lua/kide/core/utils/jdtls.lua @@ -1,4 +1,4 @@ -local utils = require("kide.core.utils") +local utils = require "kide.core.utils" local M = {} local function delete_file(hf) @@ -16,10 +16,10 @@ end -- fd -I -H project$ | xargs rm -rf -- fd -I -H factorypath$ | xargs rm -rf local function clean_jdtls() - local del_files = delete_file("settings") or "" - del_files = del_files .. (delete_file("classpath") or "") - del_files = del_files .. (delete_file("project") or "") - del_files = del_files .. (delete_file("factorypath") or "") + local del_files = delete_file "settings" or "" + del_files = del_files .. (delete_file "classpath" or "") + del_files = del_files .. (delete_file "project" or "") + del_files = del_files .. (delete_file "factorypath" or "") vim.notify("delete: \n" .. del_files, vim.log.levels.INFO) end diff --git a/lua/kide/core/utils/maven.lua b/lua/kide/core/utils/maven.lua index 9350cd70..1d861241 100644 --- a/lua/kide/core/utils/maven.lua +++ b/lua/kide/core/utils/maven.lua @@ -1,9 +1,9 @@ -local utils = require("kide.core.utils") +local utils = require "kide.core.utils" local M = {} local function maven_settings() - if vim.fn.filereadable(vim.fn.expand("~/.m2/settings.xml")) == 1 then - return vim.fn.expand("~/.m2/settings.xml") + if vim.fn.filereadable(vim.fn.expand "~/.m2/settings.xml") == 1 then + return vim.fn.expand "~/.m2/settings.xml" end local maven_home = vim.env["MAVEN_HOME"] if maven_home and vim.fn.filereadable(maven_home .. "/conf/settings.xml") then @@ -31,24 +31,13 @@ end local exec = function(cmd, pom, opt) opt = opt or {} - local Terminal = require("toggleterm.terminal").Terminal - -- require("toggleterm").exec(cmd .. settings_opt(M.get_maven_settings()) .. pom_file(pom)) - local mvn = Terminal:new({ + + require("nvchad.term").runner { + pos = "sp", cmd = cmd .. settings_opt(M.get_maven_settings()) .. pom_file(pom), - close_on_exit = opt.close_on_exit, - auto_scroll = true, - on_exit = function(_) - if opt.update ~= nil and opt.update and opt.close_on_exit ~= nil and opt.close_on_exit then - vim.defer_fn(function() - local filetype = vim.api.nvim_buf_get_option(0, "filetype") - if filetype == "java" then - require("jdtls").update_project_config() - end - end, 500) - end - end, - }) - mvn:toggle() + id = "maven", + clear_cmd = true, + } end local function create_command(buf, name, cmd, complete, opt) vim.api.nvim_buf_create_user_command(buf, name, function(opts) @@ -60,9 +49,9 @@ local function create_command(buf, name, cmd, complete, opt) end if opts.args then - exec(cmd .. " " .. opts.args, vim.fn.expand("%"), opt) + exec(cmd .. " " .. opts.args, vim.fn.expand "%", opt) else - exec(cmd, vim.fn.expand("%"), opt) + exec(cmd, vim.fn.expand "%", opt) end end, { nargs = "*", @@ -72,24 +61,11 @@ end local maven_args_complete = utils.command_args_complete -local function get_class_name() - if require("nvim-treesitter.query").has_query_files("java", "indents") then - local ts_utils = require("nvim-treesitter.ts_utils") - local node = ts_utils.get_node_at_cursor() - if node ~= nil and node:type() ~= "identifier" then - node = node:parent() - end - if node ~= nil and node:type() == "identifier" then - return vim.treesitter.get_node_text(node, 0) - end - end -end - M.maven_command = function(buf) -- 判断为 java 文件 if vim.api.nvim_buf_get_option(buf, "filetype") == "java" then create_command(buf, "MavenExecJava", function(_) - local filename = vim.fn.expand("%:p") + local filename = vim.fn.expand "%:p" filename = string.gsub(filename, "^[%-/%w%s]*%/src%/main%/java%/", "") filename = string.gsub(filename, "[/\\]", ".") filename = string.gsub(filename, "%.java$", "") @@ -156,9 +132,9 @@ M.setup = function() local opt = { update = true, close_on_exit = false } vim.api.nvim_create_user_command("Maven", function(opts) if opts.args then - exec("mvn " .. opts.args, vim.fn.expand("%"), opt) + exec("mvn " .. opts.args, vim.fn.expand "%", opt) else - exec("mvn", vim.fn.expand("%"), opt) + exec("mvn", vim.fn.expand "%", opt) end end, { nargs = "*", diff --git a/lua/kide/core/utils/plantuml.lua b/lua/kide/core/utils/plantuml.lua index 0cec7a82..6d0b5f82 100644 --- a/lua/kide/core/utils/plantuml.lua +++ b/lua/kide/core/utils/plantuml.lua @@ -1,5 +1,5 @@ local uv = vim.loop -local utils = require("kide.core.utils") +local utils = require "kide.core.utils" local plantuml_args_complete = utils.command_args_complete local M = {} M.config = {} @@ -7,7 +7,7 @@ M.config = {} local function plantuml_jar(default_jar) return vim.env["PLANTUML_JAR"] or default_jar end -M.config.jar_path = plantuml_jar("/opt/software/puml/plantuml.jar") +M.config.jar_path = plantuml_jar "/opt/software/puml/plantuml.jar" M.config.cmd = "java" M.config.defaultTo = "svg" M.types = {} @@ -45,7 +45,7 @@ local function exec(opt) vim.notify("Plantuml: 没有文件 " .. M.config.jar_path, vim.log.levels.ERROR) return end - if not vim.fn.executable("java") then + if not vim.fn.executable "java" then vim.notify("Plantuml: 没有 java 环境", vim.log.levels.ERROR) return end @@ -53,6 +53,7 @@ local function exec(opt) if vim.startswith(item, "-t") then return true end + return false end, opt.args) if not out_type or vim.tbl_count(out_type) == 0 then local ot = to_type() @@ -66,7 +67,7 @@ local function exec(opt) end local ofile = out_file(ot, opt.file) - local p = vim.fn.expand("%:p:h") + local p = vim.fn.expand "%:p:h" table.insert(opt.args, 1, "-jar") table.insert(opt.args, 2, M.config.jar_path) table.insert(opt.args, opt.file) @@ -87,13 +88,19 @@ local function exec(opt) process.stderr:read_stop() process.stderr:close() if data then - vim.notify("Plantuml: " .. data, vim.log.levels.WARN) + vim.schedule(function() + vim.notify("Plantuml: " .. data, vim.log.levels.WARN) + end) else - vim.notify("Plantuml: export error " .. code, vim.log.levels.WARN) + vim.schedule(function() + vim.notify("Plantuml: export error " .. code, vim.log.levels.WARN) + end) end end) else - vim.notify("Plantuml: export success", vim.log.levels.INFO) + vim.schedule(function() + vim.notify("Plantuml: export success", vim.log.levels.INFO) + end) utils.open_fn(ofile) end end @@ -108,10 +115,10 @@ local function init() desc = "Export Plantuml file", callback = function(o) vim.api.nvim_buf_create_user_command(o.buf, "Plantuml", function(opts) - exec({ + exec { args = opts.fargs, file = o.file, - }) + } end, { nargs = "*", complete = plantuml_args_complete(complete_list, { single = true }), diff --git a/lua/kide/core/utils/url.lua b/lua/kide/core/utils/url.lua deleted file mode 100644 index f167c437..00000000 --- a/lua/kide/core/utils/url.lua +++ /dev/null @@ -1,532 +0,0 @@ --- https://github.com/golgote/neturl/blob/master/lib/net/url.lua --- net/url.lua - a robust url parser and builder --- --- Bertrand Mansion, 2011-2021; License MIT --- @module net.url --- @alias M - -local M = {} -M.version = "1.1.0" - ---- url options --- - `separator` is set to `&` by default but could be anything like `&amp;` or `;` --- - `cumulative_parameters` is false by default. If true, query parameters with the same name will be stored in a table. --- - `legal_in_path` is a table of characters that will not be url encoded in path components --- - `legal_in_query` is a table of characters that will not be url encoded in query values. Query parameters only support a small set of legal characters (-_.). --- - `query_plus_is_space` is true by default, so a plus sign in a query value will be converted to %20 (space), not %2B (plus) --- @todo Add option to limit the size of the argument table --- @todo Add option to limit the depth of the argument table --- @todo Add option to process dots in parameter names, ie. `param.filter=1` -M.options = { - separator = '&', - cumulative_parameters = false, - legal_in_path = { - [":"] = true, ["-"] = true, ["_"] = true, ["."] = true, - ["!"] = true, ["~"] = true, ["*"] = true, ["'"] = true, - ["("] = true, [")"] = true, ["@"] = true, ["&"] = true, - ["="] = true, ["$"] = true, [","] = true, - [";"] = true - }, - legal_in_query = { - [":"] = true, ["-"] = true, ["_"] = true, ["."] = true, - [","] = true, ["!"] = true, ["~"] = true, ["*"] = true, - ["'"] = true, [";"] = true, ["("] = true, [")"] = true, - ["@"] = true, ["$"] = true, - }, - query_plus_is_space = true -} - ---- list of known and common scheme ports --- as documented in IANA URI scheme list -M.services = { - acap = 674, - cap = 1026, - dict = 2628, - ftp = 21, - gopher = 70, - http = 80, - https = 443, - iax = 4569, - icap = 1344, - imap = 143, - ipp = 631, - ldap = 389, - mtqp = 1038, - mupdate = 3905, - news = 2009, - nfs = 2049, - nntp = 119, - rtsp = 554, - sip = 5060, - snmp = 161, - telnet = 23, - tftp = 69, - vemmi = 575, - afs = 1483, - jms = 5673, - rsync = 873, - prospero = 191, - videotex = 516 -} - -local function decode(str) - return (str:gsub("%%(%x%x)", function(c) - return string.char(tonumber(c, 16)) - end)) -end - -local function encode(str, legal) - return (str:gsub("([^%w])", function(v) - if legal[v] then - return v - end - return string.upper(string.format("%%%02x", string.byte(v))) - end)) -end - --- for query values, + can mean space if configured as such -local function decodeValue(str) - if M.options.query_plus_is_space then - str = str:gsub('+', ' ') - end - return decode(str) -end - -local function concat(a, b) - if type(a) == 'table' then - return a:build() .. b - else - return a .. b:build() - end -end - -function M:addSegment(path) - if type(path) == 'string' then - self.path = self.path .. '/' .. encode(path:gsub("^/+", ""), M.options.legal_in_path) - end - return self -end - ---- builds the url --- @return a string representing the built url -function M:build() - local url = '' - if self.path then - local path = self.path - url = url .. tostring(path) - end - if self.query then - local qstring = tostring(self.query) - if qstring ~= "" then - url = url .. '?' .. qstring - end - end - if self.host then - local authority = self.host - if self.port and self.scheme and M.services[self.scheme] ~= self.port then - authority = authority .. ':' .. self.port - end - local userinfo - if self.user and self.user ~= "" then - userinfo = self.user - if self.password then - userinfo = userinfo .. ':' .. self.password - end - end - if userinfo and userinfo ~= "" then - authority = userinfo .. '@' .. authority - end - if authority then - if url ~= "" then - url = '//' .. authority .. '/' .. url:gsub('^/+', '') - else - url = '//' .. authority - end - end - end - if self.scheme then - url = self.scheme .. ':' .. url - end - if self.fragment then - url = url .. '#' .. self.fragment - end - return url -end - ---- builds the querystring --- @param tab The key/value parameters --- @param sep The separator to use (optional) --- @param key The parent key if the value is multi-dimensional (optional) --- @return a string representing the built querystring -function M.buildQuery(tab, sep, key) - local query = {} - if not sep then - sep = M.options.separator or '&' - end - local keys = {} - for k in pairs(tab) do - keys[#keys+1] = k - end - table.sort(keys, function (a, b) - local function padnum(n, rest) return ("%03d"..rest):format(tonumber(n)) end - return tostring(a):gsub("(%d+)(%.)",padnum) < tostring(b):gsub("(%d+)(%.)",padnum) - end) - for _,name in ipairs(keys) do - local value = tab[name] - name = encode(tostring(name), {["-"] = true, ["_"] = true, ["."] = true}) - if key then - if M.options.cumulative_parameters and string.find(name, '^%d+$') then - name = tostring(key) - else - name = string.format('%s[%s]', tostring(key), tostring(name)) - end - end - if type(value) == 'table' then - query[#query+1] = M.buildQuery(value, sep, name) - else - local value = encode(tostring(value), M.options.legal_in_query) - if value ~= "" then - query[#query+1] = string.format('%s=%s', name, value) - else - query[#query+1] = name - end - end - end - return table.concat(query, sep) -end - ---- Parses the querystring to a table --- This function can parse multidimensional pairs and is mostly compatible --- with PHP usage of brackets in key names like ?param[key]=value --- @param str The querystring to parse --- @param sep The separator between key/value pairs, defaults to `&` --- @todo limit the max number of parameters with M.options.max_parameters --- @return a table representing the query key/value pairs -function M.parseQuery(str, sep) - if not sep then - sep = M.options.separator or '&' - end - - local values = {} - for key,val in str:gmatch(string.format('([^%q=]+)(=*[^%q=]*)', sep, sep)) do - local key = decodeValue(key) - local keys = {} - key = key:gsub('%[([^%]]*)%]', function(v) - -- extract keys between balanced brackets - if string.find(v, "^-?%d+$") then - v = tonumber(v) - else - v = decodeValue(v) - end - table.insert(keys, v) - return "=" - end) - key = key:gsub('=+.*$', "") - key = key:gsub('%s', "_") -- remove spaces in parameter name - val = val:gsub('^=+', "") - - if not values[key] then - values[key] = {} - end - if #keys > 0 and type(values[key]) ~= 'table' then - values[key] = {} - elseif #keys == 0 and type(values[key]) == 'table' then - values[key] = decodeValue(val) - elseif M.options.cumulative_parameters - and type(values[key]) == 'string' then - values[key] = { values[key] } - table.insert(values[key], decodeValue(val)) - end - - local t = values[key] - for i,k in ipairs(keys) do - if type(t) ~= 'table' then - t = {} - end - if k == "" then - k = #t+1 - end - if not t[k] then - t[k] = {} - end - if i == #keys then - t[k] = val - end - t = t[k] - end - - end - setmetatable(values, { __tostring = M.buildQuery }) - return values -end - ---- set the url query --- @param query Can be a string to parse or a table of key/value pairs --- @return a table representing the query key/value pairs -function M:setQuery(query) - local query = query - if type(query) == 'table' then - query = M.buildQuery(query) - end - self.query = M.parseQuery(query) - return query -end - ---- set the authority part of the url --- The authority is parsed to find the user, password, port and host if available. --- @param authority The string representing the authority --- @return a string with what remains after the authority was parsed -function M:setAuthority(authority) - self.authority = authority - self.port = nil - self.host = nil - self.userinfo = nil - self.user = nil - self.password = nil - - authority = authority:gsub('^([^@]*)@', function(v) - self.userinfo = v - return '' - end) - - authority = authority:gsub(':(%d+)$', function(v) - self.port = tonumber(v) - return '' - end) - - local function getIP(str) - -- ipv4 - local chunks = { str:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$") } - if #chunks == 4 then - for _, v in pairs(chunks) do - if tonumber(v) > 255 then - return false - end - end - return str - end - -- ipv6 - local chunks = { str:match("^%["..(("([a-fA-F0-9]*):"):rep(8):gsub(":$","%%]$"))) } - if #chunks == 8 or #chunks < 8 and - str:match('::') and not str:gsub("::", "", 1):match('::') then - for _,v in pairs(chunks) do - if #v > 0 and tonumber(v, 16) > 65535 then - return false - end - end - return str - end - return nil - end - - local ip = getIP(authority) - if ip then - self.host = ip - elseif type(ip) == 'nil' then - -- domain - if authority ~= '' and not self.host then - local host = authority:lower() - if string.match(host, '^[%d%a%-%.]+$') ~= nil and - string.sub(host, 0, 1) ~= '.' and - string.sub(host, -1) ~= '.' and - string.find(host, '%.%.') == nil then - self.host = host - end - end - end - - if self.userinfo then - local userinfo = self.userinfo - userinfo = userinfo:gsub(':([^:]*)$', function(v) - self.password = v - return '' - end) - if string.find(userinfo, "^[%w%+%.]+$") then - self.user = userinfo - else - -- incorrect userinfo - self.userinfo = nil - self.user = nil - self.password = nil - end - end - - return authority -end - ---- Parse the url into the designated parts. --- Depending on the url, the following parts can be available: --- scheme, userinfo, user, password, authority, host, port, path, --- query, fragment --- @param url Url string --- @return a table with the different parts and a few other functions -function M.parse(url) - local comp = {} - M.setAuthority(comp, "") - M.setQuery(comp, "") - - local url = tostring(url or '') - url = url:gsub('#(.*)$', function(v) - comp.fragment = v - return '' - end) - url =url:gsub('^([%w][%w%+%-%.]*)%:', function(v) - comp.scheme = v:lower() - return '' - end) - url = url:gsub('%?(.*)', function(v) - M.setQuery(comp, v) - return '' - end) - url = url:gsub('^//([^/]*)', function(v) - M.setAuthority(comp, v) - return '' - end) - - comp.path = url:gsub("([^/]+)", function (s) return encode(decode(s), M.options.legal_in_path) end) - - setmetatable(comp, { - __index = M, - __tostring = M.build, - __concat = concat, - __div = M.addSegment - }) - return comp -end - ---- removes dots and slashes in urls when possible --- This function will also remove multiple slashes --- @param path The string representing the path to clean --- @return a string of the path without unnecessary dots and segments -function M.removeDotSegments(path) - local fields = {} - if string.len(path) == 0 then - return "" - end - local startslash = false - local endslash = false - if string.sub(path, 1, 1) == "/" then - startslash = true - end - if (string.len(path) > 1 or startslash == false) and string.sub(path, -1) == "/" then - endslash = true - end - - path:gsub('[^/]+', function(c) table.insert(fields, c) end) - - local new = {} - local j = 0 - - for i,c in ipairs(fields) do - if c == '..' then - if j > 0 then - j = j - 1 - end - elseif c ~= "." then - j = j + 1 - new[j] = c - end - end - local ret = "" - if #new > 0 and j > 0 then - ret = table.concat(new, '/', 1, j) - else - ret = "" - end - if startslash then - ret = '/'..ret - end - if endslash then - ret = ret..'/' - end - return ret -end - -local function reducePath(base_path, relative_path) - if string.sub(relative_path, 1, 1) == "/" then - return '/' .. string.gsub(relative_path, '^[%./]+', '') - end - local path = base_path - local startslash = string.sub(path, 1, 1) ~= "/"; - if relative_path ~= "" then - path = (startslash and '' or '/') .. path:gsub("[^/]*$", "") - end - path = path .. relative_path - path = path:gsub("([^/]*%./)", function (s) - if s ~= "./" then return s else return "" end - end) - path = string.gsub(path, "/%.$", "/") - local reduced - while reduced ~= path do - reduced = path - path = string.gsub(reduced, "([^/]*/%.%./)", function (s) - if s ~= "../../" then return "" else return s end - end) - end - path = string.gsub(path, "([^/]*/%.%.?)$", function (s) - if s ~= "../.." then return "" else return s end - end) - local reduced - while reduced ~= path do - reduced = path - path = string.gsub(reduced, '^/?%.%./', '') - end - return (startslash and '' or '/') .. path -end - ---- builds a new url by using the one given as parameter and resolving paths --- @param other A string or a table representing a url --- @return a new url table -function M:resolve(other) - if type(self) == "string" then - self = M.parse(self) - end - if type(other) == "string" then - other = M.parse(other) - end - if other.scheme then - return other - else - other.scheme = self.scheme - if not other.authority or other.authority == "" then - other:setAuthority(self.authority) - if not other.path or other.path == "" then - other.path = self.path - local query = other.query - if not query or not next(query) then - other.query = self.query - end - else - other.path = reducePath(self.path, other.path) - end - end - return other - end -end - ---- normalize a url path following some common normalization rules --- described on The URL normalization page of Wikipedia --- @return the normalized path -function M:normalize() - if type(self) == 'string' then - self = M.parse(self) - end - if self.path then - local path = self.path - path = reducePath(path, "") - -- normalize multiple slashes - path = string.gsub(path, "//+", "/") - self.path = path - end - return self -end - -local hex_to_char = function(x) - return string.char(tonumber(x, 16)) -end - -M.unescape = function(url) - return url:gsub("%%(%x%x)", hex_to_char) -end - -return M diff --git a/lua/kide/dap/codelldb.lua b/lua/kide/dap/codelldb.lua deleted file mode 100644 index 48493449..00000000 --- a/lua/kide/dap/codelldb.lua +++ /dev/null @@ -1,67 +0,0 @@ -local M = {} -local vscode = require("kide.core.vscode") -local utils = require("kide.core.utils") --- Update this path -M.extension_path = (function() - local epath = vscode.find_one("/vadimcn.vscode-lldb-*") - if epath then - return epath - elseif require("mason-registry").has_package("codelldb") then - return require("mason-registry").get_package("codelldb"):get_install_path() .. "/extension" - end -end)() -M.codelldb_path = (function() - if M.extension_path then - if utils.is_win then - return vim.fn.glob(M.extension_path .. "/adapter/codelldb.exe") - else - return vim.fn.glob(M.extension_path .. "/adapter/codelldb") - end - end -end)() -M.liblldb_path = (function() - if M.extension_path then - if utils.is_mac then - return vim.fn.glob(M.extension_path .. "/lldb/lib/liblldb.dylib") - elseif utils.is_win then - return vim.fn.glob(M.extension_path .. "/lldb/bin/liblldb.dll") - else - return vim.fn.glob(M.extension_path .. "/lldb/lib/liblldb.so") - end - end -end)() - -M.setup = function() - if not M.extension_path then - vim.notify("codelldb not found", vim.log.levels.WARN) - return false - end - local dap = require("dap") - dap.adapters.codelldb = { - type = "server", - port = "${port}", - executable = { - command = M.codelldb_path, - args = { "--liblldb", M.liblldb_path, "--port", "${port}" }, - -- On windows you may have to uncomment this: - -- detached = false, - }, - } - - dap.configurations.cpp = { - { - name = "Launch file", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") - end, - cwd = "${workspaceFolder}", - stopOnEntry = false, - }, - } - dap.configurations.c = dap.configurations.cpp - -- dap.configurations.rust = dap.configurations.cpp - return true -end -return M diff --git a/lua/kide/dap/gdscript.lua b/lua/kide/dap/gdscript.lua deleted file mode 100644 index 71174c70..00000000 --- a/lua/kide/dap/gdscript.lua +++ /dev/null @@ -1,20 +0,0 @@ -local M = {} - -M.setup = function() - local dap = require("dap") - dap.adapters.godot = { - type = "server", - host = "127.0.0.1", - port = 6006, - } - dap.configurations.gdscript = { - { - type = "godot", - request = "launch", - name = "Launch scene", - project = "${workspaceFolder}", - launch_scene = true, - }, - } -end -return M diff --git a/lua/kide/dap/init.lua b/lua/kide/dap/init.lua deleted file mode 100644 index c6a15b51..00000000 --- a/lua/kide/dap/init.lua +++ /dev/null @@ -1,9 +0,0 @@ -require("kide.dap.codelldb").setup() -require("kide.dap.gdscript").setup() -require("kide.dap.zig").setup() -vim.fn.sign_define("DapBreakpoint", { text = "", texthl = "Debug", linehl = "", numhl = "" }) --- vim.fn.sign_define('DapBreakpoint', { text = '🔴', texthl = '', linehl = '', numhl = '' }) --- vim.fn.sign_define("DapBreakpointCondition", { text = "C", texthl = "", linehl = "", numhl = "" }) --- vim.fn.sign_define('DapBreakpointRejected', {text='R', texthl='', linehl='', numhl=''}) --- vim.fn.sign_define('DapLogPoint', {text='L', texthl='', linehl='', numhl=''}) --- vim.fn.sign_define('DapStopped', {text='→', texthl='', linehl='debugPC', numhl=''}) diff --git a/lua/kide/dap/zig.lua b/lua/kide/dap/zig.lua deleted file mode 100644 index b0902d28..00000000 --- a/lua/kide/dap/zig.lua +++ /dev/null @@ -1,19 +0,0 @@ -local M = {} -M.setup = function() - local dap = require("dap") - dap.configurations.zig = { - { - name = "Launch file", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input("Path to executable: ", vim.fn.glob(vim.fn.getcwd() .. "/zig-out/bin/"), "file") - end, - args = { "zig" }, - cwd = "${workspaceFolder}", - stopOnEntry = false, - }, - } - return true -end -return M diff --git a/lua/kide/icons/lspkind.lua b/lua/kide/icons/lspkind.lua new file mode 100644 index 00000000..2c05c749 --- /dev/null +++ b/lua/kide/icons/lspkind.lua @@ -0,0 +1,43 @@ +local lspkind = require "nvchad.icons.lspkind" +local M = {} +M.symbol_map = { + Text = { icon = lspkind.Text }, + Method = { icon = lspkind.Method, hl = "@method" }, + Function = { icon = lspkind.Function, hl = "@function" }, + Constructor = { icon = lspkind.Constructor, hl = "@constructor" }, + Field = { icon = lspkind.Field, hl = "@field" }, + Variable = { icon = lspkind.Variable, hl = "@constant" }, + Class = { icon = lspkind.Class, hl = "@type" }, + Interface = { icon = lspkind.Interface, hl = "@type" }, + Module = { icon = lspkind.Module, hl = "@namespace" }, + Property = { icon = lspkind.Property, hl = "@method" }, + Unit = { icon = lspkind.Unit }, + Value = { icon = lspkind.Value }, + Enum = { icon = lspkind.Enum, hl = "@lsp.type.enum" }, + Keyword = { icon = lspkind.Keyword }, + Snippet = { icon = lspkind.Snippet }, + Color = { icon = lspkind.Color }, + File = { icon = lspkind.File, hl = "@text.uri" }, + Reference = { icon = lspkind.Reference }, + Folder = { icon = lspkind.Folder }, + EnumMember = { icon = lspkind.EnumMember, hl = "@field" }, + Constant = { icon = lspkind.Constant, hl = "@constant" }, + Struct = { icon = lspkind.Struct, hl = "@type" }, + Event = { icon = lspkind.Event, hl = "@type" }, + Operator = { icon = lspkind.Operator, hl = "@operator" }, + TypeParameter = { icon = "", hl = "@parameter" }, + Key = { icon = lspkind.Keyword, hl = "@type" }, + Null = { icon = lspkind.Null, hl = "@type" }, + Namespace = { icon = lspkind.Namespace, hl = "@namespace" }, + Package = { icon = lspkind.Package, hl = "@namespace" }, + String = { icon = lspkind.String, hl = "@string" }, + Number = { icon = lspkind.Number, hl = "@number" }, + Boolean = { icon = lspkind.Boolean, hl = "@boolean" }, + Array = { icon = lspkind.Array, hl = "@constant" }, + Object = { icon = lspkind.Object, hl = "@type" }, + --------------------------------------------------------- + Component = { icon = "󰡀", hl = "@function" }, + Fragment = { icon = "", hl = "@constant" }, +} + +return M diff --git a/lua/kide/init.lua b/lua/kide/init.lua new file mode 100644 index 00000000..f0ca3c31 --- /dev/null +++ b/lua/kide/init.lua @@ -0,0 +1,3 @@ +require "kide.autocmds" +require("kide.core.utils.plantuml").setup() +require("kide.core.utils.maven").setup() diff --git a/lua/kide/lsp/clangd.lua b/lua/kide/lsp/clangd.lua deleted file mode 100644 index a5647075..00000000 --- a/lua/kide/lsp/clangd.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/lua/kide/lsp/gdscript.lua b/lua/kide/lsp/gdscript.lua deleted file mode 100644 index 4767469f..00000000 --- a/lua/kide/lsp/gdscript.lua +++ /dev/null @@ -1,6 +0,0 @@ -local M = {} -M.setup = function(opt) - require("lspconfig").gdscript.setup(opt) -end - -return M diff --git a/lua/kide/lsp/gopls.lua b/lua/kide/lsp/gopls.lua deleted file mode 100644 index a5647075..00000000 --- a/lua/kide/lsp/gopls.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/lua/kide/lsp/html.lua b/lua/kide/lsp/html.lua deleted file mode 100644 index a5647075..00000000 --- a/lua/kide/lsp/html.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/lua/kide/lsp/init.lua b/lua/kide/lsp/init.lua deleted file mode 100644 index 42a39139..00000000 --- a/lua/kide/lsp/init.lua +++ /dev/null @@ -1,191 +0,0 @@ -require("kide.lsp.lsp_ui").init() -local mason_lspconfig = require("mason-lspconfig") -mason_lspconfig.setup({ - ensure_installed = { - "lua_ls", - }, -}) - --- { key: 语言 value: 配置文件 } -local server_configs = { - lua_ls = require("kide.lsp.lua_ls"), - jdtls = require("kide.lsp.java"), - metals = require("kide.lsp.metals"), - clangd = require("kide.lsp.clangd"), - tsserver = require("kide.lsp.tsserver"), - html = require("kide.lsp.html"), - pyright = require("kide.lsp.pyright"), - rust_analyzer = require("kide.lsp.rust_analyzer"), - sqlls = require("kide.lsp.sqlls"), - gopls = require("kide.lsp.gopls"), - kotlin_language_server = {}, - vuels = {}, - lemminx = require("kide.lsp.lemminx"), - gdscript = require("kide.lsp.gdscript"), - rime_ls = require("kide.lsp.rime_ls"), - sourcekit = require("kide.lsp.sourcekit"), - sonarlint = require("kide.lsp.sonarlint"), - spring_boot = require("kide.lsp.spring_boot"), - taplo = { - setup = function(cfg) - require("lspconfig").taplo.setup(cfg) - end, - }, -} - -local utils = require("kide.core.utils") - -require("mason-lspconfig").setup_handlers({ - function(server_name) - local lspconfig = require("lspconfig") - -- tools config - local cfg = utils.or_default(server_configs[server_name], {}) - -- 自定义启动方式 - if cfg.setup then - return - end - - -- lspconfig - local scfg = utils.or_default(cfg.server, {}) - scfg.flags = { - debounce_text_changes = 150, - } - scfg.capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) - lspconfig[server_name].setup(scfg) - end, -}) - --- 自定义 LSP 启动方式 -for _, value in pairs(server_configs) do - if value.setup then - value.setup({ - flags = { - debounce_text_changes = 150, - }, - capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()), - }) - end -end - --- LspAttach 事件 -vim.api.nvim_create_augroup("LspAttach_keymap", {}) -vim.api.nvim_create_autocmd("LspAttach", { - group = "LspAttach_keymap", - callback = function(args) - if not (args.data and args.data.client_id) then - return - end - - local bufnr = args.buf - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client.name == "copilot" then - return - end - -- 绑定快捷键 - require("kide.core.keybindings").maplsp(client, bufnr, client.name == "null-ls") - end, -}) - -vim.api.nvim_create_augroup("LspAttach_inlay_hint", {}) -vim.api.nvim_create_autocmd("LspAttach", { - group = "LspAttach_inlay_hint", - callback = function(args) - if not (args.data and args.data.client_id) then - return - end - - local bufnr = args.buf - vim.api.nvim_buf_create_user_command(bufnr, "InlayHint", function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) - end, { - nargs = 0, - }) - -- local client = vim.lsp.get_client_by_id(args.data.client_id) - -- if client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then - -- vim.lsp.inlay_hint.enable(true) - -- end - end, -}) - -vim.api.nvim_create_augroup("LspAttach_navic", {}) -vim.api.nvim_create_autocmd("LspAttach", { - group = "LspAttach_navic", - callback = function(args) - if not (args.data and args.data.client_id) then - return - end - - local bufnr = args.buf - local client = vim.lsp.get_client_by_id(args.data.client_id) - if client.name == "spring-boot" then - return - end - if client.server_capabilities.documentSymbolProvider then - vim.opt_local.winbar = "%{%v:lua.require'nvim-navic'.get_location()%}" - require("nvim-navic").attach(client, bufnr) - end - end, -}) - -local CLIENT_CACHE = {} -local function clientCache(client_id) - if not CLIENT_CACHE[client_id] then - CLIENT_CACHE[client_id] = { - CursorHold = {}, - CursorHoldI = {}, - CursorMoved = {}, - } - end - return CLIENT_CACHE[client_id] -end -vim.api.nvim_create_autocmd("LspAttach", { - callback = function(args) - local bufnr = args.buf - local client = vim.lsp.get_client_by_id(args.data.client_id) - - if client.server_capabilities.documentHighlightProvider then - if not clientCache(args.data.client_id).CursorHold[bufnr] then - clientCache(args.data.client_id).CursorHold[bufnr] = vim.api.nvim_create_autocmd("CursorHold", { - buffer = bufnr, - callback = function() - vim.lsp.buf.document_highlight() - end, - }) - end - if not clientCache(args.data.client_id).CursorHoldI[bufnr] then - clientCache(args.data.client_id).CursorHoldI[bufnr] = vim.api.nvim_create_autocmd("CursorHoldI", { - buffer = bufnr, - callback = function() - vim.lsp.buf.document_highlight() - end, - }) - end - if not clientCache(args.data.client_id).CursorMoved[bufnr] then - clientCache(args.data.client_id).CursorMoved[bufnr] = vim.api.nvim_create_autocmd("CursorMoved", { - buffer = bufnr, - callback = function() - vim.lsp.buf.clear_references() - end, - }) - end - end - end, -}) -vim.api.nvim_create_autocmd("LspDetach", { - callback = function(args) - local bufnr = args.buf - -- local client = vim.lsp.get_client_by_id(args.data.client_id) - if clientCache(args.data.client_id).CursorHold[bufnr] then - vim.api.nvim_del_autocmd(clientCache(args.data.client_id).CursorHold[bufnr]) - clientCache(args.data.client_id).CursorHold[bufnr] = nil - end - if clientCache(args.data.client_id).CursorHoldI[bufnr] then - vim.api.nvim_del_autocmd(clientCache(args.data.client_id).CursorHoldI[bufnr]) - clientCache(args.data.client_id).CursorHoldI[bufnr] = nil - end - if clientCache(args.data.client_id).CursorMoved[bufnr] then - vim.api.nvim_del_autocmd(clientCache(args.data.client_id).CursorMoved[bufnr]) - clientCache(args.data.client_id).CursorMoved[bufnr] = nil - end - end, -}) diff --git a/lua/kide/lsp/java.lua b/lua/kide/lsp/java.lua index b2d89c96..bf5a13c6 100644 --- a/lua/kide/lsp/java.lua +++ b/lua/kide/lsp/java.lua @@ -7,7 +7,7 @@ local env = { JDTLS_WORKSPACE = vim.env["JDTLS_WORKSPACE"], JOL_JAR = vim.env["JOL_JAR"], } -local maven = require("kide.core.utils.maven") +local maven = require "kide.core.utils.maven" local jdtls_java = (function() local jdtls_run_java = env.JDTLS_RUN_JAVA @@ -20,10 +20,7 @@ local jdtls_java = (function() end return "java" end)() -local utils = require("kide.core.utils") -local function or_default(a, v) - return utils.or_default(a, v) -end +local utils = require "kide.core.utils" local function get_java_ver_home(v, dv) return vim.env["JAVA_" .. v .. "_HOME"] or dv @@ -33,10 +30,10 @@ local function get_java_ver_sources(v, dv) end local function get_jdtls_workspace() - return or_default(env.JDTLS_WORKSPACE, env.HOME .. "/.jdtls-workspace/") + return env.JDTLS_WORKSPACE or env.HOME .. "/.jdtls-workspace/" end -local vscode = require("kide.core.vscode") +local vscode = require "kide.core.vscode" local function get_jol_jar() return env.JOL_JAR or "/opt/software/java/jol-cli-0.16-full.jar" @@ -94,24 +91,24 @@ local runtimes = (function() end end if #result == 0 then - vim.notify("Please config Java runtimes (JAVA_17_HOME...)") + vim.notify "Please config Java runtimes (JAVA_17_HOME...)" end return result end)() -- local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") -local root_dir = require("jdtls.setup").find_root({ ".git", "mvnw", "gradlew" }) +local root_dir = require("jdtls.setup").find_root { ".git", "mvnw", "gradlew" } local rwdir = root_dir or vim.fn.getcwd() -local workspace_dir = get_jdtls_workspace() .. require("md5").sumhexa(rwdir) +local workspace_dir = get_jdtls_workspace() .. require("kide.core.utils.md5").sumhexa(rwdir) -- local jdtls_path = vscode.find_one("/redhat.java-*/server") local function get_jdtls_path() - return or_default(env.JDTLS_HOME, vscode.find_one("/redhat.java-*/server")) + return env.JDTLS_HOME or vscode.find_one "/redhat.java-*/server" end local function jdtls_launcher() local jdtls_path = get_jdtls_path() if jdtls_path then - elseif require("mason-registry").has_package("jdtls") then + elseif require("mason-registry").has_package "jdtls" then jdtls_path = require("mason-registry").get_package("jdtls"):get_install_path() end local jdtls_config = nil @@ -159,11 +156,11 @@ local bundles = {} -- This bundles definition is the same as in the previous section (java-debug installation) local vscode_java_debug_path = (function() - local p = vscode.find_one("/vscjava.vscode-java-debug-*/server") + local p = vscode.find_one "/vscjava.vscode-java-debug-*/server" if p then return p end - if require("mason-registry").has_package("java-debug-adapter") then + if require("mason-registry").has_package "java-debug-adapter" then return require("mason-registry").get_package("java-debug-adapter"):get_install_path() .. "/extension/server" end end)() @@ -177,11 +174,11 @@ end -- /opt/software/lsp/java/vscode-java-test/server -- vim.list_extend(bundles, vim.split(vim.fn.glob("/opt/software/lsp/java/vscode-java-test/server/*.jar"), "\n")); local vscode_java_test_path = (function() - local p = vscode.find_one("/vscjava.vscode-java-test-*/server") + local p = vscode.find_one "/vscjava.vscode-java-test-*/server" if p then return p end - if require("mason-registry").has_package("java-test") then + if require("mason-registry").has_package "java-test" then return require("mason-registry").get_package("java-test"):get_install_path() .. "/extension/server" end end)() @@ -197,7 +194,7 @@ if vscode_java_test_path then end -- /opt/software/lsp/java/vscode-java-decompiler/server/ -local java_decoompiler_path = vscode.find_one("/dgileadi.java-decompiler-*/server") +local java_decoompiler_path = vscode.find_one "/dgileadi.java-decompiler-*/server" if java_decoompiler_path then vim.list_extend(bundles, vim.split(vim.fn.glob(java_decoompiler_path .. "/*.jar"), "\n")) end @@ -205,12 +202,12 @@ end -- /opt/software/lsp/java/vscode-java-dependency/jdtls.ext/ -- vim.list_extend(bundles, vim.split(vim.fn.glob("/opt/software/lsp/java/vscode-java-dependency/jdtls.ext/com.microsoft.jdtls.ext.core/target/com.microsoft.jdtls.ext.core-*.jar"), "\n")); -- /opt/software/lsp/java/vscode-java-dependency/server/ -local java_dependency_path = vscode.find_one("/vscjava.vscode-java-dependency-*/server") +local java_dependency_path = vscode.find_one "/vscjava.vscode-java-dependency-*/server" if java_dependency_path then vim.list_extend(bundles, vim.split(vim.fn.glob(java_dependency_path .. "/*.jar"), "\n")) end -local vscode_pde_path = vscode.find_one("/yaozheng.vscode-pde-*/server") +local vscode_pde_path = vscode.find_one "/yaozheng.vscode-pde-*/server" if vscode_pde_path and "Y" == vim.env["VSCODE_PDE_ENABLE"] then vim.list_extend(bundles, vim.split(vim.fn.glob(vscode_pde_path .. "/*.jar"), "\n")) end @@ -341,7 +338,7 @@ config.commands["_java.reloadBundles.command"] = function() return {} end -local jdtls = require("jdtls") +local jdtls = require "jdtls" jdtls.jol_path = get_jol_jar() local extendedClientCapabilities = jdtls.extendedClientCapabilities @@ -394,8 +391,8 @@ local function test_with_profile(test_fn) local async_profiler_so = get_async_profiler_ddl() local event = "event=" .. choice local vmArgs = "-ea -agentpath:" .. async_profiler_so .. "=start," - vmArgs = vmArgs .. event .. ",file=" .. utils.tmpdir_file("profile.jfr") - test_fn({ + vmArgs = vmArgs .. event .. ",file=" .. utils.tmpdir_file "profile.jfr" + test_fn { config_overrides = { vmArgs = vmArgs, noDebug = true, @@ -405,94 +402,17 @@ local function test_with_profile(test_fn) "java -jar " .. get_async_profiler_cov() .. " jfr2flame " - .. utils.tmpdir_file("profile.jfr") + .. utils.tmpdir_file "profile.jfr" .. " " - .. utils.tmpdir_file("profile.html") + .. utils.tmpdir_file "profile.html" ) - utils.open_fn(utils.tmpdir_file("profile.html")) + utils.open_fn(utils.tmpdir_file "profile.html") end, - }) + } end) end end -config["on_attach"] = function(client, buffer) - local function desc_opts(desc) - return { silent = true, buffer = buffer, desc = desc } - end - - local function with_compile(fn) - return function() - if vim.bo.modified then - vim.cmd("w") - end - client.request_sync("java/buildWorkspace", false, 5000, buffer) - fn() - end - end - vim.keymap.set("n", "dc", with_compile(jdtls.test_class), desc_opts("Test class")) - vim.keymap.set("n", "dm", with_compile(jdtls.test_nearest_method), desc_opts("Test method")) - vim.keymap.set("n", "ds", with_compile(jdtls.pick_test), desc_opts("Select test")) - vim.keymap.set("n", "crv", jdtls.extract_variable, desc_opts("Extract variable")) - vim.keymap.set("v", "crm", [[lua require('jdtls').extract_method(true)]], desc_opts("Extract method")) - vim.keymap.set("n", "crc", jdtls.extract_constant, desc_opts("Extract constant")) - - if M.async_profiler_home then - vim.keymap.set( - "n", - "dM", - with_compile(test_with_profile(jdtls.test_nearest_method)), - desc_opts("Test method with profiling") - ) - end - - local create_command = vim.api.nvim_buf_create_user_command - create_command(buffer, "OR", require("jdtls").organize_imports, { - nargs = 0, - }) - - require("java-deps").attach(client, buffer, root_dir) - create_command(buffer, "JavaProjects", require("java-deps").toggle_outline, { - nargs = 0, - }) - -- vim.notify(vim.api.nvim_buf_get_name(bufnr), vim.log.levels.INFO) - - create_command( - buffer, - "JdtRun", - with_compile(function() - local main_config_opts = { - verbose = false, - on_ready = require("dap")["continue"], - } - require("jdtls.dap").setup_dap_main_class_configs(main_config_opts) - end), - { - nargs = 0, - } - ) -end - -local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) -if capabilities.textDocument.foldingRange then - capabilities.textDocument.foldingRange.dynamicRegistration = false - capabilities.textDocument.foldingRange.lineFoldingOnly = true -else - capabilities.textDocument.foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true, - } -end --- capabilities.experimental = { --- hoverActions = true, --- hoverRange = true, --- serverStatusNotification = true, --- snippetTextEdit = true, --- codeActionGroup = true, --- ssr = true, --- } - -config.capabilities = capabilities config.flags = { debounce_text_changes = 150, } @@ -507,12 +427,76 @@ config.handlers["language/status"] = function(_, s) end M.config = config -M.start = function(_) +M.start = function() jdtls.start_or_attach(config, { dap = { hotcodereplace = "auto" } }) end M.setup = function(opts) - require("kide.lsp.utils.jdtls").customize_jdtls() + local on_attach = opts.on_attach + config.on_attach = function(client, buffer) + vim.api.nvim_buf_set_option(buffer, "shiftwidth", 4) + vim.api.nvim_buf_set_option(buffer, "tabstop", 4) + vim.api.nvim_buf_set_option(buffer, "softtabstop", 4) + local function desc_opts(desc) + return { silent = true, buffer = buffer, desc = desc } + end + + local function with_compile(fn) + return function() + if vim.bo.modified then + vim.cmd "w" + end + client.request_sync("java/buildWorkspace", false, 5000, buffer) + fn() + end + end + vim.keymap.set("n", "dc", with_compile(jdtls.test_class), desc_opts "Test class") + vim.keymap.set("n", "dm", with_compile(jdtls.test_nearest_method), desc_opts "Test method") + vim.keymap.set("n", "ds", with_compile(jdtls.pick_test), desc_opts "Select test") + vim.keymap.set("n", "crv", jdtls.extract_variable, desc_opts "Extract variable") + vim.keymap.set("v", "crm", [[lua require('jdtls').extract_method(true)]], desc_opts "Extract method") + vim.keymap.set("n", "crc", jdtls.extract_constant, desc_opts "Extract constant") + + if M.async_profiler_home then + vim.keymap.set( + "n", + "dM", + with_compile(test_with_profile(jdtls.test_nearest_method)), + desc_opts "Test method with profiling" + ) + end + + local create_command = vim.api.nvim_buf_create_user_command + create_command(buffer, "OR", require("jdtls").organize_imports, { + nargs = 0, + }) + + -- require("java-deps").attach(client, buffer, root_dir) + -- create_command(buffer, "JavaProjects", require("java-deps").toggle_outline, { + -- nargs = 0, + -- }) + + create_command( + buffer, + "JdtRun", + with_compile(function() + local main_config_opts = { + verbose = false, + on_ready = require("dap")["continue"], + } + require("jdtls.dap").setup_dap_main_class_configs(main_config_opts) + end), + { + nargs = 0, + } + ) + + on_attach(client, buffer) + end + + config.capabilities = opts.capabilities + config.on_init = opts.on_init + -- require("kide.lsp.utils.jdtls").customize_jdtls() local group = vim.api.nvim_create_augroup("kide_jdtls_java", { clear = true }) vim.api.nvim_create_autocmd({ "FileType" }, { group = group, @@ -522,7 +506,7 @@ M.setup = function(opts) if e.file == "java" and vim.bo[e.buf].buftype == "nofile" then -- ignore else - M.start(opts) + M.start() end end, }) diff --git a/lua/kide/lsp/jsonls.lua b/lua/kide/lsp/jsonls.lua deleted file mode 100644 index a5647075..00000000 --- a/lua/kide/lsp/jsonls.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/lua/kide/lsp/lemminx.lua b/lua/kide/lsp/lemminx.lua index e82bb747..0de6cc66 100644 --- a/lua/kide/lsp/lemminx.lua +++ b/lua/kide/lsp/lemminx.lua @@ -1,10 +1,10 @@ local M = {} local lemminx_home = vim.env["LEMMINX_HOME"] -if lemminx_home then - M.setup = function(opt) - local lspconfig = require("lspconfig") - local utils = require("kide.core.utils") +M.setup = function(opt) + if lemminx_home then + local lspconfig = require "lspconfig" + local utils = require "kide.core.utils" local lemminx_jars = {} for _, bundle in ipairs(vim.split(vim.fn.glob(lemminx_home .. "/*.jar"), "\n")) do diff --git a/lua/kide/lsp/lsp_ui.lua b/lua/kide/lsp/lsp_ui.lua deleted file mode 100644 index c0246408..00000000 --- a/lua/kide/lsp/lsp_ui.lua +++ /dev/null @@ -1,277 +0,0 @@ -local M = {} -local lspkind_symbol_map = { - 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 = "", -} - --- remove obsolete TS* highlight groups https://github.com/nvim-treesitter/nvim-treesitter/pull/3656 -M.symbol_map = { - Text = { icon = lspkind_symbol_map.Text }, - Method = { icon = lspkind_symbol_map.Method, hl = "@method" }, - Function = { icon = lspkind_symbol_map.Function, hl = "@function" }, - Constructor = { icon = lspkind_symbol_map.Constructor, hl = "@constructor" }, - Field = { icon = lspkind_symbol_map.Field, hl = "@field" }, - Variable = { icon = lspkind_symbol_map.Variable, hl = "@constant" }, - Class = { icon = lspkind_symbol_map.Class, hl = "@type" }, - Interface = { icon = lspkind_symbol_map.Interface, hl = "@type" }, - Module = { icon = lspkind_symbol_map.Module, hl = "@namespace" }, - Property = { icon = lspkind_symbol_map.Property, hl = "@method" }, - Unit = { icon = lspkind_symbol_map.Unit }, - Value = { icon = lspkind_symbol_map.Value }, - Enum = { icon = lspkind_symbol_map.Enum, hl = "TSType" }, - Keyword = { icon = lspkind_symbol_map.Keyword }, - Snippet = { icon = lspkind_symbol_map.Snippet }, - Color = { icon = lspkind_symbol_map.Color }, - File = { icon = lspkind_symbol_map.File, hl = "@text.uri" }, - Reference = { icon = lspkind_symbol_map.Reference }, - Folder = { icon = lspkind_symbol_map.Folder }, - EnumMember = { icon = lspkind_symbol_map.EnumMember, hl = "@field" }, - Constant = { icon = lspkind_symbol_map.Constant, hl = "@constant" }, - Struct = { icon = lspkind_symbol_map.Struct, hl = "@type" }, - Event = { icon = lspkind_symbol_map.Event, hl = "@type" }, - Operator = { icon = lspkind_symbol_map.Operator, hl = "@operator" }, - TypeParameter = { icon = "", hl = "@parameter" }, - --------------------------------------------------------- - Namespace = { icon = "", hl = "@namespace" }, - Package = { icon = "", hl = "@namespace" }, - String = { icon = "", hl = "@string" }, - Number = { icon = "", hl = "@number" }, - Boolean = { icon = "", hl = "@boolean" }, - Array = { icon = "", hl = "@constant" }, - Object = { icon = "", hl = "@type" }, - Key = { icon = "󰌋", hl = "@type" }, - Null = { icon = "󰟢", hl = "@type" }, - Component = { icon = "󰡀", hl = "@function" }, - Fragment = { icon = "", hl = "@constant" }, -} - -M.window = { - winhighlight = "Normal:Normal,FloatBorder:Normal,CursorLine:Visual,Search:None", -} - -M.hover_actions = { - border = { - { "┌", "FloatBorder" }, - { "─", "FloatBorder" }, - { "┐", "FloatBorder" }, - { "│", "FloatBorder" }, - { "┘", "FloatBorder" }, - { "─", "FloatBorder" }, - { "└", "FloatBorder" }, - { "│", "FloatBorder" }, - }, - style = "fillchars", - -- Maximal width of the hover window. Nil means no max. - max_width = 80, - - -- Maximal height of the hover window. Nil means no max. - max_height = 20, - - -- whether the hover action window gets automatically focused - -- default: false - auto_focus = false, -} - -M.signs = { - closed = "", - opened = "", -} - -M.diagnostics = { - icons = { - hint = "", - info = "", - warning = "", - error = "", - }, -} - --- LSP 相关美化参考 https://github.com/NvChad/NvChad -local function lspSymbol(name, icon) - local hl = "DiagnosticSign" .. name - vim.fn.sign_define(hl, { text = icon, numhl = hl, texthl = hl }) -end - -local function lspDiagnosticConf(lsp_ui) - local diagnostics_conf = { - virtual_text = true, - signs = true, - underline = true, - update_in_insert = false, - severity_sort = false, - } - lspSymbol("Error", lsp_ui.diagnostics.icons.error) - lspSymbol("Info", lsp_ui.diagnostics.icons.info) - lspSymbol("Hint", lsp_ui.diagnostics.icons.hint) - lspSymbol("Warn", lsp_ui.diagnostics.icons.warning) - if vim.fn.has("nvim-0.10") == 1 then - diagnostics_conf.signs = { - text = { - [vim.diagnostic.severity.ERROR] = lsp_ui.diagnostics.icons.error, - [vim.diagnostic.severity.WARN] = lsp_ui.diagnostics.icons.warning, - [vim.diagnostic.severity.HINT] = lsp_ui.diagnostics.icons.hint, - [vim.diagnostic.severity.INFO] = lsp_ui.diagnostics.icons.info, - }, - } - end - vim.diagnostic.config(diagnostics_conf) -end - --- 文档格式化 -local function markdown_format(input) - if input then - input = string.gsub(input, '%[([%a%$_]?[%.%w%(%)*"+,\\_%[%]%s :%-@<>]*)%]%(file:/[^%)]+%)', function(i1) - return "`" .. i1 .. "`" - end) - input = string.gsub(input, '%[([%a%$_]?[%.%w%(%)*"+,\\_%[%]%s :%-@<>]*)%]%(jdt://[^%)]+%)', function(i1) - return "`" .. i1 .. "`" - end) - end - return input -end - -local function lspDocUI(lsp_ui) - vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, lsp_ui.hover_actions) - - local function split_lines(value) - value = string.gsub(value, "\r\n?", "\n") - return vim.split(value, "\n", { plain = true }) - end - local function convert_input_to_markdown_lines(input, contents) - contents = contents or {} - -- MarkedString variation 1 - if type(input) == "string" then - input = markdown_format(input) - vim.list_extend(contents, split_lines(input)) - else - assert(type(input) == "table", "Expected a table for Hover.contents") - -- MarkupContent - if input.kind then - -- The kind can be either plaintext or markdown. - -- If it's plaintext, then wrap it in a block - - -- Some servers send input.value as empty, so let's ignore this :( - local value = input.value or "" - - if input.kind == "plaintext" then - -- wrap this in a block so that stylize_markdown - -- can properly process it as plaintext - value = string.format("\n%s\n", value) - end - - -- assert(type(value) == 'string') - vim.list_extend(contents, split_lines(value)) - -- MarkupString variation 2 - elseif input.language then - -- Some servers send input.value as empty, so let's ignore this :( - -- assert(type(input.value) == 'string') - table.insert(contents, "```" .. input.language) - vim.list_extend(contents, split_lines(input.value or "")) - table.insert(contents, "```") - -- By deduction, this must be MarkedString[] - else - -- Use our existing logic to handle MarkedString - for _, marked_string in ipairs(input) do - convert_input_to_markdown_lines(marked_string, contents) - end - end - end - if (contents[1] == "" or contents[1] == nil) and #contents == 1 then - return {} - end - return contents - end - - local function jhover(_, result, ctx, config) - config = config or {} - config.focus_id = ctx.method - if vim.api.nvim_get_current_buf() ~= ctx.bufnr then - -- Ignore result since buffer changed. This happens for slow language servers. - return - end - if not (result and result.contents) then - if config.silent ~= true then - vim.notify("No information available") - end - return - end - local markdown_lines = convert_input_to_markdown_lines(result.contents) - markdown_lines = vim.lsp.util.trim_empty_lines(markdown_lines) - if vim.tbl_isempty(markdown_lines) then - if config.silent ~= true then - vim.notify("No information available") - end - return - end - local bufnr, winnr = vim.lsp.util.open_floating_preview(markdown_lines, "markdown", config) - vim.api.nvim_win_set_option(winnr, "winhighlight", lsp_ui.window.winhighlight) - return bufnr, winnr - end - -- https://github.com/neovim/neovim/pull/25073 美化 hover - if vim.fn.has("nvim-0.10") == 0 then - vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(jhover, lsp_ui.hover_actions) - else - vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, lsp_ui.hover_actions) - end - vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(function(a, result, ctx, b) - local bufnr, winnr = vim.lsp.handlers.signature_help(a, result, ctx, b) - vim.api.nvim_win_set_option(winnr, "winhighlight", lsp_ui.window.winhighlight) - return bufnr, winnr - end, lsp_ui.hover_actions) -end - -local function cmpDocUI() - local source = require("cmp_nvim_lsp.source") - source.resolve = function(self, completion_item, callback) - -- client is stopped. - if self.client.is_stopped() then - return callback() - end - - -- client has no completion capability. - if not self:_get(self.client.server_capabilities, { "completionProvider", "resolveProvider" }) then - return callback() - end - - self:_request("completionItem/resolve", completion_item, function(_, response) - -- jdtls 文档格式化 - if self.client.name == "jdtls" and response and response.documentation then - response.documentation.value = markdown_format(response.documentation.value) - end - -- print(vim.inspect(response)) - callback(response or completion_item) - end) - end -end - -M.init = function() - local lsp_ui = M - lspDiagnosticConf(lsp_ui) - lspDocUI(lsp_ui) - cmpDocUI() -end - -return M diff --git a/lua/kide/lsp/lua_ls.lua b/lua/kide/lsp/lua_ls.lua deleted file mode 100644 index 5524b980..00000000 --- a/lua/kide/lsp/lua_ls.lua +++ /dev/null @@ -1,32 +0,0 @@ --- local runtime_path = vim.split(package.path, ";") --- table.insert(runtime_path, "lua/?.lua") --- table.insert(runtime_path, "lua/?/init.lua") -return { - server = { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - -- Setup your lua path - -- path = runtime_path, - }, - hint = { - enable = true, - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - }, - }, - }, -} diff --git a/lua/kide/lsp/metals.lua b/lua/kide/lsp/metals.lua deleted file mode 100644 index 2d20d0ed..00000000 --- a/lua/kide/lsp/metals.lua +++ /dev/null @@ -1,30 +0,0 @@ -local M = {} -local metals_config = require("metals").bare_config() -metals_config.settings = { - showImplicitArguments = true, - excludedPackages = { - "akka.actor.typed.javadsl", - "com.github.swagger.akka.javadsl", - }, - ammoniteJvmProperties = { "-Xmx1G", "-Xms100M", "-XX:+UseZGC" }, - serverProperties = { "-Xmx1G", "-Xms100M", "-XX:+UseZGC" }, -} --- metals_config.init_options.statusBarProvider = "on" -M.setup = function(opt) - metals_config.capabilities = opt.capabilities - metals_config.on_attach = function(client, buffer) - if opt.on_attach then - opt.on_attach(client, buffer) - end - end - local group = vim.api.nvim_create_augroup("kide_metals", { clear = true }) - vim.api.nvim_create_autocmd({ "FileType" }, { - group = group, - pattern = { "scala", "sbt" }, - callback = function() - require("metals").initialize_or_attach(metals_config) - end, - }) -end - -return M diff --git a/lua/kide/lsp/pyright.lua b/lua/kide/lsp/pyright.lua index 711bab84..8a509fc3 100644 --- a/lua/kide/lsp/pyright.lua +++ b/lua/kide/lsp/pyright.lua @@ -1,11 +1,17 @@ -return { - server = { - on_attach = function(_, bufnr) - local dap_py = require("dap-python") - local opts = { silent = true, buffer = bufnr } - vim.keymap.set("n", "dc", dap_py.test_class, opts) - vim.keymap.set("n", "dm", dap_py.test_method, opts) - vim.keymap.set("v", "ds", dap_py.debug_selection, opts) +local M = {} + +local lspconfig = require "lspconfig" +M.setup = function(opts) + local on_attach = opts.on_attach + local config = vim.tbl_deep_extend("keep", { + on_attach = function(client, bufnr) + local dap_py = require "dap-python" + vim.keymap.set("n", "dc", dap_py.test_class, { desc = "Dap Test Class" }) + vim.keymap.set("n", "dm", dap_py.test_method, { desc = "Dap Test Method" }) + vim.keymap.set("v", "ds", dap_py.debug_selection, { desc = "Dap Debug Selection" }) + on_attach(client, bufnr) end, - }, -} + }, opts) + lspconfig.pyright.setup(config) +end +return M diff --git a/lua/kide/lsp/rime_ls.lua b/lua/kide/lsp/rime_ls.lua deleted file mode 100644 index d3a92ca7..00000000 --- a/lua/kide/lsp/rime_ls.lua +++ /dev/null @@ -1,95 +0,0 @@ -local config = require("kide.config") -local utils = require("kide.core.utils") - -local M = {} - -function M.setup(opts) - if not config.env.rime_ls_bin then - return - end - -- global status - vim.g.rime_enabled = false - - -- update lualine - local function rime_status() - if vim.g.rime_enabled then - return "ㄓ" - else - return "" - end - end - - require("lualine").setup({ - sections = { - lualine_x = { rime_status, "encoding", "fileformat", "filetype" }, - }, - }) - - -- add rime-ls to lspconfig as a custom server - -- see `:h lspconfig-new` - local lspconfig = require("lspconfig") - local configs = require("lspconfig.configs") - if not configs.rime_ls then - configs.rime_ls = { - default_config = { - name = "rime_ls", - cmd = { config.env.rime_ls_bin }, - -- cmd = vim.lsp.rpc.connect('127.0.0.1', 9257), - filetypes = { "*" }, - single_file_support = true, - }, - settings = {}, - docs = { - description = [[ -https://www.github.com/wlh320/rime-ls - -A language server for librime -]], - }, - } - end - - local rime_on_attach = function(client, _) - local toggle_rime = function() - client.request("workspace/executeCommand", { command = "rime-ls.toggle-rime" }, function(_, result, ctx, _) - if ctx.client_id == client.id then - vim.g.rime_enabled = result - end - end) - end - -- keymaps for executing command - vim.keymap.set("n", "", function() - toggle_rime() - end) - vim.keymap.set("i", "", function() - toggle_rime() - end) - vim.keymap.set("n", "rs", function() - vim.lsp.buf.execute_command({ command = "rime-ls.sync-user-data" }) - end) - end - - local shared_data_dir = nil - if utils.is_mac then - shared_data_dir = "/Library/Input Methods/Squirrel.app/Contents/SharedSupport" - else - shared_data_dir = "/usr/share/rime-data" - end - - lspconfig.rime_ls.setup({ - init_options = { - enabled = vim.g.rime_enabled, - shared_data_dir = shared_data_dir, - user_data_dir = "~/.local/share/rime-ls", - log_dir = "~/.local/share/rime-ls", - max_candidates = 9, - trigger_characters = {}, - schema_trigger_character = "&", -- [since v0.2.0] 当输入此字符串时请求补全会触发 “方案选单” - }, - on_attach = rime_on_attach, - flags = opts.flags, - capabilities = opts.capabilities, - }) -end - -return M diff --git a/lua/kide/lsp/rust_analyzer.lua b/lua/kide/lsp/rust_analyzer.lua deleted file mode 100644 index 1c5ac30d..00000000 --- a/lua/kide/lsp/rust_analyzer.lua +++ /dev/null @@ -1,51 +0,0 @@ -local M = {} -local codelldb = require("kide.dap.codelldb") -local adapter = function() - if codelldb.extension_path then - return require("rust-tools.dap").get_codelldb_adapter(codelldb.codelldb_path, codelldb.liblldb_path) - end -end -local config = { - dap = { - adapter = adapter(), - }, - tools = { - inlay_hints = { - auto = false, - parameter_hints_prefix = " ", - other_hints_prefix = " ", - }, - }, - server = { - standalone = false, - settings = { - ["rust-analyzer"] = { - completion = { - postfix = { - enable = false, - }, - }, - checkOnSave = { - command = "clippy", - }, - }, - }, - }, -} -M.setup = function(opt) - local rt = require("rust-tools") - local on_attach = opt.on_attach - config.server = vim.tbl_deep_extend("keep", config.server, opt) - config.server.on_attach = function(client, bufnr) - if on_attach then - on_attach(client, bufnr) - end - -- Hover actions - vim.keymap.set("n", "ha", rt.hover_actions.hover_actions, { buffer = bufnr }) - -- Code action groups - vim.keymap.set("n", "ca", rt.code_action_group.code_action_group, { buffer = bufnr }) - end - rt.setup(config) -end - -return M diff --git a/lua/kide/lsp/sonarlint.lua b/lua/kide/lsp/sonarlint.lua index ed7005ab..01c72061 100644 --- a/lua/kide/lsp/sonarlint.lua +++ b/lua/kide/lsp/sonarlint.lua @@ -1,15 +1,15 @@ local M = {} -if "Y" == vim.env["SONARLINT_ENABLE"] then - M.setup = function() - local vscode = require("kide.core.vscode") - local utils = require("kide.core.utils") - local sonarlint_ls = vscode.find_one("/sonarsource.sonarlint-vscode*/server/sonarlint-ls.jar") +M.setup = function() + if "Y" == vim.env["SONARLINT_ENABLE"] then + local vscode = require "kide.core.vscode" + local utils = require "kide.core.utils" + local sonarlint_ls = vscode.find_one "/sonarsource.sonarlint-vscode*/server/sonarlint-ls.jar" if not sonarlint_ls then vim.notify("sonarlint not found", vim.log.levels.WARN) return end - local analyzer_path = vscode.find_one("/sonarsource.sonarlint-vscode*/analyzers") + local analyzer_path = vscode.find_one "/sonarsource.sonarlint-vscode*/analyzers" local analyzer_jar = vim.split(vim.fn.glob(analyzer_path .. "/*.jar"), "\n") @@ -21,14 +21,14 @@ if "Y" == vim.env["SONARLINT_ENABLE"] then "-analyzers", } vim.list_extend(cmd, analyzer_jar) - require("sonarlint").setup({ + require("sonarlint").setup { server = { cmd = cmd, }, filetypes = { "java", }, - }) + } end end return M diff --git a/lua/kide/lsp/sourcekit.lua b/lua/kide/lsp/sourcekit.lua deleted file mode 100644 index 230bd26d..00000000 --- a/lua/kide/lsp/sourcekit.lua +++ /dev/null @@ -1,8 +0,0 @@ -local M = {} -M.setup = function(opt) - require("lspconfig").sourcekit.setup({ - filetypes = { "swift" }, - }) -end - -return M diff --git a/lua/kide/lsp/spring_boot.lua b/lua/kide/lsp/spring_boot.lua deleted file mode 100644 index 5e583fb1..00000000 --- a/lua/kide/lsp/spring_boot.lua +++ /dev/null @@ -1,12 +0,0 @@ -local M = {} -M.setup = function(opts) - local config = { - server = opts, - } - - local ok, spring_boot = pcall(require, "spring_boot") - if ok then - spring_boot.setup(config) - end -end -return M diff --git a/lua/kide/lsp/sqlls.lua b/lua/kide/lsp/sqlls.lua deleted file mode 100644 index 97aeaddb..00000000 --- a/lua/kide/lsp/sqlls.lua +++ /dev/null @@ -1,2 +0,0 @@ -return { -} diff --git a/lua/kide/lsp/tsserver.lua b/lua/kide/lsp/tsserver.lua deleted file mode 100644 index a5647075..00000000 --- a/lua/kide/lsp/tsserver.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/lua/kide/lsp/utils/init.lua b/lua/kide/lsp/utils/init.lua deleted file mode 100644 index 50fadd81..00000000 --- a/lua/kide/lsp/utils/init.lua +++ /dev/null @@ -1,84 +0,0 @@ -local M = {} - -M.format_range_operator = function() - local old_func = vim.go.operatorfunc - _G.op_func_formatting = function() - local start = vim.api.nvim_buf_get_mark(0, "[") - local finish = vim.api.nvim_buf_get_mark(0, "]") - - local bfn = vim.api.nvim_get_current_buf() - vim.lsp.buf.format({ - bufnr = bfn, - filter = function(c) - return require("kide.lsp.utils").filter_format_lsp_client(c, bfn) - end, - range = { - start, - finish, - }, - }) - vim.go.operatorfunc = old_func - _G.op_func_formatting = nil - end - vim.go.operatorfunc = "v:lua.op_func_formatting" - vim.api.nvim_feedkeys("g@", "n", false) -end - --- 指定格式化 lsp_client -local format_lsp_mapping = {} -format_lsp_mapping["java"] = "jdtls" - --- sql_formatter -format_lsp_mapping["sql"] = "null-ls" -format_lsp_mapping["mysql"] = "null-ls" --- prettier -format_lsp_mapping["javascript"] = "null-ls" -format_lsp_mapping["javascriptreact"] = "null-ls" -format_lsp_mapping["typescript"] = "null-ls" -format_lsp_mapping["typescriptreact"] = "null-ls" -format_lsp_mapping["vue"] = "null-ls" -format_lsp_mapping["css"] = "null-ls" -format_lsp_mapping["scss"] = "null-ls" -format_lsp_mapping["less"] = "null-ls" -format_lsp_mapping["html"] = "null-ls" -format_lsp_mapping["json"] = "null-ls" -format_lsp_mapping["jsonc"] = "null-ls" -format_lsp_mapping["yaml"] = "null-ls" -format_lsp_mapping["markdown"] = "null-ls" -format_lsp_mapping["graphql"] = "null-ls" -format_lsp_mapping["handlebars"] = "null-ls" -format_lsp_mapping["nginx"] = "null-ls" - --- xmllint -format_lsp_mapping["xml"] = "lemminx" - --- taplo -format_lsp_mapping["toml"] = "taplo" - --- shfmt -format_lsp_mapping["sh"] = "null-ls" --- stylua -format_lsp_mapping["lua"] = "null-ls" - -format_lsp_mapping["http"] = "null-ls" - --- gofmt -format_lsp_mapping["go"] = "null-ls" - --- clang_format -format_lsp_mapping["c"] = "clangd" -format_lsp_mapping["cpp"] = "clangd" - --- black -format_lsp_mapping["python"] = "null-ls" - -M.filter_format_lsp_client = function(client, bufnr) - local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") - local cn = format_lsp_mapping[filetype] - if cn == nil and client.name ~= "null-ls" then - return true - end - return client.name == cn -end - -return M diff --git a/lua/kide/lsp/utils/jdtls.lua b/lua/kide/lsp/utils/jdtls.lua deleted file mode 100644 index d3e8ecb4..00000000 --- a/lua/kide/lsp/utils/jdtls.lua +++ /dev/null @@ -1,187 +0,0 @@ --- code from https://github.com/mfussenegger/nvim-jdtls/blob/f8fb45e05e/lua/jdtls.lua -local api = vim.api -local M = {} -function M.execute_command(command, callback, bufnr) - local clients = {} - local candidates = bufnr and vim.lsp.buf_get_clients(bufnr) or vim.lsp.get_active_clients() - for _, c in pairs(candidates) do - local command_provider = c.server_capabilities.executeCommandProvider - local commands = type(command_provider) == "table" and command_provider.commands or {} - if vim.tbl_contains(commands, command.command) then - table.insert(clients, c) - end - end - local num_clients = vim.tbl_count(clients) - if num_clients == 0 then - if bufnr then - -- User could've switched buffer to non-java file, try all clients - return M.execute_command(command, callback, nil) - else - vim.notify("No LSP client found that supports " .. command.command, vim.log.levels.ERROR) - return - end - end - - if num_clients > 1 then - vim.notify( - "Multiple LSP clients found that support " - .. command.command - .. " you should have at most one JDTLS server running", - vim.log.levels.WARN - ) - end - - local co - if not callback then - co = coroutine.running() - if co then - callback = function(err, resp) - coroutine.resume(co, err, resp) - end - end - end - clients[1].request("workspace/executeCommand", command, callback) - if co then - return coroutine.yield() - end -end ---- Open `jdt://` uri or decompile class contents and load them into the buffer ---- ---- nvim-jdtls by defaults configures a `BufReadCmd` event which uses this function. ---- You shouldn't need to call this manually. ---- ----@param fname string -function M.open_classfile(fname, buf, timeout_ms) - local uri - local use_cmd - if vim.startswith(fname, "jdt://") then - uri = fname - use_cmd = false - else - uri = vim.uri_from_fname(fname) - use_cmd = true - if not vim.startswith(uri, "file://") then - return - end - end - vim.bo[buf].modifiable = true - vim.bo[buf].swapfile = false - vim.bo[buf].buftype = "nofile" - -- This triggers FileType event which should fire up the lsp client if not already running - vim.bo[buf].filetype = "java" - vim.wait(timeout_ms, function() - return next(vim.lsp.get_active_clients({ name = "jdtls" })) ~= nil - end) - local client = vim.lsp.get_active_clients({ name = "jdtls" })[1] - assert(client, "Must have a `jdtls` client to load class file or jdt uri") - - local content - local function handler(err, result) - assert(not err, vim.inspect(err)) - if api.nvim_buf_is_valid(buf) then - content = result - api.nvim_buf_set_lines(buf, 0, -1, false, vim.split(result, "\n", { plain = true })) - vim.bo[buf].modifiable = false - end - end - - if not api.nvim_buf_is_valid(buf) then - return - end - - if use_cmd then - local command = { - command = "java.decompile", - arguments = { uri }, - } - M.execute_command(command, handler) - else - local params = { - uri = uri, - } - client.request("java/classFileContents", params, handler, buf) - end - -- Need to block. Otherwise logic could run that sets the cursor to a position - -- that's still missing. - vim.wait(timeout_ms, function() - return content ~= nil - end) -end - -M.customize_jdtls = function() - local function mk_buf_loop(sock, handle_buffer) - local buffer = "" - return function(err, chunk) - assert(not err, err) - if chunk then - buffer = buffer .. chunk - else - sock:close() - handle_buffer(buffer) - end - end - end - - -- 零时修改等上游修复后删除 - -- @see https://github.com/mfussenegger/nvim-jdtls/blob/master/lua/jdtls/junit.lua - local junit = require("jdtls.junit") - junit.mk_test_results = function(bufnr) - local tests = {} - local handle_buffer = function(buf) - junit.__parse(buf, tests) - end - return { - show = function() - local items = {} - local repl = require("dap.repl") - local num_failures = 0 - for _, test in ipairs(tests) do - if test.failed then - num_failures = num_failures + 1 - if test.method then - repl.append(" " .. test.method, "$") - end - for _, msg in ipairs(test.traces) do - local match = msg:match(string.format("at %s.%s", test.fq_class, test.method) .. "%(([%a%p]*:%d+)%)") - if match then - local lnum = vim.split(match, ":")[2] - local trace = table.concat(test.traces, "\n") - if #trace > 140 then - trace = trace:sub(1, 140) .. "..." - end - table.insert(items, { - bufnr = bufnr, - lnum = lnum, - text = test.method .. " " .. trace, - }) - end - repl.append(msg, "$") - end - else - repl.append(" " .. test.method, "$") - end - end - - if num_failures > 0 then - vim.fn.setqflist({}, "r", { - title = "jdtls-tests", - items = items, - }) - print( - "Tests finished. Results printed to dap-repl.", - #items > 0 and "Errors added to quickfix list" or "", - string.format("( %d / %d)", num_failures, #tests) - ) - else - print("Tests finished. Results printed to dap-repl. All", #tests, "succeeded") - end - return items - end, - mk_reader = function(sock) - return vim.schedule_wrap(mk_buf_loop(sock, handle_buffer)) - end, - } - end -end - -return M diff --git a/lua/kide/lsp/yaml-language-server.lua b/lua/kide/lsp/yaml-language-server.lua deleted file mode 100644 index a5647075..00000000 --- a/lua/kide/lsp/yaml-language-server.lua +++ /dev/null @@ -1 +0,0 @@ -return {} diff --git a/lua/kide/plugins/config/browse-nvim.lua b/lua/kide/plugins/config/browse-nvim.lua deleted file mode 100644 index 0ad53ad9..00000000 --- a/lua/kide/plugins/config/browse-nvim.lua +++ /dev/null @@ -1,53 +0,0 @@ -local browse = require("browse") - -browse.setup({ - -- search provider you want to use - provider = "google", -- default -}) - -local bookmarks = { - "https://docs.spring.io/spring-framework/docs/5.3.12/reference/html/", - "https://github.com/", - "https://stackoverflow.com/", - "https://mvnrepository.com/", - ["github"] = { - ["name"] = "search github from neovim", - ["code_search"] = "https://github.com/search?q=%s&type=code", - ["repo_search"] = "https://github.com/search?q=%s&type=repositories", - ["issues_search"] = "https://github.com/search?q=%s&type=issues", - ["pulls_search"] = "https://github.com/search?q=%s&type=pullrequests", - }, - ["maven"] = { - ["name"] = "search maven from neovim", - ["jar_search"] = "https://mvnrepository.com/search?q=%s", - }, -} - -local function command(name, rhs, opts) - opts = opts or {} - vim.api.nvim_create_user_command(name, rhs, opts) -end - -command("BrowseInputSearch", function() - browse.input_search() -end, {}) - -command("Browse", function() - browse.browse({ bookmarks = bookmarks }) -end, {}) - -command("BrowseBookmarks", function() - browse.open_bookmarks({ bookmarks = bookmarks }) -end, {}) - -command("BrowseDevdocsSearch", function() - browse.devdocs.search() -end, {}) - -command("BrowseDevdocsFiletypeSearch", function() - browse.devdocs.search_with_filetype() -end, {}) - -command("BrowseMdnSearch", function() - browse.mdn.search() -end, {}) diff --git a/lua/kide/plugins/config/bufferline.lua b/lua/kide/plugins/config/bufferline.lua deleted file mode 100644 index bfb6c347..00000000 --- a/lua/kide/plugins/config/bufferline.lua +++ /dev/null @@ -1,81 +0,0 @@ -local bufferline = require("bufferline") -bufferline.setup({ - options = { - mode = "buffers", - style_preset = bufferline.style_preset.minimal, - -- 使用 nvim 内置lsp - diagnostics = "nvim_lsp", - diagnostics_indicator = function(count, level, diagnostics_dict, context) - local s = " " - for e, n in pairs(diagnostics_dict) do - local sym = e == "error" and " " or (e == "warning" and " " or " ") - s = s .. n .. sym - end - return s - end, - -- 左侧让出 nvim-tree 的位置 - offsets = { - { - filetype = "NvimTree", - text = function() - return "File Explorer" - end, - padding = 1, - highlight = "Directory", - -- text_align = "center" - text_align = "left", - }, - { - filetype = "DiffviewFiles", - text = function() - return "DiffviewFilePanel" - end, - padding = 1, - highlight = "Directory", - -- text_align = "center" - text_align = "left", - }, - { - filetype = "Outline", - text = " Outline", - padding = 1, - highlight = "Directory", - text_align = "left", - }, - { - filetype = "flutterToolsOutline", - text = " Outline", - padding = 1, - highlight = "Directory", - text_align = "left", - }, - { - filetype = "dapui_watches", - text = "Debug", - padding = 1, - highlight = "Directory", - text_align = "left", - }, - { - filetype = "dbui", - text = "Databases", - padding = 1, - highlight = "Directory", - text_align = "left", - }, - { - filetype = "JavaProjects", - text = " JavaProjects", - padding = 1, - highlight = "Directory", - text_align = "left", - }, - }, - indicator = { - style = "none", - }, - color_icons = true, - show_buffer_close_icons = true, - show_close_icon = false, - }, -}) diff --git a/lua/kide/plugins/config/flutter-tools.lua b/lua/kide/plugins/config/flutter-tools.lua deleted file mode 100644 index 404f2d2c..00000000 --- a/lua/kide/plugins/config/flutter-tools.lua +++ /dev/null @@ -1,29 +0,0 @@ -require("flutter-tools").setup({ - lsp = { - color = { -- show the derived colours for dart variables - enabled = true, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10 - background = false, -- highlight the background - background_color = nil, -- required, when background is transparent (i.e. background_color = { r = 19, g = 17, b = 24},) - foreground = false, -- highlight the foreground - virtual_text = true, -- show the highlight using virtual text - virtual_text_str = "■", -- the virtual text character to highlight - }, - flags = { - debounce_text_changes = 150, - }, - capabilities = function(c) - require("cmp_nvim_lsp").default_capabilities(c) - return c - end, - -- see the link below for details on each option: - -- https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/tool/lsp_spec/README.md#client-workspace-configuration - settings = { - showTodos = true, - completeFunctionCalls = true, - renameFilesWithClasses = "prompt", -- "always" - enableSnippets = true, - updateImportsOnRename = true, -- Whether to update imports and other directives when files are renamed. Required for `FlutterRename` command. - }, - }, -}) -require("telescope").load_extension("flutter") diff --git a/lua/kide/plugins/config/gitsigns-nvim.lua b/lua/kide/plugins/config/gitsigns-nvim.lua deleted file mode 100644 index 9787e84b..00000000 --- a/lua/kide/plugins/config/gitsigns-nvim.lua +++ /dev/null @@ -1,91 +0,0 @@ -require("gitsigns").setup({ - signs = { - add = { hl = "DiffAdd", text = "", numhl = "GitSignsAddNr" }, - change = { hl = "DiffChange", text = "│", numhl = "GitSignsChangeNr" }, - delete = { hl = "DiffDelete", text = "", numhl = "GitSignsDeleteNr" }, - topdelete = { hl = "DiffDelete", text = "‾", numhl = "GitSignsDeleteNr" }, - changedelete = { hl = "GitSignsChangedelete", text = "", numhl = "GitSignsChangedeleteNr" }, - untracked = { hl = "GitSignsAdd", text = "│", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" }, - }, - 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 = true, -- Toggle with `:Gitsigns toggle_current_line_blame` - current_line_blame_opts = { - virt_text = true, - virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align' - delay = 400, - ignore_whitespace = false, - }, - current_line_blame_formatter = ", - ", - current_line_blame_formatter_opts = { - relative_time = false, - }, - sign_priority = 6, - update_debounce = 100, - status_formatter = nil, -- Use default - max_file_length = 40000, - preview_config = { - -- Options passed to nvim_open_win - border = "single", - style = "minimal", - relative = "cursor", - row = 0, - col = 1, - }, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns - - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end - - -- Navigation - map("n", "]c", function() - if vim.wo.diff then - return "]c" - end - vim.schedule(function() - gs.next_hunk() - end) - return "" - end, { expr = true }) - - map("n", "[c", function() - if vim.wo.diff then - return "[c" - end - vim.schedule(function() - gs.prev_hunk() - end) - return "" - end, { expr = true }) - - -- Actions - map({ "n", "v" }, "hs", ":Gitsigns stage_hunk") - map({ "n", "v" }, "hr", ":Gitsigns reset_hunk") - map("n", "hS", gs.stage_buffer) - map("n", "hu", gs.undo_stage_hunk) - map("n", "hR", gs.reset_buffer) - map("n", "hp", gs.preview_hunk) - map("n", "hb", function() - gs.blame_line({ full = true }) - end) - map("n", "tb", gs.toggle_current_line_blame) - map("n", "hd", gs.diffthis) - map("n", "hD", function() - gs.diffthis("~") - end) - map("n", "td", gs.toggle_deleted) - - -- Text object - map({ "o", "x" }, "ih", ":Gitsigns select_hunk") - end, -}) diff --git a/lua/kide/plugins/config/indent-blankline.lua b/lua/kide/plugins/config/indent-blankline.lua deleted file mode 100644 index 39a79223..00000000 --- a/lua/kide/plugins/config/indent-blankline.lua +++ /dev/null @@ -1,36 +0,0 @@ --- vim.opt.listchars:append("space:⋅") --- vim.opt.listchars:append("eol:↴") - -require("kide.theme.gruvbox").load_indent_blankline_highlights() -require("ibl").setup({ - exclude = { - filetypes = { - "lspinfo", - "packer", - "checkhealth", - "man", - "help", - "terminal", - "packer", - "git", - "gitcommit", - "text", - "txt", - "NvimTree", - "dashboard", - "alpha", - "Outline", - "flutterToolsOutline", - "TelescopePrompt", - "TelescopeResults", - "NeogitStatus", - "NeogitPopup", - "DiffviewFiles", - "TelescopePrompt", - "TelescopeResults", - "", - "dbui", - "dbout", - }, - }, -}) diff --git a/lua/kide/plugins/config/lualine.lua b/lua/kide/plugins/config/lualine.lua deleted file mode 100644 index 332d3d1d..00000000 --- a/lua/kide/plugins/config/lualine.lua +++ /dev/null @@ -1,156 +0,0 @@ -local config = { - options = { - icons_enabled = true, - theme = "gruvbox-material", - component_separators = { left = "", right = "" }, - section_separators = { left = "", right = "" }, - disabled_filetypes = { - "alpha", - }, - always_divide_middle = true, - }, - sections = { - lualine_a = { "mode" }, - lualine_b = { - "branch", - "diff", - "diagnostics", - }, - -- lualine_c = {'filename', 'lsp_progress'}, - lualine_c = { - { - function() - local names = {} - for _, server in pairs(vim.lsp.buf_get_clients(0)) do - table.insert(names, server.name) - end - if vim.tbl_isempty(names) then - return " [No LSP]" - else - return " [" .. table.concat(names, " ") .. "]" - end - end, - }, - "filename", - -- "navic", - }, - lualine_x = { - "encoding", - "fileformat", - "filetype", - }, - lualine_y = { "progress" }, - lualine_z = { "location" }, - }, - inactive_sections = { - lualine_a = {}, - -- lualine_b = {function() return require('lsp-status').status() end}, - lualine_b = {}, - lualine_c = { "filename" }, - lualine_x = { "location" }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - extensions = { "quickfix", "toggleterm", "fugitive", "symbols-outline", "nvim-dap-ui" }, -} - -local dap = {} -dap.sections = { - lualine_a = { - { "filename", file_status = false }, - }, -} -dap.filetypes = { - "dap-terminal", - "dapui_console", -} -table.insert(config.extensions, dap) - --- NvimTree -local nerdtree = require("lualine.extensions.nerdtree") - -local nvim_tree = {} -nvim_tree.sections = vim.deepcopy(nerdtree.sections) -nvim_tree.sections.lualine_b = { "branch" } -nvim_tree.filetypes = { - "NvimTree", -} -table.insert(config.extensions, nvim_tree) - --- nvim-sqls extensions --- local db_connection_value = "default" --- local db_database_value = "default" --- require("sqls.events").add_subscriber("connection_choice", function(event) --- local cs = vim.split(event.choice, " ") --- db_connection_value = cs[3] --- local db = vim.split(cs[4], "/") --- if db[2] and db_database_value == "default" then --- db_database_value = db[2] --- end --- end) --- require("sqls.events").add_subscriber("database_choice", function(event) --- db_database_value = event.choice --- end) --- local function db_info() --- return db_connection_value .. "->" .. db_database_value --- end --- --- local sqls = {} --- sqls.sections = vim.deepcopy(config.sections) --- table.insert(sqls.sections.lualine_c, db_info) --- sqls.filetypes = { --- "sql", --- } --- table.insert(config.extensions, sqls) - --- DiffviewFilePanel -local diffview = {} -diffview.sections = { - lualine_a = { - { "filename", file_status = false }, - }, -} -diffview.filetypes = { - "DiffviewFiles", -} -table.insert(config.extensions, diffview) - --- db-ui -local dbui = {} -dbui.sections = { - lualine_a = { - { "filename", file_status = false }, - }, -} -dbui.filetypes = { - "dbui", - "dbout", -} -table.insert(config.extensions, dbui) - --- JavaProjects -local java_projects = {} -java_projects.sections = { - lualine_a = { - { "filename", file_status = false }, - }, -} -java_projects.filetypes = { - "JavaProjects", -} -table.insert(config.extensions, java_projects) - --- Flutter -local flutter = {} -flutter.sections = { - lualine_a = { - { "filename", file_status = false }, - }, -} -flutter.filetypes = { - "flutterToolsOutline", -} -table.insert(config.extensions, flutter) - -require("lualine").setup(config) diff --git a/lua/kide/plugins/config/null-ls.lua b/lua/kide/plugins/config/null-ls.lua deleted file mode 100644 index b71ef90a..00000000 --- a/lua/kide/plugins/config/null-ls.lua +++ /dev/null @@ -1,129 +0,0 @@ -local null_ls = require("null-ls") - --- register any number of sources simultaneously -local sources = { - null_ls.builtins.formatting.prettierd.with({ - filetypes = { - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "vue", - "css", - "scss", - "less", - "html", - "json", - "jsonc", - "yaml", - "markdown", - "graphql", - "handlebars", - }, - }), - -- null_ls.builtins.formatting.jq, - -- xml - -- null_ls.builtins.formatting.xmllint, - -- toml - -- null_ls.builtins.formatting.taplo, - -- sh - null_ls.builtins.formatting.shfmt, - -- lua - null_ls.builtins.formatting.stylua, - -- word - null_ls.builtins.diagnostics.write_good.with({ - method = null_ls.methods.DIAGNOSTICS_ON_SAVE, - }), - -- md - -- null_ls.builtins.diagnostics.markdownlint.with({ - -- method = null_ls.methods.DIAGNOSTICS_ON_SAVE, - -- }), - -- null_ls.builtins.code_actions.gitsigns, - -- sql - null_ls.builtins.formatting.sql_formatter.with({ - filetypes = { - "sql", - "mysql", - }, - }), - -- null_ls.builtins.formatting.google_java_format, - -- null_ls.builtins.diagnostics.semgrep, - -- null_ls.builtins.diagnostics.semgrep.with({ - -- method = null_ls.methods.DIAGNOSTICS_ON_SAVE, - -- extra_args = { "--config", "p/java" }, - -- }), - null_ls.builtins.formatting.gofmt, - -- null_ls.builtins.formatting.clang_format.with({ - -- filetypes = { - -- "c", - -- "cpp", - -- }, - -- }), - null_ls.builtins.formatting.nginx_beautifier, - - -- python - null_ls.builtins.formatting.black, - - -- swift - null_ls.builtins.formatting.swiftformat, -} - -local lsp_formatting = function(bufnr) - vim.lsp.buf.format({ - filter = function(client) - -- apply whatever logic you want (in this example, we'll only use null-ls) - return client.name == "null-ls" - end, - bufnr = bufnr, - }) -end - --- if you want to set up formatting on save, you can use this as a callback -local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - --- add to your shared on_attach callback -local on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - lsp_formatting(bufnr) - end, - }) - end -end - -if "Y" == vim.env["SEMGREP_ENABLE"] then - table.insert(sources, null_ls.builtins.diagnostics.semgrep) -end -if "Y" == vim.env["PMD_ENABLE"] then - table.insert( - sources, - null_ls.builtins.diagnostics.pmd.with({ - filetypes = { - "java", - "jsp", - }, - args = { - "check", - "--format", - "json", - "--dir", - "$FILENAME", - }, - extra_args = { - "--rulesets", - "category/java/bestpractices.xml,category/jsp/bestpractices.xml", - }, - }) - ) -end - -null_ls.setup({ - sources = sources, -}) - -require("null-ls").register(require("none-ls-shellcheck.diagnostics")) -require("null-ls").register(require("none-ls-shellcheck.code_actions")) diff --git a/lua/kide/plugins/config/nvim-cmp.lua b/lua/kide/plugins/config/nvim-cmp.lua deleted file mode 100644 index 66f65b1b..00000000 --- a/lua/kide/plugins/config/nvim-cmp.lua +++ /dev/null @@ -1,139 +0,0 @@ -local lspkind = require("lspkind") -local cmp = require("cmp") - -local function sorting() - local comparators = { - cmp.config.compare.sort_text, - -- Below is the default comparitor list and order for nvim-cmp - cmp.config.compare.offset, - -- cmp.config.compare.scopes, --this is commented in nvim-cmp too - cmp.config.compare.exact, - cmp.config.compare.score, - cmp.config.compare.recently_used, - cmp.config.compare.locality, - cmp.config.compare.kind, - cmp.config.compare.length, - cmp.config.compare.order, - } - return { - priority_weight = 2, - comparators = comparators, - } -end - -local menu = { - nvim_lsp = "[LSP]", - luasnip = "[Lsnip]", - path = "[Path]", - copilot = "[Copilot]", - -- buffer = "[Buffer]", -} -local lsp_ui = require("kide.lsp.lsp_ui") -cmp.setup({ - enabled = function() - return vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt" or require("cmp_dap").is_dap_buffer() - end, - window = { - completion = cmp.config.window.bordered({ - border = lsp_ui.hover_actions.border, - winhighlight = lsp_ui.window.winhighlight, - }), - documentation = cmp.config.window.bordered({ - border = lsp_ui.hover_actions.border, - winhighlight = lsp_ui.window.winhighlight, - }), - }, - sorting = sorting(), - -- 指定 snippet 引擎 - snippet = { - expand = function(args) - -- For `vsnip` users. - -- vim.fn["vsnip#anonymous"](args.body) - - -- For `luasnip` users. - require("luasnip").lsp_expand(args.body) - - -- For `ultisnips` users. - -- vim.fn["UltiSnips#Anon"](args.body) - - -- For `snippy` users. - -- require'snippy'.expand_snippet(args.body) - end, - }, - -- 来源 - sources = cmp.config.sources({ - { name = "copilot" }, - { name = "nvim_lsp" }, - -- For vsnip users. - -- { name = 'vsnip' }, - -- For luasnip users. - { name = "luasnip" }, - --For ultisnips users. - -- { name = 'ultisnips' }, - -- -- For snippy users. - -- { name = 'snippy' }, - }, { - { name = "path" }, - { name = "buffer" }, - }), - - -- 快捷键 - mapping = require("kide.core.keybindings").cmp(cmp), - -- 使用lspkind-nvim显示类型图标 - formatting = { - format = lspkind.cmp_format({ - with_text = true, -- do not show text alongside icons - maxwidth = 50, - before = function(entry, vim_item) - -- Source 显示提示来源 - vim_item.menu = lspkind.symbolic(vim_item.menu, {}) - local m = vim_item.menu and vim_item.menu or "" - - local ms - if entry.source.source.client and entry.source.source.client.name == "rime_ls" then - ms = "[rime]" - else - ms = menu[entry.source.name] and menu[entry.source.name] .. m or m - end - vim_item.menu = ms - -- 判断 ms 长度,如果大于40,就截取前40个字符 - if #ms > 40 then - vim_item.menu = string.sub(ms, 1, 40) .. "..." - end - return vim_item - end, - }), - }, -}) - --- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). -cmp.setup.cmdline({ "/" }, { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "nvim_lsp_document_symbol" }, - }, { - { name = "buffer" }, - }), -}) -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" }, - }), -}) - -cmp.setup.filetype({ "dap-repl", "dapui_watches", "dapui_hover" }, { - sources = { - { name = "dap" }, - }, -}) diff --git a/lua/kide/plugins/config/nvim-dap-ui.lua b/lua/kide/plugins/config/nvim-dap-ui.lua deleted file mode 100644 index 99c5b727..00000000 --- a/lua/kide/plugins/config/nvim-dap-ui.lua +++ /dev/null @@ -1,103 +0,0 @@ -local dap = require("dap") --- dap.defaults.fallback.terminal_win_cmd = '50vsplit new' --- dap.defaults.fallback.focus_terminal = true --- dap.defaults.fallback.external_terminal = { --- command = '/opt/homebrew/bin/alacritty'; --- args = { '-e' }; --- } -local dapui = require("dapui") -dapui.setup({ - icons = { expanded = "", collapsed = "", current_frame = "" }, - layouts = { - { - -- You can change the order of elements in the sidebar - elements = { - -- Provide IDs as strings or tables with "id" and "size" keys - { - id = "scopes", - size = 0.25, -- Can be float or integer > 1 - }, - { id = "breakpoints", size = 0.25 }, - { id = "stacks", size = 0.25 }, - { id = "watches", size = 0.25 }, - }, - size = 40, - position = "left", - }, - { - elements = { - { id = "repl", size = 0.3 }, - { id = "console", size = 0.7 }, - }, - size = 0.25, - position = "bottom", - }, - }, -}) -local M = { dapui_active = false } - -local function auto_close(bufnr) - local acid - acid = vim.api.nvim_create_autocmd({ "BufDelete", "BufHidden" }, { - buffer = bufnr, - callback = function() - if M.dapui_active then - require("dapui").close() - M.dapui_active = false - else - dap.repl.close() - end - vim.api.nvim_del_autocmd(acid) - end, - }) -end - --- dap.defaults.fallback.terminal_win_cmd = "belowright 12new | set filetype=dap-terminal" -local dapui_console = dap.defaults.fallback.terminal_win_cmd -dap.defaults.fallback.terminal_win_cmd = function() - if M.dapui_active then - local bufnr = dapui_console() - auto_close(bufnr) - return bufnr - else - local cur_win = vim.api.nvim_get_current_win() - -- open terminal - vim.api.nvim_command("belowright 12new") - local bufnr = vim.api.nvim_get_current_buf() - vim.bo[bufnr].modifiable = false - vim.bo[bufnr].swapfile = false - vim.bo[bufnr].buftype = "nofile" - vim.bo[bufnr].filetype = "dap-terminal" - - local win = vim.api.nvim_get_current_win() - vim.api.nvim_set_current_win(cur_win) - auto_close(bufnr) - return bufnr, win - end -end - -dap.listeners.after.event_initialized["dapui_config"] = function() - -- dapui.open() - if not M.dapui_active then - dap.repl.open() - end -end --- dap.listeners.before.event_terminated["dapui_config"] = function() --- dapui.close() --- end --- dap.listeners.before.event_exited["dapui_config"] = function() --- dapui.close() --- end --- nvim-dap -vim.api.nvim_create_user_command("DapUIOpen", function() - M.dapui_active = true - require("dapui").open() -end, {}) -vim.api.nvim_create_user_command("DapUIClose", function() - M.dapui_active = false - require("dapui").close() -end, {}) -vim.api.nvim_create_user_command("DapUIToggle", function() - M.dapui_active = not M.dapui_active - require("dapui").toggle() -end, {}) diff --git a/lua/kide/plugins/config/nvim-tree.lua b/lua/kide/plugins/config/nvim-tree.lua deleted file mode 100644 index f20414db..00000000 --- a/lua/kide/plugins/config/nvim-tree.lua +++ /dev/null @@ -1,108 +0,0 @@ -local function on_attach(bufnr) - local api = require("nvim-tree.api") - - local function opts(desc) - return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } - end - api.config.mappings.default_on_attach(bufnr) - - local treeutils = require("kide.plugins.config.utils.treeutil") - - vim.keymap.set("n", "ff", treeutils.launch_find_files, opts("Launch Find Files")) - vim.keymap.set("n", "fg", treeutils.launch_live_grep, opts("Launch Live Grep")) -end - -require("nvim-tree").setup({ - on_attach = on_attach, - disable_netrw = true, - hijack_netrw = true, - -- auto_close = true, - auto_reload_on_write = true, - open_on_tab = false, - hijack_cursor = true, - actions = { - use_system_clipboard = true, - change_dir = { - enable = true, - global = false, - }, - open_file = { - quit_on_open = true, - resize_window = true, - window_picker = { - enable = true, - chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", - exclude = { - filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame", "dbui", "dbout" }, - buftype = { "nofile", "terminal", "help" }, - }, - }, - }, - }, - update_focused_file = { - enable = true, - update_cwd = false, - ignore_list = {}, - }, - system_open = { - cmd = "", - args = {}, - }, - filters = { - dotfiles = false, - custom = { "^.git$" }, - }, - git = { - enable = true, - ignore = true, - timeout = 400, - }, - view = { - width = 40, - -- height = 40, - side = "left", - preserve_window_proportions = false, - number = false, - relativenumber = false, - signcolumn = "yes", - }, - renderer = { - root_folder_label = false, - indent_markers = { - enable = false, - icons = { - corner = "└", - edge = "│", - item = "│", - none = " ", - }, - }, - icons = { - glyphs = { - folder = { - arrow_closed = "", - arrow_open = "", - default = "", - open = "", - empty = "", - empty_open = "", - symlink = "", - symlink_open = "", - }, - git = { - unstaged = "󰄱", - staged = "", - unmerged = "", - renamed = "➜", - untracked = "", - deleted = "", - ignored = "◌", - }, - }, - }, - }, - trash = { - cmd = "trash", - require_confirm = true, - }, -}) diff --git a/lua/kide/plugins/config/pandoc.lua b/lua/kide/plugins/config/pandoc.lua deleted file mode 100644 index e22bbfca..00000000 --- a/lua/kide/plugins/config/pandoc.lua +++ /dev/null @@ -1,51 +0,0 @@ -local utils = require("kide.core.utils") -require("pandoc").setup({ - commands = { - enable = false, - }, -}) - -local uv = vim.loop -require("pandoc.process").spawn = function(bin, args, callback) - local stdout = uv.new_pipe(false) - local stderr = uv.new_pipe(false) - - local p = vim.fn.expand("%:p:h") - local spawn_opts = { - args = args, - cwd = p, - stdio = { nil, stdout, stderr }, - } - - local result = {} - - local handle, pid - handle, pid = uv.spawn( - bin, - spawn_opts, - vim.schedule_wrap(function(exit_code, signal) - stdout:read_stop() - stderr:read_stop() - stdout:close() - stderr:close() - handle:close() - callback(result, exit_code, signal) - end) - ) - - if handle == nil then - error(("Failed to spawn process: cmd = %s, error = %s"):format(bin, pid)) - end - - local function on_read(err, data) - if err then - error(err) - end - if data then - table.insert(result, data) - end - end - - stderr:read_start(on_read) - stdout:read_start(on_read) -end diff --git a/lua/kide/plugins/config/symbols-outline.lua b/lua/kide/plugins/config/symbols-outline.lua deleted file mode 100644 index cdcc6af2..00000000 --- a/lua/kide/plugins/config/symbols-outline.lua +++ /dev/null @@ -1,66 +0,0 @@ -local lsp_ui = require("kide.lsp.lsp_ui") -local symbols_map = lsp_ui.symbol_map --- init.lua -require("symbols-outline").setup({ - highlight_hovered_item = false, - show_guides = true, - auto_preview = false, - position = "right", - relative_width = true, - width = 25, - auto_close = false, - show_numbers = false, - show_relative_numbers = false, - show_symbol_details = true, - preview_bg_highlight = "Normal,FloatBorder:Normal,CursorLine:Visual,Search:None", - autofold_depth = nil, - auto_unfold_hover = true, - fold_markers = { "", "" }, - wrap = false, - keymaps = { -- These keymaps can be a string or a table for multiple keys - close = { "", "q" }, - goto_location = "", - focus_location = "o", - hover_symbol = "", - toggle_preview = "K", - rename_symbol = "r", - code_actions = "a", - fold = "h", - unfold = "l", - fold_all = "W", - unfold_all = "E", - fold_reset = "R", - }, - lsp_blacklist = {}, - symbol_blacklist = {}, - symbols = { - File = symbols_map.File, - Module = symbols_map.Module, - Namespace = symbols_map.Namespace, - Package = symbols_map.Package, - Class = symbols_map.Class, - Method = symbols_map.Method, - Property = symbols_map.Property, - Field = symbols_map.Field, - Constructor = symbols_map.Constructor, - Enum = symbols_map.Enum, - Interface = symbols_map.Interface, - Function = symbols_map.Function, - Variable = symbols_map.Variable, - Constant = symbols_map.Constant, - String = symbols_map.String, - Number = symbols_map.Number, - Boolean = symbols_map.Boolean, - Array = symbols_map.Array, - Object = symbols_map.Object, - Key = symbols_map.Key, - Null = symbols_map.Null, - EnumMember = symbols_map.EnumMember, - Struct = symbols_map.Struct, - Event = symbols_map.Event, - Operator = symbols_map.Operator, - TypeParameter = symbols_map.TypeParameter, - Component = symbols_map.Component, - Fragment = symbols_map.Fragment, - }, -}) diff --git a/lua/kide/plugins/config/telescope.lua b/lua/kide/plugins/config/telescope.lua deleted file mode 100644 index 8205e3a6..00000000 --- a/lua/kide/plugins/config/telescope.lua +++ /dev/null @@ -1,151 +0,0 @@ --- local actions = require("telescope.actions") --- local trouble = require("trouble.providers.telescope") -local telescope = require("telescope") - --- 支持预览 jar 包 class -local form_entry = require("telescope.from_entry") -local f_path = form_entry.path -form_entry.path = function(entry, validate, escape) - if entry.filename and vim.startswith(entry.filename, "jdt://") then - return entry.filename - end - return f_path(entry, validate, escape) -end - -local set = require("telescope.actions.set") -set.edit = require("kide.plugins.config.telescope.actions.set").edit - -local previewers = require("telescope.previewers") -previewers.buffer_previewer_maker = require("kide.plugins.config.telescope.buffer_previewer").file_maker - -local conf = require("telescope.config").values -conf["qflist_previewer"] = function(...) - return require("kide.plugins.config.telescope.buffer_previewer").qflist.new(...) -end -telescope.setup({ - defaults = { - vimgrep_arguments = { - "rg", - "-L", - "--color=never", - "--no-heading", - "--with-filename", - "--line-number", - "--column", - "--smart-case", - }, - prompt_prefix = "  ", - selection_caret = " ", - entry_prefix = " ", - initial_mode = "insert", - selection_strategy = "reset", - sorting_strategy = "ascending", - layout_strategy = "horizontal", - layout_config = { - horizontal = { - prompt_position = "top", - preview_width = 0.55, - results_width = 0.8, - }, - vertical = { - mirror = false, - }, - width = 0.87, - height = 0.80, - preview_cutoff = 120, - }, - winblend = 0, - -- border = {}, - borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, - color_devicons = true, - -- use_less = true, - set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, - -- file_sorter = require("telescope.sorters").get_fuzzy_file, - file_ignore_patterns = { "node_modules" }, - -- generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, - path_display = { "truncate" }, - dynamic_preview_title = true, - results_title = false, - -- file_previewer = require("telescope.previewers").vim_buffer_cat.new, - -- grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, - -- qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, - -- Developer configurations: Not meant for general override - -- buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, - - -- Default configuration for telescope goes here: - -- config_key = value, - preview = { - timeout = 1000, - filetype_hook = function(filepath, bufnr, opts) - if vim.startswith(filepath, "jdt://") then - require("kide.lsp.utils.jdtls").open_classfile(filepath, bufnr, opts.preview.timeout) - return false - end - return true - end, - }, - mappings = { - i = { - -- map actions.which_key to (default: ) - -- actions.which_key shows the mappings for your picker, - -- e.g. git_{create, delete, ...}_branch for the git_branches picker - [""] = "which_key", - -- [""] = actions.close, - -- [""] = trouble.open_with_trouble, - }, - n = { - -- [""] = trouble.open_with_trouble, - ["q"] = require("telescope.actions").close, - }, - }, - }, - pickers = { - -- Default configuration for builtin pickers goes here: - -- picker_name = { - -- picker_config_key = value, - -- ... - -- } - -- Now the picker_config_key will be applied every time you call this - -- builtin picker - }, - extensions = { - -- Your extension configuration goes here: - -- extension_name = { - -- extension_config_key = value, - -- } - -- please take a look at the readme of the extension you want to configure - ["ui-select"] = { - require("telescope.themes").get_dropdown({ - -- even more opts - }), - }, - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, -- override the generic sorter - override_file_sorter = true, -- override the file sorter - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - -- the default case_mode is "smart_case" - }, - }, -}) --- telescope.load_extension('fzf') --- telescope.load_extension('gradle') --- telescope.load_extension('maven_search') - --- 解决 telescope 打开的文件不折叠问题 --- https://github.com/nvim-telescope/telescope.nvim/issues/1277 -vim.api.nvim_create_autocmd("BufRead", { - callback = function() - vim.api.nvim_create_autocmd("BufWinEnter", { - once = true, - command = "normal! zx", - }) - end, -}) - -require("telescope").load_extension("project") -require("telescope").load_extension("ui-select") -require("telescope").load_extension("fzf") -require("telescope").load_extension("env") - -require("kide.theme.gruvbox").load_telescope_highlights() diff --git a/lua/kide/plugins/config/telescope/actions/set.lua b/lua/kide/plugins/config/telescope/actions/set.lua deleted file mode 100644 index 8220fb7f..00000000 --- a/lua/kide/plugins/config/telescope/actions/set.lua +++ /dev/null @@ -1,313 +0,0 @@ ----@tag telescope.actions.set ----@config { ["module"] = "telescope.actions.set", ["name"] = "ACTIONS_SET" } - ----@brief [[ ---- Telescope action sets are used to provide an interface for managing ---- actions that all primarily do the same thing, but with slight tweaks. ---- ---- For example, when editing files you may want it in the current split, ---- a vertical split, etc. Instead of making users have to overwrite EACH ---- of those every time they want to change this behavior, they can instead ---- replace the `set` itself and then it will work great and they're done. ----@brief ]] - -local a = vim.api - -local log = require "telescope.log" -local Path = require "plenary.path" -local state = require "telescope.state" -local utils = require "telescope.utils" - -local action_state = require "telescope.actions.state" - -local transform_mod = require("telescope.actions.mt").transform_mod - -local action_set = setmetatable({}, { - __index = function(_, k) - error("'telescope.actions.set' does not have a value: " .. tostring(k)) - end, -}) - ---- Move the current selection of a picker {change} rows. ---- Handles not overflowing / underflowing the list. ----@param prompt_bufnr number: The prompt bufnr ----@param change number: The amount to shift the selection by -action_set.shift_selection = function(prompt_bufnr, change) - local count = vim.v.count - count = count == 0 and 1 or count - count = a.nvim_get_mode().mode == "n" and count or 1 - action_state.get_current_picker(prompt_bufnr):move_selection(change * count) -end - ---- Select the current entry. This is the action set to overwrite common ---- actions by the user. ---- ---- By default maps to editing a file. ----@param prompt_bufnr number: The prompt bufnr ----@param type string: The type of selection to make --- Valid types include: "default", "horizontal", "vertical", "tabedit" -action_set.select = function(prompt_bufnr, type) - return action_set.edit(prompt_bufnr, action_state.select_key_to_edit_key(type)) -end - --- goal: currently we have a workaround in actions/init.lua where we do this for all files --- action_set.select = { --- -- Will not be called if `select_default` is replaced rather than `action_set.select` because we never get here --- pre = function(prompt_bufnr) --- action_state.get_current_history():append( --- action_state.get_current_line(), --- action_state.get_current_picker(prompt_bufnr) --- ) --- end, --- action = function(prompt_bufnr, type) --- return action_set.edit(prompt_bufnr, action_state.select_key_to_edit_key(type)) --- end --- } - -local edit_buffer -do - local map = { - drop = "drop", - ["tab drop"] = "tab drop", - edit = "buffer", - new = "sbuffer", - vnew = "vert sbuffer", - ["leftabove new"] = "leftabove sbuffer", - ["leftabove vnew"] = "leftabove vert sbuffer", - ["rightbelow new"] = "rightbelow sbuffer", - ["rightbelow vnew"] = "rightbelow vert sbuffer", - ["topleft new"] = "topleft sbuffer", - ["topleft vnew"] = "topleft vert sbuffer", - ["botright new"] = "botright sbuffer", - ["botright vnew"] = "botright vert sbuffer", - tabedit = "tab sb", - } - - edit_buffer = function(command, bufnr) - local buf_command = map[command] - if buf_command == nil then - local valid_commands = vim.tbl_map(function(cmd) - return string.format("%q", cmd) - end, vim.tbl_keys(map)) - table.sort(valid_commands) - error( - string.format( - "There was no associated buffer command for %q.\nValid commands are: %s.", - command, - table.concat(valid_commands, ", ") - ) - ) - end - if buf_command ~= "drop" and buf_command ~= "tab drop" then - vim.cmd(string.format("%s %d", buf_command, bufnr)) - else - vim.cmd(string.format("%s %s", buf_command, vim.fn.fnameescape(vim.api.nvim_buf_get_name(bufnr)))) - end - end -end - ---- Edit a file based on the current selection. ----@param prompt_bufnr number: The prompt bufnr ----@param command string: The command to use to open the file. --- Valid commands are: --- - "edit" --- - "new" --- - "vedit" --- - "tabedit" --- - "drop" --- - "tab drop" --- - "leftabove new" --- - "leftabove vnew" --- - "rightbelow new" --- - "rightbelow vnew" --- - "topleft new" --- - "topleft vnew" --- - "botright new" --- - "botright vnew" -action_set.edit = function(prompt_bufnr, command) - local entry = action_state.get_selected_entry() - - if not entry then - utils.notify("actions.set.edit", { - msg = "Nothing currently selected", - level = "WARN", - }) - return - end - - local filename, row, col - - if entry.path or entry.filename then - filename = entry.path or entry.filename - - -- TODO: Check for off-by-one - row = entry.row or entry.lnum - col = entry.col - elseif not entry.bufnr then - -- TODO: Might want to remove this and force people - -- to put stuff into `filename` - local value = entry.value - if not value then - utils.notify("actions.set.edit", { - msg = "Could not do anything with blank line...", - level = "WARN", - }) - return - end - - if type(value) == "table" then - value = entry.display - end - - local sections = vim.split(value, ":") - - filename = sections[1] - row = tonumber(sections[2]) - col = tonumber(sections[3]) - end - - local entry_bufnr = entry.bufnr - - local picker = action_state.get_current_picker(prompt_bufnr) - require("telescope.pickers").on_close_prompt(prompt_bufnr) - pcall(vim.api.nvim_set_current_win, picker.original_win_id) - local win_id = picker.get_selection_window(picker, entry) - - if picker.push_cursor_on_edit then - vim.cmd "normal! m'" - end - - if picker.push_tagstack_on_edit then - local from = { vim.fn.bufnr "%", vim.fn.line ".", vim.fn.col ".", 0 } - local items = { { tagname = vim.fn.expand "", from = from } } - vim.fn.settagstack(vim.fn.win_getid(), { items = items }, "t") - end - - if win_id ~= 0 and a.nvim_get_current_win() ~= win_id then - vim.api.nvim_set_current_win(win_id) - end - - if entry_bufnr then - if not vim.api.nvim_buf_get_option(entry_bufnr, "buflisted") then - vim.api.nvim_buf_set_option(entry_bufnr, "buflisted", true) - end - edit_buffer(command, entry_bufnr) - else - -- check if we didn't pick a different buffer - -- prevents restarting lsp server - if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then - if vim.startswith(filename, "jdt://") then - local bufnr = vim.uri_to_bufnr(filename) - vim.bo[bufnr].buflisted = true - vim.api.nvim_win_set_buf(win_id, bufnr) - else - filename = Path:new(filename):normalize(vim.loop.cwd()) - pcall(vim.cmd, string.format("%s %s", command, vim.fn.fnameescape(filename))) - end - end - end - - local pos = vim.api.nvim_win_get_cursor(0) - if col == nil then - if row == pos[1] then - col = pos[2] + 1 - elseif row == nil then - row, col = pos[1], pos[2] + 1 - else - col = 1 - end - end - - if row and col then - local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, { row, col }) - if not ok then - log.debug("Failed to move to cursor:", err_msg, row, col) - end - end -end - ---- Scrolls the previewer up or down. ---- Defaults to a half page scroll, but can be overridden using the `scroll_speed` ---- option in `layout_config`. See |telescope.layout| for more details. ----@param prompt_bufnr number: The prompt bufnr ----@param direction number: The direction of the scrolling --- Valid directions include: "1", "-1" -action_set.scroll_previewer = function(prompt_bufnr, direction) - local previewer = action_state.get_current_picker(prompt_bufnr).previewer - local status = state.get_status(prompt_bufnr) - - -- Check if we actually have a previewer and a preview window - if type(previewer) ~= "table" or previewer.scroll_fn == nil or status.preview_win == nil then - return - end - - local default_speed = vim.api.nvim_win_get_height(status.preview_win) / 2 - local speed = status.picker.layout_config.scroll_speed or default_speed - - previewer:scroll_fn(math.floor(speed * direction)) -end - ---- Scrolls the previewer to the left or right. ---- Defaults to a half page scroll, but can be overridden using the `scroll_speed` ---- option in `layout_config`. See |telescope.layout| for more details. ----@param prompt_bufnr number: The prompt bufnr ----@param direction number: The direction of the scrolling --- Valid directions include: "1", "-1" -action_set.scroll_horizontal_previewer = function(prompt_bufnr, direction) - local previewer = action_state.get_current_picker(prompt_bufnr).previewer - local status = state.get_status(prompt_bufnr) - - -- Check if we actually have a previewer and a preview window - if type(previewer) ~= "table" or previewer.scroll_horizontal_fn == nil or status.preview_win == nil then - return - end - - local default_speed = vim.api.nvim_win_get_height(status.preview_win) / 2 - local speed = status.picker.layout_config.scroll_speed or default_speed - - previewer:scroll_horizontal_fn(math.floor(speed * direction)) -end - ---- Scrolls the results up or down. ---- Defaults to a half page scroll, but can be overridden using the `scroll_speed` ---- option in `layout_config`. See |telescope.layout| for more details. ----@param prompt_bufnr number: The prompt bufnr ----@param direction number: The direction of the scrolling --- Valid directions include: "1", "-1" -action_set.scroll_results = function(prompt_bufnr, direction) - local status = state.get_status(prompt_bufnr) - local default_speed = vim.api.nvim_win_get_height(status.results_win) / 2 - local speed = status.picker.layout_config.scroll_speed or default_speed - - local input = direction > 0 and [[]] or [[]] - - vim.api.nvim_win_call(status.results_win, function() - vim.cmd([[normal! ]] .. math.floor(speed) .. input) - end) - - action_set.shift_selection(prompt_bufnr, math.floor(speed) * direction) -end - ---- Scrolls the results to the left or right. ---- Defaults to a half page scroll, but can be overridden using the `scroll_speed` ---- option in `layout_config`. See |telescope.layout| for more details. ----@param prompt_bufnr number: The prompt bufnr ----@param direction number: The direction of the scrolling --- Valid directions include: "1", "-1" -action_set.scroll_horizontal_results = function(prompt_bufnr, direction) - local status = state.get_status(prompt_bufnr) - local default_speed = vim.api.nvim_win_get_height(status.results_win) / 2 - local speed = status.picker.layout_config.scroll_speed or default_speed - - local input = direction > 0 and [[zl]] or [[zh]] - - vim.api.nvim_win_call(status.results_win, function() - vim.cmd([[normal! ]] .. math.floor(speed) .. input) - end) -end - --- ================================================== --- Transforms modules and sets the corect metatables. --- ================================================== -action_set = transform_mod(action_set) -return action_set diff --git a/lua/kide/plugins/config/telescope/buffer_previewer.lua b/lua/kide/plugins/config/telescope/buffer_previewer.lua deleted file mode 100644 index e21e1314..00000000 --- a/lua/kide/plugins/config/telescope/buffer_previewer.lua +++ /dev/null @@ -1,1209 +0,0 @@ -local from_entry = require "telescope.from_entry" -local Path = require "plenary.path" -local utils = require "telescope.utils" -local putils = require "telescope.previewers.utils" -local Previewer = require "telescope.previewers.previewer" -local conf = require("telescope.config").values - -local pscan = require "plenary.scandir" - -local buf_delete = utils.buf_delete - -local previewers = {} - -local ns_previewer = vim.api.nvim_create_namespace "telescope.previewers" - -local has_file = 1 == vim.fn.executable "file" - --- TODO(fdschmidt93) switch to Job once file_maker callbacks get cleaned up with plenary async --- avoids SIGABRT from utils.get_os_command_output due to vim.time in fs_stat cb -local function capture(cmd, raw) - local f = assert(io.popen(cmd, "r")) - local s = assert(f:read "*a") - f:close() - if raw then - return s - end - s = string.gsub(s, "^%s+", "") - s = string.gsub(s, "%s+$", "") - s = string.gsub(s, "[\n\r]+", " ") - return s -end - -local function defaulter(f, default_opts) - default_opts = default_opts or {} - return { - new = function(opts) - if conf.preview == false and not opts.preview then - return false - end - opts.preview = type(opts.preview) ~= "table" and {} or opts.preview - if type(conf.preview) == "table" then - for k, v in pairs(conf.preview) do - opts.preview[k] = vim.F.if_nil(opts.preview[k], v) - end - end - return f(opts) - end, - __call = function() - local ok, err = pcall(f(default_opts)) - if not ok then - error(debug.traceback(err)) - end - end, - } -end - --- modified vim.split to incorporate a timer -local function split(s, sep, plain, opts) - opts = opts or {} - local t = {} - for c in vim.gsplit(s, sep, plain) do - local line = opts.file_encoding and vim.iconv(c, opts.file_encoding, "utf8") or c - table.insert(t, line) - if opts.preview.timeout then - local diff_time = (vim.loop.hrtime() - opts.start_time) / 1e6 - if diff_time > opts.preview.timeout then - return - end - end - end - return t -end -local bytes_to_megabytes = math.pow(1024, 2) - -local color_hash = { - ["p"] = "TelescopePreviewPipe", - ["c"] = "TelescopePreviewCharDev", - ["d"] = "TelescopePreviewDirectory", - ["b"] = "TelescopePreviewBlock", - ["l"] = "TelescopePreviewLink", - ["s"] = "TelescopePreviewSocket", - ["."] = "TelescopePreviewNormal", - ["r"] = "TelescopePreviewRead", - ["w"] = "TelescopePreviewWrite", - ["x"] = "TelescopePreviewExecute", - ["-"] = "TelescopePreviewHyphen", - ["T"] = "TelescopePreviewSticky", - ["S"] = "TelescopePreviewSticky", - [2] = "TelescopePreviewSize", - [3] = "TelescopePreviewUser", - [4] = "TelescopePreviewGroup", - [5] = "TelescopePreviewDate", -} -color_hash[6] = function(line) - return color_hash[line:sub(1, 1)] -end - -local colorize_ls_long = function(bufnr, data, sections) - local windows_add = Path.path.sep == "\\" and 2 or 0 - for lnum, line in ipairs(data) do - local section = sections[lnum] - for i = 1, section[1].end_index - 1 do -- Highlight permissions - local c = line:sub(i, i) - vim.api.nvim_buf_add_highlight(bufnr, ns_previewer, color_hash[c], lnum - 1, i - 1, i) - end - for i = 2, #section do -- highlights size, (user, group), date and name - local hl_group = color_hash[i + (i ~= 2 and windows_add or 0)] - vim.api.nvim_buf_add_highlight( - bufnr, - ns_previewer, - type(hl_group) == "function" and hl_group(line) or hl_group, - lnum - 1, - section[i].start_index - 1, - section[i].end_index - 1 - ) - end - end -end - -local handle_directory_preview = function(filepath, bufnr, opts) - opts.preview.ls_short = vim.F.if_nil(opts.preview.ls_short, false) - - local set_colorize_lines - if opts.preview.ls_short then - set_colorize_lines = function(data, sections) - local PATH_SECTION = Path.path.sep == "\\" and 4 or 6 - local paths = {} - for i, line in ipairs(data) do - local section = sections[i][PATH_SECTION] - local path = line:sub(section.start_index, section.end_index) - table.insert(paths, path) - end - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, paths) - for i, path in ipairs(paths) do - local hl = color_hash[6](data[i]) - vim.api.nvim_buf_add_highlight(bufnr, ns_previewer, hl, i - 1, 0, #path) - end - end - else - set_colorize_lines = function(data, sections) - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, data) - colorize_ls_long(bufnr, data, sections) - end - end - - pscan.ls_async(filepath, { - hidden = true, - group_directories_first = true, - on_exit = vim.schedule_wrap(function(data, sections) - set_colorize_lines(data, sections) - if opts.callback then - opts.callback(bufnr) - end - end), - }) -end - -local handle_file_preview = function(filepath, bufnr, stat, opts) - vim.schedule(function() - opts.ft = opts.use_ft_detect and putils.filetype_detect(filepath) - local possible_binary = false - if type(opts.preview.filetype_hook) == "function" and opts.ft ~= nil and opts.ft ~= "" then - if not opts.preview.filetype_hook(filepath, bufnr, opts) then - return - end - end - if opts.preview.check_mime_type == true and has_file and (opts.ft == nil or opts.ft == "") then - -- avoid SIGABRT in buffer previewer happening with utils.get_os_command_output - local output = capture(string.format([[file --mime-type -b "%s"]], filepath)) - local mime_type = vim.split(output, "/") - if mime_type[1] ~= "text" and mime_type[1] ~= "inode" and mime_type[2] ~= "json" then - if type(opts.preview.mime_hook) == "function" then - opts.preview.mime_hook(filepath, bufnr, opts) - return - else - possible_binary = true - end - end - if mime_type[2] == "json" then - opts.ft = "json" - end - end - - if opts.preview.filesize_limit then - local mb_filesize = math.floor(stat.size / bytes_to_megabytes) - if mb_filesize > opts.preview.filesize_limit then - if type(opts.preview.filesize_hook) == "function" then - opts.preview.filesize_hook(filepath, bufnr, opts) - else - putils.set_preview_message(bufnr, opts.winid, "File exceeds preview size limit", opts.preview.msg_bg_fillchar) - end - return - end - end - - opts.start_time = vim.loop.hrtime() - Path:new(filepath):_read_async(vim.schedule_wrap(function(data) - if not vim.api.nvim_buf_is_valid(bufnr) then - return - end - local processed_data = split(data, "[\r]?\n", nil, opts) - - if processed_data then - local ok = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, processed_data) - if not ok then - return - end - -- last resort, if ft is still empty at this point in time, - -- we need to determine the filetype using the buffer contents - if opts.ft == nil or opts.ft == "" then - opts.ft = vim.filetype.match { filename = filepath, buf = bufnr } - end - -- we need to attempt to call filetype hook at this point "again" - -- previously only if we had a valid filetype, now every time - -- also if there will never be a filetype - if type(opts.preview.filetype_hook) == "function" then - if not opts.preview.filetype_hook(filepath, bufnr, opts) then - return - end - end - -- if we still dont have a ft we need to display the binary message - if (opts.ft == nil or opts.ft == "") and possible_binary then - putils.set_preview_message(bufnr, opts.winid, "Binary cannot be previewed", opts.preview.msg_bg_fillchar) - return - end - - if opts.callback then - opts.callback(bufnr) - end - putils.highlighter(bufnr, opts.ft, opts) - else - if type(opts.preview.timeout_hook) == "function" then - opts.preview.timeout_hook(filepath, bufnr, opts) - else - putils.set_preview_message(bufnr, opts.winid, "Previewer timed out", opts.preview.msg_bg_fillchar) - end - return - end - end)) - end) -end - -local PREVIEW_TIMEOUT_MS = 250 -local PREVIEW_FILESIZE_MB = 25 - -previewers.file_maker = function(filepath, bufnr, opts) - opts = vim.F.if_nil(opts, {}) - opts.preview = vim.F.if_nil(opts.preview, {}) - opts.preview.timeout = vim.F.if_nil(opts.preview.timeout, PREVIEW_TIMEOUT_MS) - opts.preview.filesize_limit = vim.F.if_nil(opts.preview.filesize_limit, PREVIEW_FILESIZE_MB) - opts.preview.msg_bg_fillchar = vim.F.if_nil(opts.preview.msg_bg_fillchar, "╱") - opts.preview.treesitter = vim.F.if_nil(opts.preview.treesitter, true) - if opts.use_ft_detect == nil then - opts.use_ft_detect = true - end - if opts.bufname ~= filepath then - if not vim.in_fast_event() then - local fp = vim.fn.expand(filepath) - -- windows jdt:// 路径解析为空 - if fp ~= nil and fp ~= "" then - filepath = fp - end - end - -- jdt:// path is a special case, we need to call the filetype hook - if vim.startswith(filepath, "jdt://") and type(opts.preview.filetype_hook) == "function" then - if not opts.preview.filetype_hook(filepath, bufnr, opts) then - return - end - end - - vim.loop.fs_stat(filepath, function(_, stat) - if not stat then - return - end - if stat.type == "directory" then - handle_directory_preview(filepath, bufnr, opts) - else - handle_file_preview(filepath, bufnr, stat, opts) - end - end) - else - if opts.callback then - if vim.in_fast_event() then - vim.schedule(function() - opts.callback(bufnr) - end) - else - opts.callback(bufnr) - end - end - end -end - -local search_cb_jump = function(self, bufnr, query) - if not query then - return - end - vim.api.nvim_buf_call(bufnr, function() - pcall(vim.fn.matchdelete, self.state.hl_id, self.state.winid) - vim.cmd "norm! gg" - vim.fn.search(query, "W") - vim.cmd "norm! zz" - - self.state.hl_id = vim.fn.matchadd("TelescopePreviewMatch", query) - end) -end - -local search_teardown = function(self) - if self.state and self.state.hl_id then - pcall(vim.fn.matchdelete, self.state.hl_id, self.state.hl_win) - self.state.hl_id = nil - end -end - -local scroll_fn = function(self, direction) - if not self.state then - return - end - - local input = direction > 0 and [[]] or [[]] - local count = math.abs(direction) - - vim.api.nvim_win_call(self.state.winid, function() - vim.cmd([[normal! ]] .. count .. input) - end) -end - -local scroll_horizontal_fn = function(self, direction) - if not self.state then - return - end - - local input = direction > 0 and [[zl]] or [[zh]] - local count = math.abs(direction) - - vim.api.nvim_win_call(self.state.winid, function() - vim.cmd([[normal! ]] .. count .. input) - end) -end - -previewers.new_buffer_previewer = function(opts) - opts = opts or {} - - assert(opts.define_preview, "define_preview is a required function") - assert(not opts.preview_fn, "preview_fn not allowed") - - local opt_setup = opts.setup - local opt_teardown = opts.teardown - - local old_bufs = {} - local bufname_table = {} - - local global_state = require "telescope.state" - local preview_window_id - - local function get_bufnr(self) - if not self.state then - return nil - end - return self.state.bufnr - end - - local function set_bufnr(self, value) - if self.state then - self.state.bufnr = value - table.insert(old_bufs, value) - end - end - - local function get_bufnr_by_bufname(self, value) - if not self.state then - return nil - end - return bufname_table[value] - end - - local function set_bufname(self, value) - if self.state then - self.state.bufname = value - if value then - bufname_table[value] = get_bufnr(self) - end - end - end - - function opts.setup(self) - local state = {} - if opt_setup then - vim.tbl_deep_extend("force", state, opt_setup(self)) - end - return state - end - - function opts.teardown(self) - if opt_teardown then - opt_teardown(self) - end - - local last_nr - if opts.keep_last_buf then - last_nr = global_state.get_global_key "last_preview_bufnr" - -- Push in another buffer so the last one will not be cleaned up - if preview_window_id then - local bufnr = vim.api.nvim_create_buf(false, true) - utils.win_set_buf_noautocmd(preview_window_id, bufnr) - end - end - - set_bufnr(self, nil) - set_bufname(self, nil) - - for _, bufnr in ipairs(old_bufs) do - if bufnr ~= last_nr then - buf_delete(bufnr) - end - end - -- enable resuming picker with existing previewer to avoid lookup of deleted bufs - bufname_table = {} - end - - function opts.preview_fn(self, entry, status) - if get_bufnr(self) == nil then - set_bufnr(self, vim.api.nvim_win_get_buf(status.preview_win)) - preview_window_id = status.preview_win - end - - if opts.get_buffer_by_name and get_bufnr_by_bufname(self, opts.get_buffer_by_name(self, entry)) then - self.state.bufname = opts.get_buffer_by_name(self, entry) - self.state.bufnr = get_bufnr_by_bufname(self, self.state.bufname) - utils.win_set_buf_noautocmd(status.preview_win, self.state.bufnr) - else - local bufnr = vim.api.nvim_create_buf(false, true) - set_bufnr(self, bufnr) - - vim.schedule(function() - if vim.api.nvim_buf_is_valid(bufnr) then - utils.win_set_buf_noautocmd(status.preview_win, bufnr) - end - end) - - vim.api.nvim_win_set_option(status.preview_win, "winhl", "Normal:TelescopePreviewNormal") - vim.api.nvim_win_set_option(status.preview_win, "signcolumn", "no") - vim.api.nvim_win_set_option(status.preview_win, "foldlevel", 100) - vim.api.nvim_win_set_option(status.preview_win, "wrap", false) - vim.api.nvim_win_set_option(status.preview_win, "scrollbind", false) - - self.state.winid = status.preview_win - self.state.bufname = nil - end - - if opts.keep_last_buf then - global_state.set_global_key("last_preview_bufnr", self.state.bufnr) - end - - opts.define_preview(self, entry, status) - - vim.schedule(function() - if not self or not self.state or not self.state.bufnr then - return - end - - if vim.api.nvim_buf_is_valid(self.state.bufnr) then - vim.api.nvim_buf_call(self.state.bufnr, function() - vim.api.nvim_exec_autocmds("User", { - pattern = "TelescopePreviewerLoaded", - data = { - title = entry.preview_title, - bufname = self.state.bufname, - filetype = putils.filetype_detect(self.state.bufname or ""), - }, - }) - end) - end - end) - - if opts.get_buffer_by_name then - set_bufname(self, opts.get_buffer_by_name(self, entry)) - end - end - - if not opts.scroll_fn then - opts.scroll_fn = scroll_fn - end - - if not opts.scroll_horizontal_fn then - opts.scroll_horizontal_fn = scroll_horizontal_fn - end - - return Previewer:new(opts) -end - -previewers.cat = defaulter(function(opts) - opts = opts or {} - local cwd = opts.cwd or vim.loop.cwd() - return previewers.new_buffer_previewer { - title = "File Preview", - dyn_title = function(_, entry) - return Path:new(from_entry.path(entry, false, false)):normalize(cwd) - end, - - get_buffer_by_name = function(_, entry) - return from_entry.path(entry, false) - end, - - define_preview = function(self, entry) - local p = from_entry.path(entry, true) - if p == nil or p == "" then - return - end - conf.buffer_previewer_maker(p, self.state.bufnr, { - bufname = self.state.bufname, - winid = self.state.winid, - preview = opts.preview, - file_encoding = opts.file_encoding, - }) - end, - } -end, {}) - -previewers.vimgrep = defaulter(function(opts) - opts = opts or {} - local cwd = opts.cwd or vim.loop.cwd() - - local jump_to_line = function(self, bufnr, lnum) - pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns_previewer, 0, -1) - if lnum and lnum > 0 then - pcall(vim.api.nvim_buf_add_highlight, bufnr, ns_previewer, "TelescopePreviewLine", lnum - 1, 0, -1) - pcall(vim.api.nvim_win_set_cursor, self.state.winid, { lnum, 0 }) - vim.api.nvim_buf_call(bufnr, function() - vim.cmd "norm! zz" - end) - end - end - - return previewers.new_buffer_previewer { - title = "Grep Preview", - dyn_title = function(_, entry) - local fp = from_entry.path(entry, false, false) - if vim.startswith(fp, 'jdt://') then - local url = require('kide.core.utils.url') - -- fp = url.unescape(fp) - fp = string.gsub(fp, '%%5C', '') - local u = url.parse(fp) - return u.path - end - return Path:new(fp):normalize(cwd) - end, - - get_buffer_by_name = function(_, entry) - return from_entry.path(entry, false) - end, - - define_preview = function(self, entry) - -- builtin.buffers: bypass path validation for terminal buffers that don't have appropriate path - local has_buftype = entry.bufnr and vim.api.nvim_buf_get_option(entry.bufnr, "buftype") ~= "" or false - local p - if not has_buftype then - p = from_entry.path(entry, true) - if p == nil or p == "" then - return - end - end - - -- Workaround for unnamed buffer when using builtin.buffer - if entry.bufnr and (p == "[No Name]" or has_buftype) then - local lines = vim.api.nvim_buf_get_lines(entry.bufnr, 0, -1, false) - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) - jump_to_line(self, self.state.bufnr, entry.lnum) - else - conf.buffer_previewer_maker(p, self.state.bufnr, { - bufname = self.state.bufname, - winid = self.state.winid, - preview = opts.preview, - callback = function(bufnr) - jump_to_line(self, bufnr, entry.lnum) - end, - file_encoding = opts.file_encoding, - }) - end - end, - } -end, {}) - -previewers.qflist = previewers.vimgrep - -previewers.ctags = defaulter(function(_) - local determine_jump = function(entry) - if entry.scode then - return function(self) - -- un-escape / then escape required - -- special chars for vim.fn.search() - -- ] ~ * - local scode = entry.scode:gsub([[\/]], "/"):gsub("[%]~*]", function(x) - return "\\" .. x - end) - - pcall(vim.fn.matchdelete, self.state.hl_id, self.state.winid) - vim.cmd "norm! gg" - vim.fn.search(scode, "W") - vim.cmd "norm! zz" - - self.state.hl_id = vim.fn.matchadd("TelescopePreviewMatch", scode) - end - else - return function(self, bufnr) - if self.state.last_set_bufnr then - pcall(vim.api.nvim_buf_clear_namespace, self.state.last_set_bufnr, ns_previewer, 0, -1) - end - pcall(vim.api.nvim_buf_add_highlight, bufnr, ns_previewer, "TelescopePreviewMatch", entry.lnum - 1, 0, -1) - pcall(vim.api.nvim_win_set_cursor, self.state.winid, { entry.lnum, 0 }) - self.state.last_set_bufnr = bufnr - end - end - end - - return previewers.new_buffer_previewer { - title = "Tags Preview", - teardown = function(self) - if self.state and self.state.hl_id then - pcall(vim.fn.matchdelete, self.state.hl_id, self.state.hl_win) - self.state.hl_id = nil - elseif self.state and self.state.last_set_bufnr and vim.api.nvim_buf_is_valid(self.state.last_set_bufnr) then - vim.api.nvim_buf_clear_namespace(self.state.last_set_bufnr, ns_previewer, 0, -1) - end - end, - - get_buffer_by_name = function(_, entry) - return entry.filename - end, - - define_preview = function(self, entry) - conf.buffer_previewer_maker(entry.filename, self.state.bufnr, { - bufname = self.state.bufname, - winid = self.state.winid, - callback = function(bufnr) - pcall(vim.api.nvim_buf_call, bufnr, function() - determine_jump(entry)(self, bufnr) - end) - end, - }) - end, - } -end, {}) - -previewers.builtin = defaulter(function(_) - return previewers.new_buffer_previewer { - title = "Grep Preview", - teardown = search_teardown, - - get_buffer_by_name = function(_, entry) - return entry.filename - end, - - define_preview = function(self, entry) - local module_name = vim.fn.fnamemodify(vim.fn.fnamemodify(entry.filename, ":h"), ":t") - local text - if entry.text:sub(1, #module_name) ~= module_name then - text = module_name .. "." .. entry.text - else - text = entry.text:gsub("_", ".", 1) - end - - conf.buffer_previewer_maker(entry.filename, self.state.bufnr, { - bufname = self.state.bufname, - winid = self.state.winid, - callback = function(bufnr) - search_cb_jump(self, bufnr, text) - end, - }) - end, - } -end, {}) - -previewers.help = defaulter(function(_) - return previewers.new_buffer_previewer { - title = "Help Preview", - teardown = search_teardown, - - get_buffer_by_name = function(_, entry) - return entry.filename - end, - - define_preview = function(self, entry) - local query = entry.cmd - query = query:sub(2) - query = [[\V]] .. query - - conf.buffer_previewer_maker(entry.filename, self.state.bufnr, { - bufname = self.state.bufname, - winid = self.state.winid, - callback = function(bufnr) - putils.regex_highlighter(bufnr, "help") - search_cb_jump(self, bufnr, query) - end, - }) - end, - } -end, {}) - -previewers.man = defaulter(function(opts) - local pager = utils.get_lazy_default(opts.PAGER, function() - return vim.fn.executable "col" == 1 and { "col", "-bx" } or { "cat" } - end) - return previewers.new_buffer_previewer { - title = "Man Preview", - get_buffer_by_name = function(_, entry) - return entry.value .. "/" .. entry.section - end, - - define_preview = function(self, entry) - local win_width = vim.api.nvim_win_get_width(self.state.winid) - putils.job_maker(vim.deepcopy(pager), self.state.bufnr, { - writer = { "man", entry.section, entry.value }, - env = { ["MANWIDTH"] = win_width, PATH = vim.env.PATH, MANPATH = vim.env.MANPATH }, - value = entry.value .. "/" .. entry.section, - bufname = self.state.bufname, - }) - putils.regex_highlighter(self.state.bufnr, "man") - end, - } -end) - -previewers.git_branch_log = defaulter(function(opts) - local highlight_buffer = function(bufnr, content) - for i = 1, #content do - local line = content[i] - local _, hstart = line:find "[%*%s|]*" - if hstart then - local hend = hstart + 7 - if hend < #line then - pcall( - vim.api.nvim_buf_add_highlight, - bufnr, - ns_previewer, - "TelescopeResultsIdentifier", - i - 1, - hstart - 1, - hend - ) - end - end - local _, cstart = line:find "- %(" - if cstart then - local cend = string.find(line, "%) ") - if cend then - pcall( - vim.api.nvim_buf_add_highlight, - bufnr, - ns_previewer, - "TelescopeResultsConstant", - i - 1, - cstart - 1, - cend - ) - end - end - local dstart, _ = line:find " %(%d" - if dstart then - pcall( - vim.api.nvim_buf_add_highlight, - bufnr, - ns_previewer, - "TelescopeResultsSpecialComment", - i - 1, - dstart, - #line - ) - end - end - end - - return previewers.new_buffer_previewer { - title = "Git Branch Preview", - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry) - local cmd = { - "git", - "--no-pager", - "log", - "--graph", - "--pretty=format:%h -%d %s (%cr)", - "--abbrev-commit", - "--date=relative", - entry.value, - } - - putils.job_maker(cmd, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - cwd = opts.cwd, - callback = function(bufnr, content) - if not content then - return - end - highlight_buffer(bufnr, content) - end, - }) - end, - } -end, {}) - -previewers.git_stash_diff = defaulter(function(opts) - return previewers.new_buffer_previewer { - title = "Git Stash Preview", - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry, _) - putils.job_maker({ "git", "--no-pager", "stash", "show", "-p", entry.value }, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - cwd = opts.cwd, - callback = function(bufnr) - if vim.api.nvim_buf_is_valid(bufnr) then - putils.regex_highlighter(bufnr, "diff") - end - end, - }) - end, - } -end, {}) - -previewers.git_commit_diff_to_parent = defaulter(function(opts) - return previewers.new_buffer_previewer { - title = "Git Diff to Parent Preview", - teardown = search_teardown, - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry) - local cmd = { "git", "--no-pager", "diff", entry.value .. "^!" } - if opts.current_file then - table.insert(cmd, "--") - table.insert(cmd, opts.current_file) - end - - putils.job_maker(cmd, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - cwd = opts.cwd, - callback = function(bufnr) - if vim.api.nvim_buf_is_valid(bufnr) then - search_cb_jump(self, bufnr, opts.current_line) - putils.regex_highlighter(bufnr, "diff") - end - end, - }) - end, - } -end, {}) - -previewers.git_commit_diff_to_head = defaulter(function(opts) - return previewers.new_buffer_previewer { - title = "Git Diff to Head Preview", - teardown = search_teardown, - - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry) - local cmd = { "git", "--no-pager", "diff", "--cached", entry.value } - if opts.current_file then - table.insert(cmd, "--") - table.insert(cmd, opts.current_file) - end - - putils.job_maker(cmd, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - cwd = opts.cwd, - callback = function(bufnr) - if vim.api.nvim_buf_is_valid(bufnr) then - search_cb_jump(self, bufnr, opts.current_line) - putils.regex_highlighter(bufnr, "diff") - end - end, - }) - end, - } -end, {}) - -previewers.git_commit_diff_as_was = defaulter(function(opts) - return previewers.new_buffer_previewer { - title = "Git Show Preview", - teardown = search_teardown, - - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry) - local cmd = { "git", "--no-pager", "show" } - local cf = opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) - local value = cf and (entry.value .. ":" .. cf) or entry.value - local ft = cf and putils.filetype_detect(value) or "diff" - table.insert(cmd, value) - - putils.job_maker(cmd, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - cwd = opts.cwd, - callback = function(bufnr) - if vim.api.nvim_buf_is_valid(bufnr) then - search_cb_jump(self, bufnr, opts.current_line) - putils.regex_highlighter(bufnr, ft) - end - end, - }) - end, - } -end, {}) - -previewers.git_commit_message = defaulter(function(opts) - local hl_map = { - "TelescopeResultsIdentifier", - "TelescopePreviewUser", - "TelescopePreviewDate", - } - return previewers.new_buffer_previewer { - title = "Git Message", - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry) - local cmd = { "git", "--no-pager", "log", "-n 1", entry.value } - - putils.job_maker(cmd, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - cwd = opts.cwd, - callback = function(bufnr, content) - if not content then - return - end - for k, v in ipairs(hl_map) do - local _, s = content[k]:find "%s" - if s then - vim.api.nvim_buf_add_highlight(bufnr, ns_previewer, v, k - 1, s, #content[k]) - end - end - end, - }) - end, - } -end, {}) - -previewers.git_file_diff = defaulter(function(opts) - return previewers.new_buffer_previewer { - title = "Git File Diff Preview", - get_buffer_by_name = function(_, entry) - return entry.value - end, - - define_preview = function(self, entry) - if entry.status and (entry.status == "??" or entry.status == "A ") then - local p = from_entry.path(entry, true) - if p == nil or p == "" then - return - end - conf.buffer_previewer_maker(p, self.state.bufnr, { - bufname = self.state.bufname, - winid = self.state.winid, - }) - else - putils.job_maker({ "git", "--no-pager", "diff", "HEAD", "--", entry.value }, self.state.bufnr, { - value = entry.value, - bufname = self.state.bufname, - cwd = opts.cwd, - callback = function(bufnr) - if vim.api.nvim_buf_is_valid(bufnr) then - putils.regex_highlighter(bufnr, "diff") - end - end, - }) - end - end, - } -end, {}) - -previewers.autocommands = defaulter(function(_) - return previewers.new_buffer_previewer { - title = "Autocommands Preview", - teardown = function(self) - if self.state and self.state.last_set_bufnr and vim.api.nvim_buf_is_valid(self.state.last_set_bufnr) then - pcall(vim.api.nvim_buf_clear_namespace, self.state.last_set_bufnr, ns_previewer, 0, -1) - end - end, - - get_buffer_by_name = function(_, entry) - return entry.value.group_name - end, - - define_preview = function(self, entry, status) - local results = vim.tbl_filter(function(x) - return x.value.group_name == entry.value.group_name - end, status.picker.finder.results) - - if self.state.last_set_bufnr then - pcall(vim.api.nvim_buf_clear_namespace, self.state.last_set_bufnr, ns_previewer, 0, -1) - end - - local selected_row = 0 - if self.state.bufname ~= entry.value.group_name then - local display = {} - table.insert(display, string.format(" augroup: %s - [ %d entries ]", entry.value.group_name, #results)) - -- TODO: calculate banner width/string in setup() - -- TODO: get column characters to be the same HL group as border - table.insert(display, string.rep("─", vim.fn.getwininfo(status.preview_win)[1].width)) - - for idx, item in ipairs(results) do - if item == entry then - selected_row = idx - end - table.insert( - display, - string.format(" %-14s▏%-08s %s", item.value.event, item.value.pattern, item.value.command) - ) - end - - vim.api.nvim_buf_set_option(self.state.bufnr, "filetype", "vim") - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, display) - vim.api.nvim_buf_add_highlight(self.state.bufnr, 0, "TelescopeBorder", 1, 0, -1) - else - for idx, item in ipairs(results) do - if item == entry then - selected_row = idx - break - end - end - end - - vim.api.nvim_buf_add_highlight(self.state.bufnr, ns_previewer, "TelescopePreviewLine", selected_row + 1, 0, -1) - -- set the cursor position after self.state.bufnr is connected to the - -- preview window (which is scheduled in new_buffer_previewer) - vim.schedule(function() - pcall(vim.api.nvim_win_set_cursor, status.preview_win, { selected_row, 0 }) - end) - - self.state.last_set_bufnr = self.state.bufnr - end, - } -end, {}) - -previewers.highlights = defaulter(function(_) - return previewers.new_buffer_previewer { - title = "Highlights Preview", - teardown = function(self) - if self.state and self.state.last_set_bufnr and vim.api.nvim_buf_is_valid(self.state.last_set_bufnr) then - vim.api.nvim_buf_clear_namespace(self.state.last_set_bufnr, ns_previewer, 0, -1) - end - end, - - get_buffer_by_name = function() - return "highlights" - end, - - define_preview = function(self, entry) - if not self.state.bufname then - local output = vim.split(vim.fn.execute "highlight", "\n") - local hl_groups = {} - for _, v in ipairs(output) do - if v ~= "" then - if v:sub(1, 1) == " " then - local part_of_old = v:match "%s+(.*)" - hl_groups[#hl_groups] = hl_groups[#hl_groups] .. part_of_old - else - table.insert(hl_groups, v) - end - end - end - - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, hl_groups) - for k, v in ipairs(hl_groups) do - local startPos = string.find(v, "xxx", 1, true) - 1 - local endPos = startPos + 3 - local hlgroup = string.match(v, "([^ ]*)%s+.*") - pcall(vim.api.nvim_buf_add_highlight, self.state.bufnr, 0, hlgroup, k - 1, startPos, endPos) - end - end - - vim.schedule(function() - vim.api.nvim_buf_call(self.state.bufnr, function() - vim.cmd "norm! gg" - vim.fn.search(entry.value .. " ") - local lnum = vim.api.nvim_win_get_cursor(self.state.winid)[1] - -- That one is actually a match but its better to use it like that then matchadd - pcall(vim.api.nvim_buf_clear_namespace, self.state.bufnr, ns_previewer, 0, -1) - vim.api.nvim_buf_add_highlight( - self.state.bufnr, - ns_previewer, - "TelescopePreviewMatch", - lnum - 1, - 0, - #entry.value - ) - -- we need to zz after the highlighting otherwise highlighting doesnt work - vim.cmd "norm! zz" - end) - end) - end, - } -end, {}) - -previewers.pickers = defaulter(function(_) - local ns_telescope_multiselection = vim.api.nvim_create_namespace "telescope_mulitselection" - local get_row = function(picker, preview_height, index) - if picker.sorting_strategy == "ascending" then - return index - 1 - else - return preview_height - index - end - end - return previewers.new_buffer_previewer { - - dyn_title = function(_, entry) - if entry.value.default_text and entry.value.default_text ~= "" then - return string.format("%s ─ %s", entry.value.prompt_title, entry.value.default_text) - end - return entry.value.prompt_title - end, - - get_buffer_by_name = function(_, entry) - return tostring(entry.value.prompt_bufnr) - end, - - teardown = function(self) - if self.state and self.state.last_set_bufnr and vim.api.nvim_buf_is_valid(self.state.last_set_bufnr) then - vim.api.nvim_buf_clear_namespace(self.state.last_set_bufnr, ns_telescope_multiselection, 0, -1) - end - end, - - define_preview = function(self, entry) - vim.api.nvim_buf_call(self.state.bufnr, function() - local ns_telescope_entry = vim.api.nvim_create_namespace "telescope_entry" - local preview_height = vim.api.nvim_win_get_height(self.state.winid) - - if self.state.bufname then - return - end - - local picker = entry.value - -- prefill buffer to be able to set lines individually - local placeholder = utils.repeated_table(preview_height, "") - vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, placeholder) - - for index = 1, math.min(preview_height, picker.manager:num_results()) do - local row = get_row(picker, preview_height, index) - local e = picker.manager:get_entry(index) - - local display, display_highlight - -- if-clause as otherwise function return values improperly unpacked - if type(e.display) == "function" then - display, display_highlight = e:display() - else - display = e.display - end - - vim.api.nvim_buf_set_lines(self.state.bufnr, row, row + 1, false, { display }) - - if display_highlight ~= nil then - for _, hl_block in ipairs(display_highlight) do - vim.api.nvim_buf_add_highlight( - self.state.bufnr, - ns_telescope_entry, - hl_block[2], - row, - hl_block[1][1], - hl_block[1][2] - ) - end - end - if picker._multi:is_selected(e) then - vim.api.nvim_buf_add_highlight( - self.state.bufnr, - ns_telescope_multiselection, - "TelescopeMultiSelection", - row, - 0, - -1 - ) - end - end - end) - end, - } -end, {}) - -previewers.display_content = defaulter(function(_) - return previewers.new_buffer_previewer { - define_preview = function(self, entry) - assert( - type(entry.preview_command) == "function", - "entry must provide a preview_command function which will put the content into the buffer" - ) - vim.api.nvim_buf_call(self.state.bufnr, function() - entry.preview_command(entry, self.state.bufnr) - end) - end, - } -end, {}) - -return previewers diff --git a/lua/kide/plugins/config/utils/treeutil.lua b/lua/kide/plugins/config/utils/treeutil.lua deleted file mode 100644 index ee57ba4e..00000000 --- a/lua/kide/plugins/config/utils/treeutil.lua +++ /dev/null @@ -1,46 +0,0 @@ -local api = require("nvim-tree.api") -local openfile = require("nvim-tree.actions.node.open-file") -local actions = require("telescope.actions") -local action_state = require("telescope.actions.state") -local M = {} - -local view_selection = function(prompt_bufnr, map) - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - local filename = selection.filename - if filename == nil then - filename = selection[1] - end - openfile.fn("preview", filename) - end) - return true -end - -function M.launch_live_grep(opts) - return M.launch_telescope("live_grep", opts) -end - -function M.launch_find_files(opts) - return M.launch_telescope("find_files", opts) -end - -function M.launch_telescope(func_name, opts) - local telescope_status_ok, _ = pcall(require, "telescope") - if not telescope_status_ok then - return - end - local node = api.tree.get_node_under_cursor() - local is_folder = node.fs_stat and node.fs_stat.type == "directory" or false - local basedir = is_folder and node.absolute_path or vim.fn.fnamemodify(node.absolute_path, ":h") - if node.name == ".." and TreeExplorer ~= nil then - basedir = TreeExplorer.cwd - end - opts = opts or {} - opts.cwd = basedir - opts.search_dirs = { basedir } - opts.attach_mappings = view_selection - return require("telescope.builtin")[func_name](opts) -end - -return M diff --git a/lua/kide/plugins/config/vim-illuminate.lua b/lua/kide/plugins/config/vim-illuminate.lua deleted file mode 100644 index ca2b3b93..00000000 --- a/lua/kide/plugins/config/vim-illuminate.lua +++ /dev/null @@ -1,54 +0,0 @@ --- https://github.com/RRethy/vim-illuminate - --- default configuration -require("illuminate").configure({ - -- providers: provider used to get references in the buffer, ordered by priority - providers = { - "treesitter", - "regex", - }, - -- delay: delay in milliseconds - delay = 100, - -- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist - filetypes_denylist = { - "dirvish", - "fugitive", - "vista_kind", - "help", - "terminal", - "term://*", - "packer", - "markdown", - "git", - "text", - "txt", - "NvimTree", - "dashboard", - "alpha", - "Outline", - "NeogitStatus", - "NeogitPopup", - "DiffviewFiles", - "TelescopePrompt", - "TelescopeResults", - }, - -- filetypes_allowlist: filetypes to illuminate, this is overriden by filetypes_denylist - filetypes_allowlist = {}, - -- modes_denylist: modes to not illuminate, this overrides modes_allowlist - modes_denylist = {}, - -- modes_allowlist: modes to illuminate, this is overriden by modes_denylist - modes_allowlist = {}, - -- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist - -- Only applies to the 'regex' provider - -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') - providers_regex_syntax_denylist = {}, - -- providers_regex_syntax_allowlist: syntax to illuminate, this is overriden by providers_regex_syntax_denylist - -- Only applies to the 'regex' provider - -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') - providers_regex_syntax_allowlist = {}, - -- under_cursor: whether or not to illuminate under the cursor - under_cursor = true, -}) - -vim.keymap.set("n", "]r", require("illuminate").goto_next_reference, { desc = "Move to next reference" }) -vim.keymap.set("n", "[r", require("illuminate").goto_prev_reference, { desc = "Move to previous reference" }) diff --git a/lua/kide/plugins/config/which-key.lua b/lua/kide/plugins/config/which-key.lua deleted file mode 100644 index 990049e5..00000000 --- a/lua/kide/plugins/config/which-key.lua +++ /dev/null @@ -1,10 +0,0 @@ -local which_key = require("which-key") -which_key.setup({ - icons = { - breadcrumb = "»", -- symbol used in the command line area that shows your active key combo - separator = "", -- symbol used between a key and it's label - group = "+", -- symbol prepended to a group - }, -}) - -require("kide.theme.gruvbox").load_which_key_highlights() diff --git a/lua/kide/plugins/config/zk-nvim.lua b/lua/kide/plugins/config/zk-nvim.lua deleted file mode 100644 index 593ebc1f..00000000 --- a/lua/kide/plugins/config/zk-nvim.lua +++ /dev/null @@ -1,21 +0,0 @@ -require("zk").setup({ - -- can be "telescope", "fzf" or "select" (`vim.ui.select`) - -- it's recommended to use "telescope" or "fzf" - picker = "telescope", - - lsp = { - -- `config` is passed to `vim.lsp.start_client(config)` - config = { - cmd = { "zk", "lsp" }, - name = "zk", - -- on_attach = ... - -- etc, see `:h vim.lsp.start_client()` - }, - - -- automatically attach buffers in a zk notebook that match the given filetypes - auto_attach = { - enabled = true, - filetypes = { "markdown" }, - }, - }, -}) diff --git a/lua/kide/plugins/init.lua b/lua/kide/plugins/init.lua deleted file mode 100644 index e84335cb..00000000 --- a/lua/kide/plugins/init.lua +++ /dev/null @@ -1,5 +0,0 @@ -require("lazy_bootstrap") -require("kide.plugins.lazy-nvim") -vim.schedule(function() - require("kide.core.keybindings").setup() -end) diff --git a/lua/kide/plugins/lazy-nvim.lua b/lua/kide/plugins/lazy-nvim.lua deleted file mode 100644 index 862e5083..00000000 --- a/lua/kide/plugins/lazy-nvim.lua +++ /dev/null @@ -1,1599 +0,0 @@ -local config = require("kide.config") - -require("lazy").setup({ - - { - "nvim-lua/plenary.nvim", - lazy = true, - }, - - { - "nvim-tree/nvim-web-devicons", - lazy = true, - }, - { - "williamboman/mason.nvim", - lazy = true, - event = { "VeryLazy" }, - config = function() - require("mason").setup() - end, - }, - { - "williamboman/mason-lspconfig.nvim", - lazy = true, - }, - { - "neovim/nvim-lspconfig", - event = { "VeryLazy", "BufNewFile", "BufReadPost" }, - config = function() - require("kide.lsp") - end, - }, - - -- 代码片段 - { - "rafamadriz/friendly-snippets", - lazy = true, - }, - -- LuaSnip - { - "L3MON4D3/LuaSnip", - lazy = true, - dependencies = { "rafamadriz/friendly-snippets" }, - build = "make install_jsregexp", - config = function() - local ls = require("luasnip") - - local s = ls.snippet - local t = ls.text_node - local types = require("luasnip.util.types") - - -- Every unspecified option will be set to the default. - ls.config.set_config({ - history = true, - -- Update more often, :h events for more info. - updateevents = "TextChanged,TextChangedI", - delete_check_events = "TextChanged", - ext_opts = { - [types.choiceNode] = { - active = { - virt_text = { { "●", "GruvboxOrange" } }, - }, - }, - [types.insertNode] = { - active = { - virt_text = { { "●", "GruvboxBlue" } }, - }, - }, - }, - - -- treesitter-hl has 100, use something higher (default is 200). - ext_base_prio = 300, - -- minimal increase in priority. - ext_prio_increase = 1, - enable_autosnippets = true, - -- mapping for cutting selected text so it's usable as SELECT_DEDENT, - -- SELECT_RAW or TM_SELECTED_TEXT (mapped via xmap). - store_selection_keys = "", - -- luasnip uses this function to get the currently active filetype. This - -- is the (rather uninteresting) default, but it's possible to use - -- eg. treesitter for getting the current filetype by setting ft_func to - -- require("luasnip.extras.filetype_functions").from_cursor (requires - -- `nvim-treesitter/nvim-treesitter`). This allows correctly resolving - -- the current filetype in eg. a markdown-code block or `vim.cmd()`. - ft_func = function() - return vim.split(vim.bo.filetype, ".", { plain = true }) - end, - }) - - -- autotriggered snippets have to be defined in a separate table, luasnip.autosnippets. - ls.autosnippets = { - all = { - s("autotrigger", { - t("autosnippet"), - }), - }, - } - - -- in a lua file: search lua-, then c-, then all-snippets. - ls.filetype_extend("lua", { "c" }) - -- in a cpp file: search c-snippets, then all-snippets only (no cpp-snippets!!). - ls.filetype_set("cpp", { "c" }) - - -- require("luasnip.loaders.from_vscode").lazy_load() - - require("kide.snippets").setup() - end, - }, - { - "saadparwaiz1/cmp_luasnip", - dependencies = { "L3MON4D3/LuaSnip" }, - lazy = true, - }, - -- lspkind - { - "onsails/lspkind-nvim", - lazy = true, - event = { "VeryLazy" }, - config = function() - require("lspkind").init({ - -- preset = "codicons", - symbol_map = { - Copilot = "", - }, - }) - vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" }) - end, - }, - -- nvim-cmp - { - "hrsh7th/nvim-cmp", - event = { "InsertEnter", "VeryLazy" }, - keys = { ":", "/", "?" }, - dependencies = { - "hrsh7th/cmp-path", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-cmdline", - "saadparwaiz1/cmp_luasnip", - "onsails/lspkind-nvim", - "rcarriga/cmp-dap", - "hrsh7th/cmp-nvim-lsp-document-symbol", - }, - lazy = true, - config = function() - require("kide.plugins.config.nvim-cmp") - end, - }, - { - "hrsh7th/cmp-nvim-lsp", - lazy = true, - }, - { - "hrsh7th/cmp-cmdline", - lazy = true, - }, - { - "hrsh7th/cmp-buffer", - lazy = true, - }, - { - "hrsh7th/cmp-path", - lazy = true, - }, - { - "rcarriga/cmp-dap", - lazy = true, - }, - { - "hrsh7th/cmp-nvim-lsp-document-symbol", - lazy = true, - }, - { - "nvimtools/none-ls.nvim", - lazy = true, - event = { "VeryLazy", "BufNewFile", "BufReadPost" }, - dependencies = { - "gbprod/none-ls-shellcheck.nvim", - }, - config = function() - require("kide.plugins.config.null-ls") - end, - }, - - -- 主题 - -- use 'morhetz/gruvbox' - { - "ellisonleao/gruvbox.nvim", - enabled = false, - lazy = false, - priority = 1000, - config = function() - require("gruvbox").setup({ - transparent_mode = vim.g.transparent_mode, - }) - vim.opt.background = "dark" - vim.cmd([[colorscheme gruvbox]]) - end, - }, - { - "sainnhe/gruvbox-material", - enabled = true, - lazy = false, - priority = 1000, - config = function() - vim.opt.background = "dark" - vim.g.gruvbox_material_background = "medium" - vim.g.gruvbox_material_foreground = "medium" - vim.g.gruvbox_material_disable_italic_comment = 0 - vim.g.gruvbox_material_better_performance = 1 - vim.g.gruvbox_material_enable_bold = 1 - vim.g.gruvbox_material_enable_italic = 1 - vim.g.gruvbox_material_cursor = "auto" - if vim.g.transparent_mode then - vim.g.gruvbox_material_transparent_background = 2 - end - vim.g.gruvbox_material_dim_inactive_windows = 0 - vim.g.gruvbox_material_visual = "grey background" -- reverse - vim.g.gruvbox_material_menu_selection_background = "grey" - vim.g.gruvbox_material_sign_column_background = "none" - vim.g.gruvbox_material_spell_foreground = "none" - vim.g.gruvbox_material_ui_contrast = "low" - vim.g.gruvbox_material_show_eob = 1 - vim.g.gruvbox_material_float_style = "bright" - vim.g.gruvbox_material_diagnostic_text_highlight = 0 - vim.g.gruvbox_material_diagnostic_line_highlight = 1 - vim.g.gruvbox_material_diagnostic_virtual_text = "colored" - vim.g.gruvbox_material_current_word = "grey background" - vim.g.gruvbox_material_disable_terminal_colors = 1 - vim.g.gruvbox_material_statusline_style = "original" - vim.g.gruvbox_material_lightline_disable_bold = 0 - -- gruvbox_material_colors_override - vim.cmd([[colorscheme gruvbox-material]]) - - vim.api.nvim_set_hl(0, "CursorLineNr", { fg = "Orange" }) - -- #fe8019, #fabd2f - vim.api.nvim_set_hl(0, "CurrentWord", { fg = "#fe8019", ctermbg = 237, bg = nil, bold = true }) - end, - }, - - -- 文件管理 - { - "kyazdani42/nvim-tree.lua", - lazy = true, - cmd = "NvimTreeToggle", - version = "*", - config = function() - require("kide.plugins.config.nvim-tree") - end, - }, - - -- using packer.nvim - { - "akinsho/bufferline.nvim", - event = { "UIEnter" }, - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - require("kide.plugins.config.bufferline") - end, - }, - { - "famiu/bufdelete.nvim", - cmd = { "Bdelete" }, - }, - - -- treesitter (新增) - { - "nvim-treesitter/nvim-treesitter", - event = { "VeryLazy", "BufNewFile", "BufReadPost" }, - build = ":TSUpdate", - config = function() - require("nvim-treesitter.configs").setup({ - ensure_installed = { - "markdown", - }, - modules = {}, - auto_install = true, - sync_install = false, - ignore_install = {}, - - highlight = { - enable = true, - disable = {}, - additional_vim_regex_highlighting = false, - }, - indent = { - enable = true, - }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "gnn", - node_incremental = "grn", - scope_incremental = "grc", - node_decremental = "grm", - }, - }, - textobjects = { - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - ["]m"] = "@function.outer", - ["]]"] = { query = "@class.outer", desc = "Next class start" }, - ["]o"] = "@loop.*", - ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" }, - ["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" }, - }, - goto_next_end = { - ["]M"] = "@function.outer", - ["]["] = "@class.outer", - }, - goto_previous_start = { - ["[m"] = "@function.outer", - ["[["] = "@class.outer", - ["[o"] = "@loop.*", - ["[s"] = { query = "@scope", query_group = "locals", desc = "Next scope" }, - ["[z"] = { query = "@fold", query_group = "folds", desc = "Next fold" }, - }, - goto_previous_end = { - ["[M"] = "@function.outer", - ["[]"] = "@class.outer", - }, - goto_next = { - ["]d"] = "@conditional.outer", - }, - goto_previous = { - ["[d"] = "@conditional.outer", - }, - }, - select = { - enable = true, - lookahead = true, - keymaps = { - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, - ["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" }, - }, - selection_modes = { - ["@parameter.outer"] = "v", -- charwise - ["@function.outer"] = "V", -- linewise - ["@class.outer"] = "", -- blockwise - }, - include_surrounding_whitespace = false, - }, - swap = { - enable = true, - swap_next = { - ["a"] = "@parameter.inner", - }, - swap_previous = { - ["A"] = "@parameter.inner", - }, - }, - }, - }) - -- 开启 Folding see nvim-ufo - -- vim.wo.foldmethod = "expr" - -- vim.wo.foldexpr = "nvim_treesitter#foldexpr()" - end, - }, - { - "nvim-treesitter/nvim-treesitter-textobjects", - dependencies = { "nvim-treesitter/nvim-treesitter" }, - event = { "VeryLazy", "BufNewFile", "BufReadPost" }, - }, - - -- java - { - "mfussenegger/nvim-jdtls", - lazy = true, - ft = "java", - }, - -- rust - { - "JavaHello/spring-boot.nvim", - lazy = true, - ft = "java", - dependencies = { - "mfussenegger/nvim-jdtls", - "ibhagwan/fzf-lua", - }, - }, - - { - "JavaHello/java-deps.nvim", - lazy = true, - ft = "java", - dependencies = "mfussenegger/nvim-jdtls", - config = function() - require("java-deps").setup({}) - end, - }, - { - "scalameta/nvim-metals", - lazy = true, - ft = "scala", - dependencies = { "nvim-lua/plenary.nvim" }, - }, - -- debug - { - "mfussenegger/nvim-dap", - lazy = true, - event = { "VeryLazy" }, - config = function() - require("kide.dap") - -- require("telescope").load_extension("dap") - end, - }, - { - "rcarriga/nvim-dap-ui", - lazy = true, - dependencies = { "mfussenegger/nvim-dap" }, - event = { "VeryLazy" }, - config = function() - require("kide.plugins.config.nvim-dap-ui") - end, - }, - { - "theHamsta/nvim-dap-virtual-text", - lazy = true, - event = { "VeryLazy" }, - dependencies = { "mfussenegger/nvim-dap" }, - config = function() - require("nvim-dap-virtual-text").setup({}) - end, - }, - - { - "mfussenegger/nvim-dap-python", - lazy = true, - ft = "java", - dependencies = { "mfussenegger/nvim-dap" }, - config = function() - require("dap-python").setup(config.env.py_bin) - end, - }, - { - "sakhnik/nvim-gdb", - lazy = true, - cmd = { - "GdbStart", - "GdbStartLLDB", - "GdbStartPDB", - "GdbStartBashDB", - "GdbStartRR", - }, - init = function() - vim.g.nvimgdb_disable_start_keymaps = 1 - vim.g.nvimgdb_use_find_executables = 0 - vim.g.nvimgdb_use_cmake_to_find_executables = 0 - end, - config = function() end, - build = ":!./install.sh", - }, - - { - "klen/nvim-test", - lazy = true, - ft = { - "go", - "javascript", - "typescript", - "lua", - "python", - "rust", - }, - config = function() - require("nvim-test").setup({ - term = "toggleterm", - }) - end, - }, - - -- 搜索插件 - { - "nvim-telescope/telescope.nvim", - lazy = true, - event = { "VeryLazy" }, - cmd = { "Telescope" }, - config = function() - require("kide.plugins.config.telescope") - end, - }, - { - "nvim-telescope/telescope-ui-select.nvim", - lazy = true, - }, - { - "nvim-telescope/telescope-fzf-native.nvim", - build = "make", - lazy = true, - }, - { - "nvim-telescope/telescope-dap.nvim", - dependencies = { "mfussenegger/nvim-dap" }, - lazy = true, - }, - - { - "LinArcX/telescope-env.nvim", - lazy = true, - }, - -- 项目管理 - { - "nvim-telescope/telescope-project.nvim", - lazy = true, - }, - - -- git - { - "tpope/vim-fugitive", - lazy = true, - cmd = { "Git" }, - }, - { - "sindrets/diffview.nvim", - layz = true, - cmd = { - "DiffviewClose", - "DiffviewFileHistory", - "DiffviewFocusFiles", - "DiffviewLog", - "DiffviewOpen", - "DiffviewRefresh", - "DiffviewToggleFiles", - }, - config = function() - require("diffview").setup({}) - end, - }, - - -- git edit 状态显示插件 - { - "lewis6991/gitsigns.nvim", - lazy = true, - event = { "VeryLazy", "BufReadPost" }, - config = function() - require("kide.plugins.config.gitsigns-nvim") - end, - }, - { - "SuperBo/fugit2.nvim", - opts = {}, - enabled = false, - dependencies = { - "MunifTanjim/nui.nvim", - "nvim-tree/nvim-web-devicons", - "nvim-lua/plenary.nvim", - { - "chrisgrieser/nvim-tinygit", -- optional: for Github PR view - dependencies = { "stevearc/dressing.nvim" }, - }, - }, - cmd = { "Fugit2", "Fugit2Graph" }, - keys = { - { "F", mode = "n", "Fugit2" }, - }, - }, - - -- 浮动窗口插件 - { - "akinsho/toggleterm.nvim", - lazy = true, - version = "*", - cmd = { "ToggleTerm" }, - config = function() - require("toggleterm").setup({ - shade_terminals = true, - direction = "horizontal", - close_on_exit = true, - float_opts = { - border = "single", - }, - }) - end, - }, - - -- 异步任务执行插件 - { - "jedrzejboczar/toggletasks.nvim", - lazy = true, - dependencies = { "akinsho/toggleterm.nvim" }, - config = function() - require("toggletasks").setup({ - search_paths = { - ".tasks", - ".toggletasks", - ".nvim/toggletasks", - ".nvim/tasks", - }, - toggleterm = { - close_on_exit = true, - }, - }) - - require("telescope").load_extension("toggletasks") - end, - }, - - -- 多光标插件 - { - "mg979/vim-visual-multi", - lazy = true, - keys = { - { "", mode = { "n", "x" }, desc = "visual multi" }, - }, - }, - -- 状态栏插件 - { - "nvim-lualine/lualine.nvim", - lazy = true, - event = { "UIEnter" }, - config = function() - require("kide.plugins.config.lualine") - end, - }, - - -- blankline - { - "lukas-reineke/indent-blankline.nvim", - enabled = true, - main = "ibl", - event = { "UIEnter" }, - config = function() - require("kide.plugins.config.indent-blankline") - end, - }, - - -- 大纲插件 - { - "simrat39/symbols-outline.nvim", - lazy = true, - cmd = { - "SymbolsOutline", - "SymbolsOutlineOpen", - "SymbolsOutlineClose", - }, - config = function() - require("kide.plugins.config.symbols-outline") - end, - }, - - -- 消息通知 - { - "rcarriga/nvim-notify", - config = function() - local notify = require("notify") - notify.setup({ - stages = "fade_in_slide_out", - on_open = nil, - on_close = nil, - render = "default", - timeout = 3000, - minimum_width = 50, - background_colour = "#000000", - icons = { - ERROR = "", - WARN = "", - INFO = "", - DEBUG = "", - TRACE = "✎", - }, - }) - - vim.notify = notify - end, - }, - { - "j-hui/fidget.nvim", - event = "LspAttach", - opts = { - -- options - }, - }, - { - "folke/noice.nvim", - enabled = false, - event = "VeryLazy", - dependencies = { - "MunifTanjim/nui.nvim", - "rcarriga/nvim-notify", - }, - config = function() - require("noice").setup({ - messages = { - enabled = true, -- enables the Noice messages UI - view = "notify", -- default view for messages - view_error = "notify", -- view for errors - view_warn = "notify", -- view for warnings - view_history = "messages", -- view for :messages - view_search = "virtualtext", -- view for search count messages. Set to `false` to disable - }, - lsp = { - override = { - ["vim.lsp.util.convert_input_to_markdown_lines"] = false, - ["vim.lsp.util.stylize_markdown"] = false, - ["cmp.entry.get_documentation"] = false, - }, - hover = { - enabled = false, - }, - signature = { - enabled = false, - }, - }, - }) - require("kide.theme.gruvbox").load_noice_highlights() - require("telescope").load_extension("noice") - end, - }, - - -- 颜色显示 - { - "NvChad/nvim-colorizer.lua", - event = { "BufReadPost", "InsertEnter", "VeryLazy" }, - config = function() - require("colorizer").setup({ - filetypes = { "*" }, - user_default_options = { - RGB = true, -- #RGB hex codes - RRGGBB = true, -- #RRGGBB hex codes - names = false, -- "Name" codes like Blue or blue - RRGGBBAA = false, -- #RRGGBBAA hex codes - AARRGGBB = false, -- 0xAARRGGBB hex codes - rgb_fn = false, -- CSS rgb() and rgba() functions - hsl_fn = false, -- CSS hsl() and hsla() functions - css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB - css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn - -- Available modes for `mode`: foreground, background, virtualtext - mode = "background", -- Set the display mode. - -- Available methods are false / true / "normal" / "lsp" / "both" - -- True is same as normal - tailwind = false, -- Enable tailwind colors - -- parsers can contain values used in |user_default_options| - sass = { enable = false, parsers = { "css" } }, -- Enable sass colors - virtualtext = "■", - -- update color values even if buffer is not focused - -- example use: cmp_menu, cmp_docs - always_update = false, - }, - -- all the sub-options of filetypes apply to buftypes - buftypes = {}, - }) - end, - }, - - { - "numToStr/Comment.nvim", - keys = { - { "gcc", mode = { "n" }, desc = "Comment" }, - { "gc", mode = { "x" }, desc = "Comment" }, - }, - config = function() - require("Comment").setup() - end, - }, - { - "danymat/neogen", - lazy = true, - event = { "VeryLazy" }, - config = function() - require("neogen").setup({ - snippet_engine = "luasnip", - enabled = true, - input_after_comment = true, - }) - end, - }, - - -- mackdown 预览插件 - { - "iamcco/markdown-preview.nvim", - lazy = true, - ft = "markdown", - build = "cd app && yarn install", - config = function() - vim.g.mkdp_page_title = "${name}" - end, - }, - -- mackdown cli 预览插件 - { - "ellisonleao/glow.nvim", - lazy = true, - ft = "markdown", - config = function() - require("glow").setup({ - style = "dark", - width = 120, - }) - end, - }, - -- pandoc 命令插件(用于md转pdf) - { - "aspeddro/pandoc.nvim", - lazy = true, - ft = "markdown", - config = function() - require("kide.plugins.config.pandoc") - end, - }, - - -- 快捷键查看 - { - "folke/which-key.nvim", - lazy = true, - event = { "VeryLazy" }, - config = function() - require("kide.plugins.config.which-key") - end, - }, - - -- 仪表盘 - { - "goolord/alpha-nvim", - config = function() - local alpha = require("alpha") - local dashboard = require("alpha.themes.dashboard") - dashboard.section.header.val = { - " ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗", - " ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║", - " ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║", - " ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║", - " ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║", - " ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝", - } - local opt = { noremap = true, silent = true } - dashboard.section.buttons.val = { - dashboard.button(" ff", "󰈞 Find File", ":Telescope find_files", opt), - dashboard.button(" fg", "󰈭 Find Word ", ":Telescope live_grep", opt), - dashboard.button( - " fp", - " Recent Projects", - ":lua require'telescope'.extensions.project.project{ display_type = 'full' }", - opt - ), - dashboard.button(" fo", " Recent File", ":Telescope oldfiles", opt), - dashboard.button(" ns", " Settings", ":e $MYVIMRC | :cd %:p:h ", opt), - dashboard.button(" q ", "󰅙 Quit NVIM", ":qa", opt), - } - alpha.setup(dashboard.opts) - end, - }, - - -- 翻译插件 - { - "uga-rosa/translate.nvim", - lazy = true, - cmd = "Translate", - config = function() - require("translate").setup({ - default = { - command = "translate_shell", - }, - preset = { - output = { - split = { - append = true, - }, - }, - }, - }) - end, - }, - -- StartupTime - { - "dstein64/vim-startuptime", - cmd = "StartupTime", - }, - -- 自动对齐插件 - { - "junegunn/vim-easy-align", - lazy = true, - cmd = "EasyAlign", - }, - - -- 表格模式插件 - { - "dhruvasagar/vim-table-mode", - lazy = true, - cmd = { "TableModeEnable" }, - }, - - -- () 自动补全 - { - "windwp/nvim-autopairs", - event = { "InsertEnter", "VeryLazy" }, - config = function() - local autopairs = require("nvim-autopairs") - local cmp_autopairs = require("nvim-autopairs.completion.cmp") - autopairs.setup({}) - local cmp = require("cmp") - cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) - end, - }, - - -- 任务插件 - { - "itchyny/calendar.vim", - lazy = true, - cmd = { - "Calendar", - }, - }, - - -- rust - { - "simrat39/rust-tools.nvim", - lazy = true, - }, - { - "vhyrro/luarocks.nvim", - priority = 1000, - opt = { - rocks = { "md5" }, - }, - config = true, - }, - { - "rest-nvim/rest.nvim", - dependencies = { "luarocks.nvim" }, - lazy = true, - ft = "http", - config = function() - require("rest-nvim").setup({}) - end, - }, - - -- 选中高亮插件 - { - "RRethy/vim-illuminate", - lazy = true, - event = { "BufReadPost" }, - config = function() - require("kide.plugins.config.vim-illuminate") - end, - }, - - -- 快速跳转 - { - "folke/flash.nvim", - event = "VeryLazy", - opts = { - modes = { - search = { - enabled = false, - }, - char = { - enabled = false, - }, - }, - }, - -- stylua: ignore - keys = { - { - "s", - mode = { "n", "x", "o" }, - function() - require("flash").jump() - end, - desc = "Flash", - }, - { - "S", - mode = { "n", "o", "x" }, - function() - require("flash").treesitter() - end, - desc = "Flash Treesitter", - }, - { - "r", - mode = "o", - function() - require("flash").remote() - end, - desc = "Remote Flash", - }, - { - "R", - mode = { "o", "x" }, - function() - require("flash").treesitter_search() - end, - desc = "Treesitter Search", - }, - { - "", - mode = { "c" }, - function() - require("flash").toggle() - end, - desc = "Toggle Flash Search", - }, - }, - }, - - -- 查找替换 - { - "windwp/nvim-spectre", - lazy = true, - config = function() - require("spectre").setup() - end, - }, - - -- ASCII 图 - { - "jbyuki/venn.nvim", - lazy = true, - cmd = { "VBox" }, - }, - - { - "tversteeg/registers.nvim", - lazy = true, - cmd = { "Registers" }, - keys = '"', - config = function() - require("registers").setup() - end, - }, - - -- databases - { - "tpope/vim-dadbod", - lazy = true, - }, - { - "kristijanhusak/vim-dadbod-ui", - lazy = true, - dependencies = { "tpope/vim-dadbod" }, - cmd = { - "DBUI", - "DBUIToggle", - }, - init = function() - vim.g.db_ui_use_nerd_fonts = 1 - end, - }, - { - "kristijanhusak/vim-dadbod-completion", - lazy = true, - dependencies = { "tpope/vim-dadbod" }, - ft = { "sql", "mysql", "plsql" }, - init = function() - vim.api.nvim_create_autocmd("FileType", { - group = vim.api.nvim_create_augroup("kide_vim_dadbod_completion", { clear = true }), - pattern = { "sql", "mysql", "plsql" }, - callback = function(_) - require("cmp").setup.buffer({ sources = { { name = "vim-dadbod-completion" } } }) - end, - }) - end, - config = function() end, - }, - - { - "aklt/plantuml-syntax", - lazy = true, - ft = "plantuml", - }, - - -- 浏览器搜索 - { - "lalitmee/browse.nvim", - lazy = true, - cmd = { - "Browse", - }, - config = function() - require("kide.plugins.config.browse-nvim") - end, - }, - - -- 环绕输入 - { - "kylechui/nvim-surround", - lazy = true, - version = "*", - event = { "VeryLazy" }, - config = function() - require("nvim-surround").setup({}) - end, - }, - - -- Create custom submodes and menus - { - "anuvyklack/hydra.nvim", - lazy = true, - config = function() - require("kide.theme.gruvbox").load_hydra_highlights() - end, - }, - - -- 代码状态栏导航 - { - "SmiteshP/nvim-navic", - lazy = true, - config = function() - local navic = require("nvim-navic") - local symbol_map = require("kide.lsp.lsp_ui").symbol_map - navic.setup({ - icons = { - File = symbol_map.File.icon .. " ", - Module = symbol_map.Module.icon .. " ", - Namespace = symbol_map.Namespace.icon .. " ", - Package = symbol_map.Package.icon .. " ", - Class = symbol_map.Class.icon .. " ", - Method = symbol_map.Method.icon .. " ", - Property = symbol_map.Property.icon .. " ", - Field = symbol_map.Field.icon .. " ", - Constructor = symbol_map.Constructor.icon .. " ", - Enum = symbol_map.Enum.icon .. "", - Interface = symbol_map.Interface.icon .. "", - Function = symbol_map.Function.icon .. " ", - Variable = symbol_map.Variable.icon .. " ", - Constant = symbol_map.Constant.icon .. " ", - String = symbol_map.String.icon .. " ", - Number = symbol_map.Number.icon .. " ", - Boolean = symbol_map.Boolean.icon .. " ", - Array = symbol_map.Array.icon .. " ", - Object = symbol_map.Object.icon .. " ", - Key = symbol_map.Key.icon .. " ", - Null = symbol_map.Null.icon .. " ", - EnumMember = symbol_map.EnumMember.icon .. " ", - Struct = symbol_map.Struct.icon .. " ", - Event = symbol_map.Event.icon .. " ", - Operator = symbol_map.Operator.icon .. " ", - TypeParameter = symbol_map.TypeParameter.icon .. " ", - }, - lazy_update_context = true, - highlight = true, - safe_output = true, - separator = " > ", - -- depth_limit = 0, - -- depth_limit_indicator = "..", - }) - end, - }, - - -- 笔记 - { - "zk-org/zk-nvim", - lazy = true, - cmd = { - "ZkIndex", - "ZkNew", - "ZkNotes", - }, - config = function() - require("kide.plugins.config.zk-nvim") - end, - }, - - -- 折叠 - { - "kevinhwang91/promise-async", - lazy = true, - }, - { - "kevinhwang91/nvim-ufo", - lazy = true, - event = { "VeryLazy" }, - config = function() - -- lsp->treesitter->indent - local ftMap = { - vim = "indent", - python = { "indent" }, - git = "", - } - - local function customizeSelector(bufnr) - local function handleFallbackException(err, providerName) - if type(err) == "string" and err:match("UfoFallbackException") then - return require("ufo").getFolds(bufnr, providerName) - else - return require("promise").reject(err) - end - end - - return require("ufo").getFolds(bufnr, "lsp") - :catch(function(err) - return handleFallbackException(err, "treesitter") - end) - :catch(function(err) - return handleFallbackException(err, "indent") - end) - end - local handler = function(virtText, lnum, endLnum, width, truncate) - local newVirtText = {} - local suffix = (" 󰁂 %d "):format(endLnum - lnum) - local sufWidth = vim.fn.strdisplaywidth(suffix) - local targetWidth = width - sufWidth - local curWidth = 0 - for _, chunk in ipairs(virtText) do - local chunkText = chunk[1] - local chunkWidth = vim.fn.strdisplaywidth(chunkText) - if targetWidth > curWidth + chunkWidth then - table.insert(newVirtText, chunk) - else - chunkText = truncate(chunkText, targetWidth - curWidth) - local hlGroup = chunk[2] - table.insert(newVirtText, { chunkText, hlGroup }) - chunkWidth = vim.fn.strdisplaywidth(chunkText) - -- str width returned from truncate() may less than 2nd argument, need padding - if curWidth + chunkWidth < targetWidth then - suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth) - end - break - end - curWidth = curWidth + chunkWidth - end - table.insert(newVirtText, { suffix, "MoreMsg" }) - return newVirtText - end - require("ufo").setup({ - provider_selector = function(_, filetype, _) - return ftMap[filetype] or customizeSelector - end, - fold_virt_text_handler = handler, - }) - require("kide.core.keybindings").ufo_mapkey() - end, - }, - - { - "ethanholz/nvim-lastplace", - lazy = true, - event = { "BufReadPost" }, - config = function() - require("nvim-lastplace").setup({ - lastplace_ignore_buftype = { "quickfix", "nofile", "help" }, - lastplace_ignore_filetype = { "gitcommit", "gitrebase", "svn", "hgcommit" }, - lastplace_open_folds = true, - }) - end, - }, - - { - "akinsho/flutter-tools.nvim", - lazy = true, - ft = { "dart" }, - init = function() - vim.api.nvim_create_autocmd("FileType", { - group = vim.api.nvim_create_augroup("kide_FlutterOutlineToggle", { clear = true }), - pattern = "dart", - callback = function(event) - vim.keymap.set("n", "o", "FlutterOutlineToggle", { buffer = event.buf, silent = true }) - end, - }) - vim.api.nvim_create_autocmd("BufNewFile", { - group = vim.api.nvim_create_augroup("kide__FlutterOutlineToggle", { clear = true }), - pattern = "Flutter Outline", - callback = function(event) - vim.keymap.set("n", "o", "FlutterOutlineToggle", { buffer = event.buf, silent = true }) - end, - }) - end, - dependencies = { - "nvim-lua/plenary.nvim", - }, - config = function() - require("kide.plugins.config.flutter-tools") - end, - }, - { - "ThePrimeagen/refactoring.nvim", - lazy = true, - ft = { - "typescript", - "javascript", - "lua", - "c", - "cpp", - "go", - "python", - "java", - "php", - "ruby", - }, - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-treesitter/nvim-treesitter", - }, - config = function() - require("refactoring").setup({}) - end, - }, - - -- ui - { - "MunifTanjim/nui.nvim", - lazy = true, - }, - - -- chatgpt - { - "robitx/gp.nvim", - lazy = true, - cmd = { - "GpNew", - "GpChatNew", - }, - config = function() - require("gp").setup({ - openai_api_endpoint = vim.env["OPENAI_API_ENDPOINT"], - }) - end, - }, - { - "folke/todo-comments.nvim", - lazy = true, - cmd = { - "TodoTelescope", - "TodoLocList", - "TodoQuickFix", - }, - config = function() - require("todo-comments").setup({}) - end, - }, - -- { - -- "zbirenbaum/copilot.lua", - -- enabled = config.plugin.copilot.enable, - -- lazy = true, - -- cmd = "Copilot", - -- config = function() - -- require("copilot").setup({}) - -- end, - -- }, - { - "github/copilot.vim", - enabled = config.plugin.copilot.enable, - config = function() - vim.g.copilot_enabled = true - vim.g.copilot_no_tab_map = true - vim.cmd('imap