Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhuster committed Nov 26, 2024
1 parent 74f874e commit fc30dfa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/dirvish-do/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lua/dirvish-do/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 = {
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lua/dirvish-do/operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -61,13 +67,17 @@ 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)
lsp.didRenameFiles(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)
Expand Down

0 comments on commit fc30dfa

Please sign in to comment.