diff --git a/lua/ht/conf/lsp/init.lua b/lua/ht/conf/lsp/init.lua index 094afade..b1460e5f 100644 --- a/lua/ht/conf/lsp/init.lua +++ b/lua/ht/conf/lsp/init.lua @@ -1,19 +1,7 @@ ---@type ht.lsp.Server[] local all_servers = (function() local servers = {} - - servers[#servers + 1] = require("ht.conf.lsp.servers.rust-analyzer") - servers[#servers + 1] = require("ht.conf.lsp.servers.pyright") - servers[#servers + 1] = require("ht.conf.lsp.servers.cmake") - servers[#servers + 1] = require("ht.conf.lsp.servers.lua_ls") servers[#servers + 1] = require("ht.conf.lsp.servers.rime_ls") - servers[#servers + 1] = require("ht.conf.lsp.servers.flutter") - - -- init sourcekit in macos - if vim.fn.has("macunix") then - servers[#servers + 1] = require("ht.conf.lsp.servers.sourcekit") - end - return servers end)() diff --git a/lua/ht/conf/lsp/servers/cmake.lua b/lua/ht/conf/lsp/servers/cmake.lua deleted file mode 100644 index 0f938d1d..00000000 --- a/lua/ht/conf/lsp/servers/cmake.lua +++ /dev/null @@ -1,22 +0,0 @@ -local CoreConst = require("ht.core.const") -local CoreLspServer = require("ht.core.lsp.server") - ----@type ht.lsp.ServerOpts -local opts = { - name = "cmake", - mason = { - name = "cmake-language-server", - }, - setup = function(on_attach, capabilities) - require("lspconfig").cmake.setup { - cmd = { - CoreConst.mason_bin .. "/cmake-language-server", - }, - on_attach = on_attach, - capabilities = capabilities, - initializationOptions = { buildDirectory = "build" }, - } - end, -} - -return CoreLspServer.new(opts) diff --git a/lua/ht/conf/lsp/servers/flutter.lua b/lua/ht/conf/lsp/servers/flutter.lua deleted file mode 100644 index 299f4210..00000000 --- a/lua/ht/conf/lsp/servers/flutter.lua +++ /dev/null @@ -1,152 +0,0 @@ -local RightClick = require("ht.core.right-click") -local CoreLspServer = require("ht.core.lsp.server") - -local function t_cmd(s, cmd, keys) - return { - s, - callback = function() - vim.cmd(cmd) - end, - keys = keys, - } -end - -local function f_cmd(title, cmd) - return { - title = title, - f = function() - vim.cmd(cmd) - end, - } -end - ----@type ht.lsp.ServerOpts -local opts = {} - -opts.name = "flutter" - -opts.mason = false - -opts.setup = function(on_buffer_attach, capabilities) - require("flutter-tools").setup { - ui = { - border = "solid", - notification_style = "plugin", - }, - debugger = { - enabled = false, - }, - widget_guides = { - enabled = false, - }, - dev_log = { - enabled = true, - }, - lsp = { - color = { - enabled = true, - }, - on_attach = on_buffer_attach, - capabilities = capabilities, - settings = { - showTodos = false, - enableSnippets = true, - completeFunctionCalls = true, - }, - }, - } - require("telescope").load_extension("flutter") -end - -opts.right_click = { - { - index = RightClick.indexes.flutter, - enabled = { - filetype = { - "dart", - }, - }, - items = { - t_cmd("Flutter: Run", "FlutterRun"), - t_cmd("Flutter: Hot Restart", "FlutterRestart", { "R" }), - { - "Flutter More", - keys = { "F" }, - children = { - t_cmd("Hot Reload", "FlutterReload"), - t_cmd("Toggle Outline", "FlutterOutlineToggle"), - t_cmd("Open Outline", "FlutterOutlineOpen"), - t_cmd("Go to super class", "FlutterSuper"), - }, - }, - }, - }, -} - -opts.function_sets = { - { - category = "Flutter", - ---@param buffer VimBuffer - filter = function(buffer) - for _, server in ipairs(buffer.lsp_servers) do - if server.name == "dartls" then - return true - end - end - return false - end, - functions = { - f_cmd( - "Run the current project. This needs to be run from within a flutter project", - "FlutterRun" - ), - f_cmd( - "Brings up a list of connected devices to select from", - "FlutterDevices" - ), - f_cmd( - "Similar to devices but shows a list of emulators to choose from", - "FlutterEmulators" - ), - f_cmd("Reload the running project", "FlutterReload"), - f_cmd("Restart the current project", "FlutterRestart"), - f_cmd("Ends a running session", "FlutterQuit"), - f_cmd( - "Ends a running session locally but keeps the process running on the device", - "FlutterDetach" - ), - f_cmd( - "Toggle the outline window showing the widget tree for the given file", - "FlutterOutlineToggle" - ), - f_cmd( - "Opens an outline window showing the widget tree for the given file", - "FlutterOutlineOpen" - ), - f_cmd("Starts a Dart Dev Tools server", "FlutterDevTools"), - f_cmd("Activates a Dart Dev Tools server", "FlutterDevToolsActivate"), - f_cmd( - "Copies the profiler url to your system clipboard (+ register). Note that commands FlutterRun and FlutterDevTools must be executed first", - "FlutterCopyProfilerUrl" - ), - f_cmd( - "This command restarts the dart language server, and is intended for situations where it begins to work incorrectly", - "FlutterLspRestart" - ), - f_cmd( - "Go to super class, method using custom LSP method dart/textDocument/super", - "FlutterSuper" - ), - f_cmd( - "Forces LSP server reanalyze using custom LSP method dart/reanalyze", - "FlutterReanalyze" - ), - f_cmd( - [[Renames and updates imports if lsp.settings.renameFilesWithClasses == "always"]], - "FlutterRename" - ), - }, - }, -} - -return CoreLspServer.new(opts) diff --git a/lua/ht/conf/lsp/servers/lua_ls.lua b/lua/ht/conf/lsp/servers/lua_ls.lua deleted file mode 100644 index 58bf12a8..00000000 --- a/lua/ht/conf/lsp/servers/lua_ls.lua +++ /dev/null @@ -1,68 +0,0 @@ -local CoreConst = require("ht.core.const") -local CoreLspServer = require("ht.core.lsp.server") - ----@type ht.lsp.ServerOpts -local opts = {} - -opts.name = "lua_ls" - -opts.mason = { name = "lua-language-server" } - -local enabled_plugins = { - ["telescope.nvim"] = true, - ["plenary.nvim"] = true, - ["lazy.nvim"] = true, - ["nui.nvim"] = true, -} - -opts.setup = function(on_attach, capabilities) - local lua_library = { - vim.fn.expand("$VIMRUNTIME/lua"), - vim.fn.expand("$VIMRUNTIME/lua/vim/lsp"), - "${3rd}/luassert/library", - } - if package.loaded["lazy"] then - local lazy_plugins = require("lazy").plugins() - local data_path = vim.fn.stdpath("data") - for _, plugin in ipairs(lazy_plugins) do - if - enabled_plugins[plugin.name] - or plugin.dir:find(data_path, 1, true) ~= 1 - then - lua_library[#lua_library + 1] = plugin.dir - end - end - end - - require("lspconfig").lua_ls.setup { - cmd = { - CoreConst.mason_bin .. "/lua-language-server", - }, - on_attach = on_attach, - capabilities = capabilities, - settings = { - Lua = { - runtime = { - version = "LuaJIT", - path = vim.split(package.path, ";"), - }, - diagnostics = { - globals = { "vim" }, - disable = { - "missing-fields", - }, - }, - workspace = { library = lua_library }, - format = { - enable = true, - defaultConfig = { - indent_style = "space", - continuation_indent_size = "2", - }, - }, - }, - }, - } -end - -return CoreLspServer.new(opts) diff --git a/lua/ht/conf/lsp/servers/pyright.lua b/lua/ht/conf/lsp/servers/pyright.lua deleted file mode 100644 index ec39041c..00000000 --- a/lua/ht/conf/lsp/servers/pyright.lua +++ /dev/null @@ -1,20 +0,0 @@ -local CoreConst = require("ht.core.const") -local CoreLspServer = require("ht.core.lsp.server") - ----@type ht.lsp.ServerOpts -local opts = {} - -opts.name = "pyright" - -opts.setup = function(on_attach, capabilities) - require("lspconfig").pyright.setup { - cmd = { - CoreConst.mason_bin .. "/pyright-langserver", - "--stdio", - }, - on_attach = on_attach, - capabilities = capabilities, - } -end - -return CoreLspServer.new(opts) diff --git a/lua/ht/conf/lsp/servers/rust-analyzer.lua b/lua/ht/conf/lsp/servers/rust-analyzer.lua deleted file mode 100644 index 62d4c074..00000000 --- a/lua/ht/conf/lsp/servers/rust-analyzer.lua +++ /dev/null @@ -1,123 +0,0 @@ -local RightClick = require("ht.core.right-click") -local CoreConst = require("ht.core.const") -local CoreLspServer = require("ht.core.lsp.server") - ----@type ht.lsp.ServerOpts -local opts = {} - -opts.name = "rust-analyzer" - -opts.setup = function(on_attach, capabilities) - require("rust-tools").setup { - tools = { - on_initialized = function() - vim.notify("rust-analyzer initialize done") - end, - inlay_hints = { auto = true }, - }, - server = { - cmd = { - CoreConst.mason_bin .. "/rust-analyzer", - }, - on_attach = on_attach, - capabilities = capabilities, - settings = { - ["rust-analyzer"] = { - cargo = { buildScripts = { enable = true } }, - procMacro = { enable = true }, - check = { - command = "clippy", - extraArgs = { "--all", "--", "-W", "clippy::all" }, - }, - completion = { privateEditable = { enable = true } }, - diagnostic = { - enable = true, - disabled = { "inactive-code" }, - }, - }, - }, - }, - } -end - -opts.right_click = { - { - index = RightClick.indexes.rust_tools, - enabled = { - filetype = "rust", - }, - items = { - { - "Rust", - keys = { "R" }, - children = { - { - "Hover Actions", - callback = function() - require("rust-tools").hover_actions.hover_actions() - end, - }, - { - "Open Cargo", - callback = function() - require("rust-tools").open_cargo_toml.open_cargo_toml() - end, - keys = { "c" }, - desc = "open project Cargo.toml", - }, - { - "Move Item Up", - callback = function() - require("rust-tools").move_item.move_item(true) - end, - }, - { - "Expand Macro", - callback = function() - require("rust-tools").expand_macro.expand_macro() - end, - desc = "expand macros recursively", - keys = { "e", "E" }, - }, - { - "Parent Module", - callback = function() - require("rust-tools").parent_module.parent_module() - end, - keys = { "p" }, - }, - { - "Join Lines", - callback = function() - require("rust-tools").join_lines.join_lines() - end, - }, - }, - }, - }, - }, -} - -opts.function_sets = { - { - category = "Rust Analyzer", - functions = { - { - title = "Open cargo.toml", - f = function() - require("rust-tools").open_cargo_toml.open_cargo_toml() - end, - }, - }, - filter = function(buffer) - for _, server in ipairs(buffer.lsp_servers) do - if server.name == "rust-analyzer" then - return true - end - end - return false - end, - }, -} - -return CoreLspServer.new(opts) diff --git a/lua/ht/conf/lsp/servers/sourcekit.lua b/lua/ht/conf/lsp/servers/sourcekit.lua deleted file mode 100644 index 44df88c8..00000000 --- a/lua/ht/conf/lsp/servers/sourcekit.lua +++ /dev/null @@ -1,18 +0,0 @@ -local CoreLspServer = require("ht.core.lsp.server") - ----@type ht.lsp.ServerOpts -local opts = {} - -opts.name = "sourcekit" - -opts.mason = false - -opts.setup = function(on_attach, capabilities) - require("lspconfig").sourcekit.setup { - filetypes = { "swift", "objective-c", "objective-cpp" }, - on_attach = on_attach, - capabilities = capabilities, - } -end - -return CoreLspServer.new(opts) diff --git a/lua/ht/conf/lsp/servers/tsserver.lua b/lua/ht/conf/lsp/servers/tsserver.lua deleted file mode 100644 index afa4b49c..00000000 --- a/lua/ht/conf/lsp/servers/tsserver.lua +++ /dev/null @@ -1,22 +0,0 @@ -local CoreConst = require("ht.core.const") -local CoreLspServer = require("ht.core.lsp.server") - ----@type ht.lsp.ServerOpts -local opts = {} - -opts.name = "tsserver" - -opts.mason = { name = "typescript-language-server" } - -opts.setup = function(on_attach, capabilities) - require("lspconfig").tsserver.setup { - cmd = { - CoreConst.mason_bin .. "/typescript-language-server", - "--stdio", - }, - on_attach = on_attach, - capabilities = capabilities, - } -end - -return CoreLspServer.new(opts) diff --git a/src/conf/actions/index.ts b/src/conf/actions/index.ts index 067124cf..f8c5ee39 100644 --- a/src/conf/actions/index.ts +++ b/src/conf/actions/index.ts @@ -1,7 +1,13 @@ import { AllPlugins } from "@conf/plugins"; -import { Plugin, PluginActionIds, TraitActionsId } from "@core/model"; +import { + LspServer, + Plugin, + PluginActionIds, + TraitActionsId, +} from "@core/model"; import { RemoveReadonlyFromTuple, TupleToUnion } from "@core/type_traits"; import { builtinActions } from "./builtin"; +import { AllLspServers } from "@conf/external_tools"; export type AvailableActions = TupleToUnion< [ @@ -9,9 +15,29 @@ export type AvailableActions = TupleToUnion< RemoveReadonlyFromTuple >, ...TraitActionsId>, + ...MergePluginsActionsMaybeGroup< + LazyServersIntoPlugin> + >, ] >; +type LazyServerIntoPlugin

> = P extends LspServer< + infer AIds +> + ? Plugin + : never; + +type LazyServersIntoPlugin

[]> = P extends [ + infer F, + ...infer R, +] + ? F extends LspServer + ? R extends LspServer[] + ? [LazyServerIntoPlugin, ...LazyServersIntoPlugin] + : never + : never + : []; + type MergePluginsActionsMaybeGroup = Ps extends [ infer P, ...infer Rest, diff --git a/src/conf/external_tools/lsp_servers/clangd.ts b/src/conf/external_tools/lsp_servers/clangd.ts index cc442305..70a309a4 100644 --- a/src/conf/external_tools/lsp_servers/clangd.ts +++ b/src/conf/external_tools/lsp_servers/clangd.ts @@ -1,6 +1,61 @@ -import { LspServer } from "@core/model"; +import { + ActionGroupBuilder, + LspServer, + Plugin, + PluginOptsBase, + andActions, +} from "@core/model"; import { HttsContext } from "context"; +const spec: PluginOptsBase = { + shortUrl: "p00f/clangd_extensions.nvim", + lazy: { + lazy: true, + }, +}; + +function generateActions() { + return ActionGroupBuilder.start() + .category("Clangd") + .from("clangd_extensions.nvim") + .condition((buf) => { + for (let server of buf.lspServers) { + if (server.name === "clangd") { + return true; + } + } + return false; + }) + .addOpts({ + id: "clangd.switch-source-header", + title: "Switch between source and header files", + callback: "ClangdSwitchSourceHeader", + }) + .addOpts({ + id: "clangd.view-ast", + title: "View AST", + callback: "ClangdAST", + }) + .addOpts({ + id: "clangd.view-type-hierarchy", + title: "View type hierarchy", + callback: "ClangdTypeHierarchy", + }) + .addOpts({ + id: "clangd.symbol-info", + title: "Symbol info", + callback: "ClangdSymbolInfo", + }) + .addOpts({ + id: "clangd.memory-usage", + title: "Memory usage", + callback: "ClangdMemoryUsage", + }) + .build(); +} + +const plugin = new Plugin(andActions(spec, generateActions)); + function wrapOnAttach(defaultCallback: (client: any, bufnr: number) => void) { return (client: unknown, bufnr: number) => { defaultCallback(client, bufnr); @@ -21,6 +76,7 @@ function wrapOnAttach(defaultCallback: (client: any, bufnr: number) => void) { export const server = new LspServer({ name: "clangd", + plugin, exe: { masonPkg: "clangd", }, diff --git a/src/conf/external_tools/lsp_servers/cmake.ts b/src/conf/external_tools/lsp_servers/cmake.ts new file mode 100644 index 00000000..b3cb47a4 --- /dev/null +++ b/src/conf/external_tools/lsp_servers/cmake.ts @@ -0,0 +1,16 @@ +import { LspServer } from "@core/model"; + +export const server = new LspServer({ + name: "cmake", + exe: { + masonPkg: "cmake-language-server", + }, + setup: (s: LspServer, on_attach, capabilities) => { + luaRequire("lspconfig").cmake.setup({ + cmd: [s.executable], + on_attach: on_attach, + capabilities: capabilities, + initializationOptions: { buildDirectory: "build" }, + }); + }, +}); diff --git a/src/conf/external_tools/lsp_servers/flutter.ts b/src/conf/external_tools/lsp_servers/flutter.ts new file mode 100644 index 00000000..46badea1 --- /dev/null +++ b/src/conf/external_tools/lsp_servers/flutter.ts @@ -0,0 +1,157 @@ +import { + ActionGroupBuilder, + LspServer, + Plugin, + PluginOptsBase, + andActions, +} from "@core/model"; + +const spec: PluginOptsBase = { + shortUrl: "akinsho/flutter-tools.nvim", + lazy: { + lazy: true, + dependencies: [ + "nvim-lua/plenary.nvim", + "stevearc/dressing.nvim", + "nvim-telescope/telescope.nvim", + ], + }, +}; + +function generateActions() { + return ActionGroupBuilder.start() + .from("flutter-tools.nvim") + .category("Flutter") + .condition((buffer) => { + return buffer.filetype === "dart"; + }) + .addOpts({ + id: "flutter-tools.run-project", + title: + "Run the current project. This need to be run from within" + + " a flutter project", + callback: "FlutterRun", + }) + .addOpts({ + id: "flutter-tools.select-devices", + title: "Brings up a list of connected devices to select from", + callback: "FlutterDevices", + }) + .addOpts({ + id: "flutter-tools.select-emulators", + title: "Similar to devices but shows a list of emulators to choose from", + callback: "FlutterEmulators", + }) + .addOpts({ + id: "flutter-tools.hot-reload", + title: "Reload the running project", + callback: "FlutterReload", + }) + .addOpts({ + id: "flutter-tools.restart-project", + title: "Restart the current project", + callback: "FlutterRestart", + }) + .addOpts({ + id: "flutter-tools.quit-project", + title: "Ends a running session", + callback: "FlutterQuit", + }) + .addOpts({ + id: "flutter-tools.detach-project", + title: + "Ends a running session, but keeps the process running on the device", + callback: "FlutterDetach", + }) + .addOpts({ + id: "flutter-tools.toggle-outline", + title: + "Toggle the outline window showing the widget tree for the given file", + callback: "FlutterOutlineToggle", + }) + .addOpts({ + id: "flutter-tools.open-outline", + title: + "Opens an outline window showing the widget tree for the given file", + callback: "FlutterOutlineOpen", + }) + .addOpts({ + id: "flutter-tools.start-dev-tools", + title: "Starts a Dart Dev Tools server", + callback: "FlutterDevTools", + }) + .addOpts({ + id: "flutter-tools.active-dev-tools", + title: "Activates a Dart Dev Tools server", + callback: "FlutterDevToolsActivate", + }) + .addOpts({ + id: "flutter-tools.copy-profiler-url", + title: + "Copies the profiler url to your system clipboard (+ register). Note that commands FlutterRun and FlutterDevTools must be executed first", + callback: "FlutterCopyProfilerUrl", + }) + .addOpts({ + id: "flutter-tools.lsp-restart", + title: + "This command restarts the dart language server, and is intended for situations where it begins to work incorrectly", + callback: "FlutterLspRestart", + }) + .addOpts({ + id: "flutter-tools.goto-super-class", + title: + "Go to super class, method using custom LSP method dart/textDocument/super", + callback: "FlutterSuper", + }) + .addOpts({ + id: "flutter-tools.reanalyze", + title: + "Forces LSP server reanalyze using custom LSP method dart/reanalyze", + callback: "FlutterReanalyze", + }) + .addOpts({ + id: "flutter-tools.rename", + title: + "Renames and updates imports if lsp.settings.renameFilesWithClasses == 'always'", + callback: "FlutterRename", + }) + .build(); +} + +const plugin = new Plugin(andActions(spec, generateActions)); + +export const server = new LspServer({ + name: "flutter", + plugin, + exe: false, + setup: (_, on_attach, capabilities) => { + luaRequire("flutter-tools").setup({ + ui: { + border: "solid", + notification_style: "plugin", + }, + debugger: { + enabled: false, + }, + widget_guides: { + enabled: false, + }, + dev_log: { + enabled: true, + }, + lsp: { + color: { + enabled: true, + }, + on_attach: on_attach, + capabilities: capabilities, + settings: { + showTodos: false, + enableSnippets: true, + completeFunctionCalls: true, + }, + }, + }); + luaRequire("telescope").load_extension("flutter"); + }, +}); diff --git a/src/conf/external_tools/lsp_servers/index.ts b/src/conf/external_tools/lsp_servers/index.ts index 78ab1434..7f8f6e78 100644 --- a/src/conf/external_tools/lsp_servers/index.ts +++ b/src/conf/external_tools/lsp_servers/index.ts @@ -1,4 +1,19 @@ -import typescriptTool from "./typescript-tools"; -import { server as clangdTool } from "./clangd"; +import { server as typescript } from "./typescript"; +import { server as clangd } from "./clangd"; +import { server as rustAnalyzer } from "./rust-analyzer"; +import { server as sourcekit } from "./sourcekit"; +import { server as pyright } from "./pyright"; +import { server as cmake } from "./cmake"; +import { server as flutter } from "./flutter"; +import { server as luaLs } from "./lua_ls"; -export default [typescriptTool, clangdTool]; +export default [ + typescript, + clangd, + rustAnalyzer, + sourcekit, + pyright, + cmake, + flutter, + luaLs, +] as const; diff --git a/src/conf/external_tools/lsp_servers/lua_ls.ts b/src/conf/external_tools/lsp_servers/lua_ls.ts new file mode 100644 index 00000000..5fa2a0ff --- /dev/null +++ b/src/conf/external_tools/lsp_servers/lua_ls.ts @@ -0,0 +1,49 @@ +import { LspServer } from "@core/model"; + +// const enabledPlugins = [ +// "telescope.nvim", +// "plenary.nvim", +// "lazy.nvim", +// "nui.nvim", +// ]; + +export const server = new LspServer({ + name: "lua_ls", + exe: { + masonPkg: "lua-language-server", + }, + setup: (s: LspServer, on_attach, capabilities) => { + let luaLibraries = [ + vim.fn.expand("$VIMRUNTIME/lua"), + vim.fn.expand("$VIMRUNTIME/lua/vim/lsp"), + "${3rd}/luassert/library", + ]; + + luaRequire("lspconfig").lua_ls.setup({ + cmd: [s.executable], + on_attach: on_attach, + capabilities: capabilities, + settings: { + Lua: { + runtime: { + version: "LuaJIT", + // @ts-ignore + path: vim.split(package.path, ";"), + }, + diagnostics: { + globals: ["vim"], + disable: ["missing-fields"], + }, + workspace: { library: luaLibraries }, + format: { + enable: true, + defaultConfig: { + indent_style: "space", + continuation_indent_size: "2", + }, + }, + }, + }, + }); + }, +}); diff --git a/src/conf/external_tools/lsp_servers/pyright.ts b/src/conf/external_tools/lsp_servers/pyright.ts new file mode 100644 index 00000000..184617f7 --- /dev/null +++ b/src/conf/external_tools/lsp_servers/pyright.ts @@ -0,0 +1,16 @@ +import { LspServer } from "@core/model"; +import { HttsContext } from "context"; + +export const server = new LspServer({ + name: "pyright", + exe: { + masonPkg: "pyright", + }, + setup: (_server: LspServer, on_attach, capabilities) => { + luaRequire("lspconfig").pyright.setup({ + cmd: [`${HttsContext.getInstance()}/pyright-langserver`, "--stdio"], + on_attach: on_attach, + capabilities: capabilities, + }); + }, +}); diff --git a/src/conf/external_tools/lsp_servers/rust-analyzer.ts b/src/conf/external_tools/lsp_servers/rust-analyzer.ts new file mode 100644 index 00000000..a3a16319 --- /dev/null +++ b/src/conf/external_tools/lsp_servers/rust-analyzer.ts @@ -0,0 +1,106 @@ +import { ActionGroupBuilder, LspServer, Plugin, andActions } from "@core/model"; +import { HttsContext } from "context"; + +const plugin = new Plugin( + andActions( + { + shortUrl: "simrat39/rust-tools.nvim", + lazy: { + lazy: true, + dependencies: ["nvim-lua/plenary.nvim", "mfussenegger/nvim-dap"], + }, + }, + () => { + return new ActionGroupBuilder() + .from("rust-tools") + .category("RustTools") + .condition((buf) => { + for (const server of buf.lspServers) { + if (server.name === "rust_analyzer") return true; + } + return false; + }) + .addOpts({ + id: "rust-tools.open-cargo-toml", + title: "Open cargo.toml of this file", + callback: () => { + luaRequire("rust-tools").open_cargo_toml.open_cargo_toml(); + }, + }) + .addOpts({ + id: "rust-tools.open-parent-module", + title: "Open parent module of this file", + callback: () => { + luaRequire("rust-tools").parent_module.parent_module(); + }, + }) + .addOpts({ + id: "rust-tools.hover-actions", + title: "Hover actions", + callback: () => { + luaRequire("rust-tools").hover_actions.hover_actions(); + }, + }) + .addOpts({ + id: "rust-tools.move-items-up", + title: "Move items up", + callback: () => { + luaRequire("rust-tools").move_item.move_item(true); + }, + }) + .addOpts({ + id: "rust-tools.join-lines", + title: "Join lines", + callback: () => { + luaRequire("rust-tools").join_lines.join_lines(); + }, + }) + .addOpts({ + id: "rust-tools.expand-macro", + title: "Expand macro", + callback: () => { + luaRequire("rust-tools").expand_macro.expand_macro(); + }, + }) + .build(); + } + ) +); + +export const server = new LspServer({ + name: "rust-analyzer", + plugin, + exe: { + masonPkg: "rust-analyzer", + }, + setup: (_server, on_attach, capabilities) => { + luaRequire("rust-tools").setup({ + tools: { + on_initialized: () => { + vim.notify("rust-analyzer initialize done"); + }, + inlay_hints: { auto: true }, + }, + server: { + cmd: [HttsContext.getInstance().masonBinRoot + "/rust-analyzer"], + on_attach: on_attach, + capabilities: capabilities, + settings: { + ["rust-analyzer"]: { + cargo: { buildScripts: { enable: true } }, + procMacro: { enable: true }, + check: { + command: "clippy", + extraArgs: ["--all", "--", "-W", "clippy::all"], + }, + completion: { privateEditable: { enable: true } }, + diagnostic: { + enable: true, + disabled: ["inactive-code"], + }, + }, + }, + }, + }); + }, +}); diff --git a/src/conf/external_tools/lsp_servers/sourcekit.ts b/src/conf/external_tools/lsp_servers/sourcekit.ts new file mode 100644 index 00000000..4f5fd907 --- /dev/null +++ b/src/conf/external_tools/lsp_servers/sourcekit.ts @@ -0,0 +1,17 @@ +import { LspServer } from "@core/model"; + +export const server = new LspServer({ + name: "sourcekit", + exe: false, + setup: ( + _server: LspServer, + on_attach: () => void, + capabilities: LuaTable + ) => { + luaRequire("lspconfig").sourcekit.setup({ + filetypes: ["swift", "objective-c", "objective-cpp"], + on_attach: on_attach, + capabilities: capabilities, + }); + }, +}); diff --git a/src/conf/external_tools/lsp_servers/typescript-tools.ts b/src/conf/external_tools/lsp_servers/typescript-tools.ts deleted file mode 100644 index 4b0ea635..00000000 --- a/src/conf/external_tools/lsp_servers/typescript-tools.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { LspServer } from "@core/model"; - -export default new LspServer({ - name: "typescript-tools", - exe: { - masonPkg: "typescript-language-server", - }, - setup(_server: LspServer, on_attach: () => void, _capabilities: LuaTable) { - luaRequire("typescript-tools").setup({ - on_attach: on_attach, - settings: { - tsserver_locale: "en", - complete_function_calls: true, - }, - }); - }, -}); diff --git a/src/conf/plugins/lsp/typescript-tools-nvim.ts b/src/conf/external_tools/lsp_servers/typescript.ts similarity index 80% rename from src/conf/plugins/lsp/typescript-tools-nvim.ts rename to src/conf/external_tools/lsp_servers/typescript.ts index 947cb263..567e1236 100644 --- a/src/conf/plugins/lsp/typescript-tools-nvim.ts +++ b/src/conf/external_tools/lsp_servers/typescript.ts @@ -1,5 +1,6 @@ import { ActionGroupBuilder, + LspServer, Plugin, PluginOpts, andActions, @@ -72,4 +73,21 @@ export const spec: PluginOpts = { allowInVscode: false, }; -export const plugin = new Plugin(andActions(spec, generateActions)); +const plugin = new Plugin(andActions(spec, generateActions)); + +export const server = new LspServer({ + name: "typescript-tools", + plugin, + exe: { + masonPkg: "typescript-language-server", + }, + setup(_server: LspServer, on_attach: () => void, _capabilities: LuaTable) { + luaRequire("typescript-tools").setup({ + on_attach: on_attach, + settings: { + tsserver_locale: "en", + complete_function_calls: true, + }, + }); + }, +}); diff --git a/src/conf/plugins/coding/index.ts b/src/conf/plugins/coding/index.ts index 1fe935b8..0474d13a 100644 --- a/src/conf/plugins/coding/index.ts +++ b/src/conf/plugins/coding/index.ts @@ -4,7 +4,6 @@ import { plugin as cppToolkit } from "./cpp-toolkit"; import { plugin as cratesNvim } from "./crates-nvim"; import { plugin as nabla } from "./nabla"; import { plugin as neogen } from "./neogen"; -import { plugin as rustToolsNvim } from "./rust-tools-nvim"; import { plugin as luasnip } from "./luasnip"; export const plugins = [ @@ -14,6 +13,5 @@ export const plugins = [ cratesNvim, nabla, neogen, - rustToolsNvim, luasnip, ] as const; diff --git a/src/conf/plugins/coding/rust-tools-nvim.ts b/src/conf/plugins/coding/rust-tools-nvim.ts deleted file mode 100644 index 10c071fd..00000000 --- a/src/conf/plugins/coding/rust-tools-nvim.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { - ActionGroupBuilder, - Plugin, - andActions, - buildSimpleCommand, -} from "@core/model"; - -export const plugin = new Plugin( - andActions( - { - shortUrl: "simrat39/rust-tools.nvim", - lazy: { - lazy: true, - dependencies: ["nvim-lua/plenary.nvim", "mfussenegger/nvim-dap"], - }, - extends: { - commands: { - category: "RustTools", - enabled: (buf) => { - for (const server of buf.lspServers) { - if (server.name === "rust_analyzer") return true; - } - return false; - }, - commands: [ - buildSimpleCommand("Open cargo.toml of this file", () => { - luaRequire("rust-tools").open_cargo_toml.open_cargo_toml(); - }), - buildSimpleCommand("Open parent module of this file", () => { - luaRequire("rust-tools").parent_module.parent_module(); - }), - ], - }, - }, - }, - () => { - return new ActionGroupBuilder() - .from("rust-tools") - .category("RustTools") - .condition((buf) => { - for (const server of buf.lspServers) { - if (server.name === "rust_analyzer") return true; - } - return false; - }) - .addOpts({ - id: "rust-tools.open-cargo-toml", - title: "Open cargo.toml of this file", - callback: () => { - luaRequire("rust-tools").open_cargo_toml.open_cargo_toml(); - }, - }) - .addOpts({ - id: "rust-tools.open-parent-module", - title: "Open parent module of this file", - callback: () => { - luaRequire("rust-tools").parent_module.parent_module(); - }, - }) - .build(); - } - ) -); diff --git a/src/conf/plugins/index.ts b/src/conf/plugins/index.ts index ead5e635..a5ec0bc3 100644 --- a/src/conf/plugins/index.ts +++ b/src/conf/plugins/index.ts @@ -25,7 +25,7 @@ export const AllPlugins = [ export const LazySpecs = [...AllPlugins, ...AllLspServers] .flat() - .map((p) => p.asLazySpec()); + .map((p) => p.intoLazySpec()); export class ActionRegistry { private static instance?: ActionRegistry; @@ -38,6 +38,12 @@ export class ActionRegistry { this.add(action); }); }); + AllLspServers.flat().forEach((server) => { + server.plugin?.actions.forEach((action) => { + this.add(action); + }); + }); + builtinActions.forEach((action) => { this.add(action); }); diff --git a/src/conf/plugins/lsp/clangd_extensions-nvim.ts b/src/conf/plugins/lsp/clangd_extensions-nvim.ts deleted file mode 100644 index c399332e..00000000 --- a/src/conf/plugins/lsp/clangd_extensions-nvim.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { - ActionGroupBuilder, - Plugin, - PluginOptsBase, - andActions, -} from "@core/model"; - -const spec: PluginOptsBase = { - shortUrl: "p00f/clangd_extensions.nvim", - lazy: { - lazy: true, - }, -}; - -function generateActions() { - return ActionGroupBuilder.start() - .category("Clangd") - .from("clangd_extensions.nvim") - .condition((buf) => { - for (let server of buf.lspServers) { - if (server.name === "clangd") { - return true; - } - } - return false; - }) - .addOpts({ - id: "clangd.switch-source-header", - title: "Switch between source and header files", - callback: "ClangdSwitchSourceHeader", - }) - .addOpts({ - id: "clangd.view-ast", - title: "View AST", - callback: "ClangdAST", - }) - .addOpts({ - id: "clangd.view-type-hierarchy", - title: "View type hierarchy", - callback: "ClangdTypeHierarchy", - }) - .addOpts({ - id: "clangd.symbol-info", - title: "Symbol info", - callback: "ClangdSymbolInfo", - }) - .addOpts({ - id: "clangd.memory-usage", - title: "Memory usage", - callback: "ClangdMemoryUsage", - }) - .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 d442c73d..5261d751 100644 --- a/src/conf/plugins/lsp/index.ts +++ b/src/conf/plugins/lsp/index.ts @@ -1,17 +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"; import { plugin as troubleNvim } from "./trouble-nvim"; -import { plugin as clangdExtensionsNvim } from "./clangd_extensions-nvim"; export const plugins = [ mason, aerial, - typescriptToolsNvim, glanceNvim, lspkindNvim, troubleNvim, - clangdExtensionsNvim, ] as const; diff --git a/src/conf/ui/right-click.ts b/src/conf/ui/right-click.ts index 73a9ad71..05cfce46 100644 --- a/src/conf/ui/right-click.ts +++ b/src/conf/ui/right-click.ts @@ -164,6 +164,52 @@ const rustToolkitGroup: RightClickMenuGroup = { ], }; +const flutterGroup: RightClickMenuGroup = { + items: [ + { + title: "Flutter: Run", + actionId: "flutter-tools.run-project", + }, + { + title: "Flutter: Restart", + actionId: "flutter-tools.restart-project", + }, + { + title: "Flutter: More", + children: [ + { + title: "Flutter: Select devices", + actionId: "flutter-tools.select-devices", + }, + { + title: "Flutter: Select emulators", + actionId: "flutter-tools.select-emulators", + }, + { + title: "Flutter: Hot reload", + actionId: "flutter-tools.hot-reload", + }, + { + title: "Flutter: Quit", + actionId: "flutter-tools.quit-project", + }, + { + title: "Flutter: Detach", + actionId: "flutter-tools.detach-project", + }, + { + title: "Flutter: Toggle outline", + actionId: "flutter-tools.toggle-outline", + }, + { + title: "Flutter: Open outline", + actionId: "flutter-tools.open-outline", + }, + ], + }, + ], +}; + const formatFileItem: RightClickMenuActionItem = { title: "Format file", actionId: "conform.format", @@ -234,6 +280,7 @@ export const rightClickMenu: RightClickMenuItem[] = [ formatFileItem, cppToolkitGroup, rustToolkitGroup, + flutterGroup, builtinLspGroup, copilotGroup, ]; diff --git a/src/core/model/ext_tool.ts b/src/core/model/ext_tool.ts index f16f24f9..ac3e4e3a 100644 --- a/src/core/model/ext_tool.ts +++ b/src/core/model/ext_tool.ts @@ -1,5 +1,5 @@ import { HttsContext } from "context"; -import { LazySpec } from "./plugin"; +import { LazySpec, Plugin } from "./plugin"; export interface MasonPackageOpt { /** @@ -121,7 +121,7 @@ type LspServerSetupFn = ( capabilities: LuaTable ) => void; -type LspServerOpt = ( +type LspServerOpt = ( | { setup: LspServerSetupFn; } @@ -133,14 +133,14 @@ type LspServerOpt = ( /** * where the lsp server is from */ - plugin?: LazySpec | string; + plugin?: Plugin; }; -export class LspServer extends ExternalTools { +export class LspServer extends ExternalTools { readonly setup: LspServerSetupFn; - readonly plugin?: LazySpec | string; + readonly plugin?: Plugin; - constructor(opts: ExternalToolsOpt & LspServerOpt) { + constructor(opts: ExternalToolsOpt & LspServerOpt) { super(opts); if ("setup" in opts) { this.setup = opts.setup; @@ -165,7 +165,7 @@ export class LspServer extends ExternalTools { }; } - asLazySpec(): LazySpec | string | undefined { - return this.plugin; + intoLazySpec(): LazySpec | string | undefined { + return this.plugin?.intoLazySpec(); } } diff --git a/src/core/model/plugin.ts b/src/core/model/plugin.ts index b0732d77..17b4a864 100644 --- a/src/core/model/plugin.ts +++ b/src/core/model/plugin.ts @@ -210,7 +210,7 @@ export class Plugin { return this._opts.lazy?.config; } - asLazySpec(): LazySpec | string { + intoLazySpec(): LazySpec | string { if (!this._opts.lazy && this.commands.length === 0) { return this._opts.shortUrl; } diff --git a/src/types/vim/builtin.d.ts b/src/types/vim/builtin.d.ts index 5a3f3453..b314b016 100644 --- a/src/types/vim/builtin.d.ts +++ b/src/types/vim/builtin.d.ts @@ -298,4 +298,14 @@ declare namespace vim { export function uri_to_bufnr(this: void, uri: string): number; export function tbl_keys(this: void, val: AnyTable): string[]; + + export function split( + this: void, + str: string, + sep: string, + opts?: { + plain?: boolean; + trimempty?: boolean; + } + ): string[]; }