From fc30dfaccbb63ba0e1812323abea251068bf4e37 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Tue, 26 Nov 2024 23:09:22 +0700 Subject: [PATCH] update --- lua/dirvish-do/init.lua | 3 +++ lua/dirvish-do/lsp.lua | 15 +++++++++++++++ lua/dirvish-do/operations.lua | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/lua/dirvish-do/init.lua b/lua/dirvish-do/init.lua index e9ddaf5..9b947f6 100644 --- a/lua/dirvish-do/init.lua +++ b/lua/dirvish-do/init.lua @@ -24,10 +24,12 @@ M.config = { local sep = utils.sep +---@param target string local function moveCursorTo(target) fn.search('\\V' .. fn.escape(target, '\\') .. '\\$') end + local function getVisualSelectedLines() local line_start = api.nvim_buf_get_mark(0, "<")[1] local line_end = api.nvim_buf_get_mark(0, ">")[1] @@ -177,6 +179,7 @@ function M.nremove() Dirvish() end +---@param opts table function M.setup(opts) M.config = vim.tbl_deep_extend("force", M.config, opts or {}) end diff --git a/lua/dirvish-do/lsp.lua b/lua/dirvish-do/lsp.lua index e5ee41a..345cce3 100644 --- a/lua/dirvish-do/lsp.lua +++ b/lua/dirvish-do/lsp.lua @@ -4,6 +4,8 @@ local M = {} local lsp = vim.lsp +---@param method string +---@param params table local function send(method, params) local clients = lsp.get_clients() if #clients == 0 then @@ -21,6 +23,9 @@ local function send(method, params) end end +---@param method string +---@param old_path string +---@param new_path string local function send_rename(method, old_path, new_path) local old_uri = vim.uri_from_fname(old_path) local new_uri = vim.uri_from_fname(new_path) @@ -36,6 +41,8 @@ local function send_rename(method, old_path, new_path) send(method, params) end +---@param method string +---@param path string local send_file = function(method, path) local uri = vim.uri_from_fname(path) local params = { @@ -46,26 +53,34 @@ local send_file = function(method, path) send(method, params) end +---@param old_path string +---@param new_path string function M.willRenameFiles(old_path, new_path) send_rename("workspace/willRenameFiles", old_path, new_path) end +---@param old_path string +---@param new_path string function M.didRenameFiles(old_path, new_path) send_rename("workspace/didRenameFiles", old_path, new_path) end +---@param path string function M.willCreateFiles(path) send_file("workspace/willCreateFiles", path) end +---@param path string function M.didCreateFiles(path) send_file("workspace/didCreateFiles", path) end +---@param path string function M.willDeleteFiles(path) send_file("workspace/willDeleteFiles", path) end +---@param path string function M.didDeleteFiles(path) send_file("workspace/didDeleteFiles", path) end diff --git a/lua/dirvish-do/operations.lua b/lua/dirvish-do/operations.lua index 8d3b2c5..e7e655d 100644 --- a/lua/dirvish-do/operations.lua +++ b/lua/dirvish-do/operations.lua @@ -5,8 +5,10 @@ local fn = vim.fn local uv = vim.uv or vim.loop local lsp = require('dirvish-do.lsp') +---@type string M.sep = fn.exists('+shellslash') == 1 and not vim.o.shellslash and '\\' or '/' +---@param path string function M.rm(path) if require('dirvish-do').config.operations.remove == 'trash' then M.trash(path) @@ -28,6 +30,8 @@ function M.rm(path) end end +---@param file string +---@param newpath string function M.copyfile(file, newpath) local success, errname, errmsg = uv.fs_copyfile(file, newpath) if not success then @@ -36,6 +40,8 @@ function M.copyfile(file, newpath) end -- Copy dir recursively +---@param dir string +---@param newpath string function M.copydir(dir, newpath) local handle = uv.fs_scandir(dir) if not handle then @@ -61,6 +67,9 @@ function M.copydir(dir, newpath) end end +---@param oldPath string +---@param newPath string +---@return boolean|nil, string|nil, string|nil function M.mv(oldPath, newPath) lsp.willRenameFiles(oldPath, newPath) local success, errname, errmsg = uv.fs_rename(oldPath, newPath) @@ -68,6 +77,7 @@ function M.mv(oldPath, newPath) return success, errname, errmsg end +---@param path string function M.trash(path) local py3cmd = string.format('from send2trash import send2trash; send2trash("%s")', path) vim.cmd.python3(py3cmd)