refactor: 重写了类的逻辑, 引入了部分bug待解决
This commit is contained in:
@ -41,16 +41,16 @@ return function(word)
|
||||
callback = function(str)
|
||||
local ok, res = pcall(vim.json.decode, str)
|
||||
if ok and res and res.trans_result then
|
||||
result.value = {
|
||||
word = word,
|
||||
result[1] = {
|
||||
title = { word = word },
|
||||
[isEn and 'translation' or 'definition'] = res.trans_result[1].dst,
|
||||
}
|
||||
|
||||
if result.callback then
|
||||
result.callback(result.value)
|
||||
result.callback(result[1])
|
||||
end
|
||||
else
|
||||
result.value = false
|
||||
result[1] = false
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -16,8 +16,9 @@ vim.api.nvim_create_autocmd('VimLeavePre', {
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
return function(word)
|
||||
local res = dict:select('stardict', {
|
||||
local res = (dict:select('stardict', {
|
||||
where = {
|
||||
word = word,
|
||||
},
|
||||
@ -33,6 +34,20 @@ return function(word)
|
||||
'exchange',
|
||||
},
|
||||
limit = 1,
|
||||
})
|
||||
return res[1]
|
||||
}))[1]
|
||||
|
||||
if res then
|
||||
res.title = {
|
||||
word = res.word,
|
||||
oxford = res.oxford,
|
||||
collins = res.collins,
|
||||
phonetic = res.phonetic,
|
||||
}
|
||||
res.word = nil
|
||||
res.oxford = nil
|
||||
res.collins = nil
|
||||
res.phonetic = nil
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
Reference in New Issue
Block a user