[Perf] use print instead of raise error directly (#61)
parent
efeb8d89e2
commit
2572f664cc
|
@ -27,11 +27,12 @@ local function get_config(specify_extension)
|
||||||
local extension = specify_extension or get_extension()
|
local extension = specify_extension or get_extension()
|
||||||
|
|
||||||
if string_utils.is_str_empty(code) then
|
if string_utils.is_str_empty(code) then
|
||||||
error("Please select code which you want to take snapshot first")
|
error("No code is selected", 0)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if string_utils.is_str_empty(extension) then
|
if string_utils.is_str_empty(extension) then
|
||||||
error("Cannot detect current filetype")
|
error("Cannot detect current filetype", 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
return table_utils.merge({
|
return table_utils.merge({
|
||||||
|
@ -52,7 +53,10 @@ end
|
||||||
|
|
||||||
function main.save_snapshot(extension)
|
function main.save_snapshot(extension)
|
||||||
if string_utils.is_str_empty(static.config.save_path) then
|
if string_utils.is_str_empty(static.config.save_path) then
|
||||||
error("Cannot find save_path from config")
|
error(
|
||||||
|
"If you want to save snapshot in somewhere, you should config the save_path before, refer: https://github.com/mistricky/codesnap.nvim?tab=readme-ov-file#save-the-snapshot",
|
||||||
|
0
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
require("generator").save_snapshot(get_config(extension))
|
require("generator").save_snapshot(get_config(extension))
|
||||||
|
|
|
@ -1,10 +1,21 @@
|
||||||
local codesnap = require("codesnap")
|
local codesnap = require("codesnap")
|
||||||
|
|
||||||
|
-- The func param is a function that come from rust side, the function
|
||||||
|
-- may raise exception to user side, the run_generator_function is used to
|
||||||
|
-- handle these function and print it friendly
|
||||||
|
local function run_generator_function(func)
|
||||||
|
xpcall(func, function(err)
|
||||||
|
print(err)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
local function take_snapshot(take_snapshot_function)
|
local function take_snapshot(take_snapshot_function)
|
||||||
return function(detail)
|
return function(detail)
|
||||||
local args = detail.fargs
|
local args = detail.fargs
|
||||||
|
|
||||||
|
run_generator_function(function()
|
||||||
take_snapshot_function(args[1])
|
take_snapshot_function(args[1])
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue