snailed
/
taolf
Archived
2
0
Fork 0

fix error reporting

This commit is contained in:
Luca Bilke 2024-01-29 01:23:11 +01:00
parent 42a5903d57
commit 38e37900fa
No known key found for this signature in database
GPG Key ID: AD6630D0A1E650AC
5 changed files with 23 additions and 17 deletions

View File

@ -15,12 +15,12 @@ process with lazy.nvim a tiny bit.
Setup:
```lua
require("taolf").setup({
default_cmd = "lf", -- The Command to start lf with
dir = "", -- The dir to start lf in. "gwd" expands to the git working directory
default_cmd = "lf", -- The Command to start lf with.
dir = "", -- The dir to start lf in. "gwd" expands to the git working directory.
}
vim.keymap.set("n", "a<Leader>el", require("lf").start, { desc = "Open Lf" })
vim.keymap.set("n", "<Leader>ec", function() require("lf").start({ dir = "cwd" }) end,
vim.keymap.set("n", "<Leader>ec", function() require("lf").start() end,
{ desc = "Open Lf in directory of open file" })
vim.keymap.set("n", "<Leader>eg", function() require("lf").start({ dir = "gwd" }) end,
{ desc = "Open Lf in git working directory" })
@ -37,7 +37,6 @@ lazy.nvim setup:
-- The path to start lf in.
-- "gwd" expands to the git working directory
-- "cwd" expands to the directory of the open file
dir = "", -- The path to start lf in.
},
dependencies = { "akinsho/toggleterm.nvim" },

View File

@ -95,6 +95,7 @@ function M.start(cfg)
cfg = vim.tbl_deep_extend("keep", cfg or {}, Config.data)
Lf:new(cfg or M.__conf):start()
end
return M

View File

@ -1,5 +1,3 @@
local api = vim.api
---@class Lf.Container
---@field data Lf.Config
---@field group integer Autocmd id
@ -18,10 +16,10 @@ local default = {
---Validate configuration values
---@param cfg Lf.Config existing configuration options
local function validate(cfg)
vim.validate({
assert(vim.validate({
default_cmd = { cfg.default_cmd, "s", false },
dir = { cfg.dir, "s", false },
})
}))
end
---Set a configuration passed as a function argument (not through `setup`)
@ -65,6 +63,6 @@ return setmetatable(Config, {
end,
---@diagnostic disable-next-line: unused-local
__newindex = function(self, key, val)
api.nvim_err_writeln(("do not set invalid config values: %s => %s"):format(key, val))
vim.echo(("do not set invalid config values: %s => %s"):format(key, val))
end,
})

View File

@ -6,7 +6,6 @@ local o = vim.o
local ok, terminal = pcall(require, "toggleterm")
if not ok then
api.nvim_err_writeln("toggleterm.nvim must be installed to use this program")
return
end
@ -82,16 +81,17 @@ function Lf:__open_in(path)
local gitdir = fn.system(("git -C %s rev-parse --show-toplevel"):format(fn.expand("%:p:h")))
if gitdir:match("^fatal:.*") then
api.nvim_out_write("Failed to get git directory")
return
require("util").error("Failed to find git working directory.")
path = nil
end
path = vim.trim(gitdir)
end
if type(path) == "string" and path ~= "cwd" then
path = fn.expand(path)
else
if path == nil then
path = fn.expand("%:p:h")
else
path = fn.expand(path)
end
local stat = uv.fs_stat(path)

View File

@ -1,4 +1,12 @@
---@meta
local api = vim.api
local M = {}
function M.error(msg)
api.nvim_echo({{msg, "WarningMsg"}}, true, {})
end
return M
---@alias Mode "n" | "i" | "?"
@ -61,7 +69,7 @@
---@class Lf.Config
---@field default_cmd? string Default `lf` command
---@field default_action? string Default action when `Lf` opens a file
---@field dir? Lf.directory Directory where `lf` starts ('gwd' is git-working-directory, ""/nil is CWD)
---@field dir? Lf.directory Directory where `lf` starts ('gwd' is git-working-directory, nil is CWD)
---@class Lf
---@field cfg Lf.Config Configuration options