From efb8f0933260a13aaefe4614a515059fb3c868af Mon Sep 17 00:00:00 2001 From: Hawtian Wang Date: Fri, 24 Nov 2023 14:10:11 +0800 Subject: [PATCH] ... --- lua/ht/plugins/lsp/glance.lua | 62 --------------- lua/ht/plugins/lsp/lspkind.lua | 55 ------------- src/conf/actions/builtin.ts | 28 ------- src/conf/plugins/lsp/glance-nvim.ts | 114 +++++++++++++++++++++++++++ src/conf/plugins/lsp/index.ts | 10 ++- src/conf/plugins/lsp/lspkind-nvim.ts | 54 +++++++++++++ src/conf/ui/right-click.ts | 6 +- src/types/vim/api.d.ts | 2 + 8 files changed, 182 insertions(+), 149 deletions(-) delete mode 100644 lua/ht/plugins/lsp/glance.lua delete mode 100644 lua/ht/plugins/lsp/lspkind.lua create mode 100644 src/conf/plugins/lsp/glance-nvim.ts create mode 100644 src/conf/plugins/lsp/lspkind-nvim.ts diff --git a/lua/ht/plugins/lsp/glance.lua b/lua/ht/plugins/lsp/glance.lua deleted file mode 100644 index 14fbf010..00000000 --- a/lua/ht/plugins/lsp/glance.lua +++ /dev/null @@ -1,62 +0,0 @@ -return { - { - "dnlhc/glance.nvim", - lazy = true, - cmd = { "Glance" }, - config = function() - local glance = require("glance") - local actions = glance.actions - - glance.setup { - detached = function(winid) - return vim.api.nvim_win_get_width(winid) < 100 - end, - preview_win_opts = { cursorline = true, number = true, wrap = false }, - border = { disable = true, top_char = "―", bottom_char = "―" }, - theme = { enable = true }, - list = { width = 0.2 }, - mappings = { - list = { - ["j"] = actions.next, - ["k"] = actions.previous, - [""] = false, - [""] = false, - [""] = actions.next_location, - [""] = actions.previous_location, - [""] = actions.preview_scroll_win(5), - [""] = actions.preview_scroll_win(-5), - ["v"] = false, - ["s"] = false, - ["t"] = false, - [""] = actions.jump, - ["o"] = false, - ["l"] = false, - ["q"] = actions.close, - ["Q"] = actions.close, - [""] = actions.close, - }, - preview = { - ["Q"] = actions.close, - [""] = false, - [""] = false, - ["l"] = false, - }, - }, - folds = { fold_closed = "󰅂", fold_open = "󰅀", folded = false }, - indent_lines = { enable = false }, - winbar = { enable = true }, - hooks = { - before_open = function(results, open, jump, method) - if method == "references" or method == "implementations" then - open(results) - elseif #results == 1 then - jump(results[1]) - else - open(results) - end - end, - }, - } - end, - }, -} diff --git a/lua/ht/plugins/lsp/lspkind.lua b/lua/ht/plugins/lsp/lspkind.lua deleted file mode 100644 index 8e2ab978..00000000 --- a/lua/ht/plugins/lsp/lspkind.lua +++ /dev/null @@ -1,55 +0,0 @@ -local M = { - "onsails/lspkind.nvim", - lazy = true, - dependencies = { "nvim-tree/nvim-web-devicons" }, -} - -M.config = function() - local lspkind = require("lspkind") - - lspkind.init { - mode = "symbol_text", - - symbol_map = { - Array = "", - Boolean = "", - Class = "", - Color = "", - Constant = "", - Constructor = "", - Enum = "", - EnumMember = "", - Event = "", - Field = "", - File = "", - Folder = "", - Function = "", - Interface = "", - Key = "", - Keyword = "", - Method = "", - Module = "", - Namespace = "", - Null = "", - Number = "", - Object = "", - Operator = "", - Package = "", - Property = "", - Reference = "", - Snippet = "", - String = "", - Struct = "", - Text = "", - TypeParameter = "", - Unit = "", - Value = "", - Variable = "", - Copilot = "", - Codeium = "", - Math = "󰀫", - }, - } -end - -return M diff --git a/src/conf/actions/builtin.ts b/src/conf/actions/builtin.ts index d4eea8e8..7d1fd12d 100644 --- a/src/conf/actions/builtin.ts +++ b/src/conf/actions/builtin.ts @@ -59,34 +59,6 @@ let lspActions = ActionGroupBuilder.start() vim.lsp.buf.declaration(); }, }) - .addOpts({ - id: "builtin.lsp.goto-definition", - title: "Goto definition", - callback: () => { - luaRequire("glance").open("definitions"); - }, - }) - .addOpts({ - id: "builtin.lsp.goto-implementation", - title: "Goto implementation", - callback: () => { - luaRequire("glance").open("implementations"); - }, - }) - .addOpts({ - id: "builtin.lsp.goto-type-definition", - title: "Goto type definition", - callback: () => { - luaRequire("glance").open("type_definitions"); - }, - }) - .addOpts({ - id: "builtin.lsp.goto-reference", - title: "Goto reference", - callback: () => { - luaRequire("glance").open("references"); - }, - }) .addOpts({ id: "builtin.lsp.rename", title: "Rename", diff --git a/src/conf/plugins/lsp/glance-nvim.ts b/src/conf/plugins/lsp/glance-nvim.ts new file mode 100644 index 00000000..e67523de --- /dev/null +++ b/src/conf/plugins/lsp/glance-nvim.ts @@ -0,0 +1,114 @@ +import { + ActionGroupBuilder, + Plugin, + PluginOptsBase, + andActions, +} from "@core/model"; + +const spec: PluginOptsBase = { + shortUrl: "dnlhc/glance.nvim", + lazy: { + lazy: true, + cmd: ["Glance"], + config: () => { + let glance = luaRequire("glance"); + let actions = glance.actions; + + glance.setup({ + detached: (winid: number) => { + return vim.api.nvim_win_get_width(winid) < 100; + }, + preview_win_opts: { cursorline: true, number: true, wrap: false }, + border: { disable: true, top_char: "―", bottom_char: "―" }, + theme: { enable: true }, + list: { width: 0.2 }, + mappings: { + list: { + ["j"]: actions.next, + ["k"]: actions.previous, + [""]: false, + [""]: false, + [""]: actions.next_location, + [""]: actions.previous_location, + [""]: actions.preview_scroll_win(5), + [""]: actions.preview_scroll_win(-5), + ["v"]: false, + ["s"]: false, + ["t"]: false, + [""]: actions.jump, + ["o"]: false, + ["l"]: false, + ["q"]: actions.close, + ["Q"]: actions.close, + [""]: actions.close, + }, + preview: { + ["Q"]: actions.close, + [""]: false, + [""]: false, + ["l"]: false, + }, + }, + folds: { fold_closed: "󰅂", fold_open: "󰅀", folded: false }, + indent_lines: { enable: false }, + winbar: { enable: true }, + hooks: { + before_open: ( + results: any[], + open: any, + jump: any, + method: string + ) => { + if (method === "references" || method === "implementations") { + open(results); + } else if (results.length === 1) { + jump(results[0]); + } else { + open(results); + } + }, + }, + }); + }, + }, +}; + +function generateActions() { + return ActionGroupBuilder.start() + .category("LSP") + .from("glance.nvim") + .condition((buf) => { + return buf.lspServers.length > 0; + }) + .addOpts({ + id: "glance.goto-definition", + title: "Goto definition", + callback: () => { + luaRequire("glance").open("definitions"); + }, + }) + .addOpts({ + id: "glance.goto-implementation", + title: "Goto implementation", + callback: () => { + luaRequire("glance").open("implementations"); + }, + }) + .addOpts({ + id: "glance.goto-type-definition", + title: "Goto type definition", + callback: () => { + luaRequire("glance").open("type_definitions"); + }, + }) + .addOpts({ + id: "glance.goto-reference", + title: "Goto reference", + callback: () => { + luaRequire("glance").open("references"); + }, + }) + .build(); +} + +export const plugin = new Plugin(andActions(spec, generateActions)); diff --git a/src/conf/plugins/lsp/index.ts b/src/conf/plugins/lsp/index.ts index f72cd3e5..15a2ec73 100644 --- a/src/conf/plugins/lsp/index.ts +++ b/src/conf/plugins/lsp/index.ts @@ -1,5 +1,13 @@ import { plugin as mason } from "./mason"; import { plugin as aerial } from "./aerial"; import { plugin as typescriptToolsNvim } from "./typescript-tools-nvim"; +import { plugin as glanceNvim } from "./glance-nvim"; +import { plugin as lspkindNvim } from "./lspkind-nvim"; -export const plugins = [mason, aerial, typescriptToolsNvim] as const; +export const plugins = [ + mason, + aerial, + typescriptToolsNvim, + glanceNvim, + lspkindNvim, +] as const; diff --git a/src/conf/plugins/lsp/lspkind-nvim.ts b/src/conf/plugins/lsp/lspkind-nvim.ts new file mode 100644 index 00000000..f844c5e3 --- /dev/null +++ b/src/conf/plugins/lsp/lspkind-nvim.ts @@ -0,0 +1,54 @@ +import { Plugin, PluginOptsBase } from "@core/model"; + +const spec: PluginOptsBase = { + shortUrl: "onsails/lspkind.nvim", + lazy: { + lazy: true, + dependencies: ["nvim-tree/nvim-web-devicons"], + config: true, + opts: { + mode: "symbol_text", + symbol_map: { + Array: "", + Boolean: "", + Class: "", + Color: "", + Constant: "", + Constructor: "", + Enum: "", + EnumMember: "", + Event: "", + Field: "", + File: "", + Folder: "", + Function: "", + Interface: "", + Key: "", + Keyword: "", + Method: "", + Module: "", + Namespace: "", + Null: "", + Number: "", + Object: "", + Operator: "", + Package: "", + Property: "", + Reference: "", + Snippet: "", + String: "", + Struct: "", + Text: "", + TypeParameter: "", + Unit: "", + Value: "", + Variable: "", + Copilot: "", + Codeium: "", + Math: "󰀫", + }, + }, + }, +}; + +export const plugin = new Plugin(spec); diff --git a/src/conf/ui/right-click.ts b/src/conf/ui/right-click.ts index d6a19aae..73a9ad71 100644 --- a/src/conf/ui/right-click.ts +++ b/src/conf/ui/right-click.ts @@ -207,17 +207,17 @@ const builtinLspGroup: RightClickMenuGroup = { }, { title: "Goto definition", - actionId: "builtin.lsp.goto-definition", + actionId: "glance.goto-definition", keys: "D", }, { title: "Goto implementation", - actionId: "builtin.lsp.goto-implementation", + actionId: "glance.goto-implementation", keys: "i", }, { title: "Inspect references", - actionId: "builtin.lsp.goto-reference", + actionId: "glance.goto-reference", keys: "r", }, { diff --git a/src/types/vim/api.d.ts b/src/types/vim/api.d.ts index d07c43ab..8a3418b8 100644 --- a/src/types/vim/api.d.ts +++ b/src/types/vim/api.d.ts @@ -217,6 +217,8 @@ declare namespace vim { export function nvim_win_set_buf(window: number, buffer: number): void; export function nvim_win_get_buf(window: number): number; + + export function nvim_win_get_width(window: number): number; export function nvim_exec_autocmds( event: string | string[],