Skip to content

Commit

Permalink
add callback api to abstract apis
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Jul 28, 2024
1 parent 7e560f4 commit 111f821
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 77 deletions.
29 changes: 14 additions & 15 deletions lua/LspUI/declaration/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ M.deinit = function()
command.unregister_command(command_key)
end

M.run = function()
--- @param callback fun(Lsp_position_wrap?)?
M.run = function(callback)
if not config.options.declaration.enable then
lib_notify.Info("declaration is not enabled!")
return
Expand All @@ -63,13 +64,6 @@ M.run = function()

current_buffer = vim.uri_to_bufnr(current_item.uri)

clients = util.get_clients(current_buffer)

if clients == nil then
lib_notify.Warn("no client supports declaration!")
return
end

if current_item.range then
--- @type lsp.TextDocumentPositionParams
params = {
Expand All @@ -85,23 +79,28 @@ M.run = function()
return
end
else
clients = util.get_clients(current_buffer)
window = api.nvim_get_current_win()
params = util.make_params(window)
end

if clients == nil then
clients = util.get_clients(current_buffer)

if clients == nil then
if callback then
callback()
else
lib_notify.Warn("no client supports declaration!")
return
end

window = api.nvim_get_current_win()
params = util.make_params(window)
return
end

pos_abstract.go(
pos_abstract.method.declaration,
current_buffer,
window,
clients,
params
params,
callback
)
end

Expand Down
29 changes: 14 additions & 15 deletions lua/LspUI/definition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ M.deinit = function()
command.unregister_command(command_key)
end

M.run = function()
--- @param callback fun(Lsp_position_wrap?)?
M.run = function(callback)
if not config.options.definition.enable then
lib_notify.Info("definition is not enabled!")
return
Expand All @@ -63,13 +64,6 @@ M.run = function()

current_buffer = vim.uri_to_bufnr(current_item.uri)

clients = util.get_clients(current_buffer)

if clients == nil then
lib_notify.Warn("no client supports definition!")
return
end

if current_item.range then
--- @type lsp.TextDocumentPositionParams
params = {
Expand All @@ -85,23 +79,28 @@ M.run = function()
return
end
else
clients = util.get_clients(current_buffer)
window = api.nvim_get_current_win()
params = util.make_params(window)
end

if clients == nil then
clients = util.get_clients(current_buffer)

if clients == nil then
if callback then
callback()
else
lib_notify.Warn("no client supports definition!")
return
end

window = api.nvim_get_current_win()
params = util.make_params(window)
return
end

pos_abstract.go(
pos_abstract.method.definition,
current_buffer,
window,
clients,
params
params,
callback
)
end

Expand Down
29 changes: 14 additions & 15 deletions lua/LspUI/implementation/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ M.deinit = function()
command.unregister_command(command_key)
end

M.run = function()
--- @param callback fun(Lsp_position_wrap?)?
M.run = function(callback)
if not config.options.implementation.enable then
lib_notify.Info("implementation is not enabled!")
return
Expand All @@ -62,13 +63,6 @@ M.run = function()

current_buffer = vim.uri_to_bufnr(current_item.uri)

clients = util.get_clients(current_buffer)

if clients == nil then
lib_notify.Warn("no client supports implementation!")
return
end

if current_item.range then
--- @type lsp.TextDocumentPositionParams
params = {
Expand All @@ -84,23 +78,28 @@ M.run = function()
return
end
else
clients = util.get_clients(current_buffer)
window = api.nvim_get_current_win()
params = util.make_params(window)
end

if clients == nil then
clients = util.get_clients(current_buffer)

if clients == nil then
if callback then
callback()
else
lib_notify.Warn("no client supports implementation!")
return
end

window = api.nvim_get_current_win()
params = util.make_params(window)
return
end

pos_abstract.go(
pos_abstract.method.implementation,
current_buffer,
window,
clients,
params
params,
callback
)
end

Expand Down
13 changes: 11 additions & 2 deletions lua/LspUI/pos_abstract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,8 @@ end
--- @param clients vim.lsp.Client[]
--- @param params table
--- @param new_method { method: string, name: string, fold: boolean }
M.go = function(new_method, buffer_id, window_id, clients, params)
--- @param callback fun(Lsp_position_wrap?)?
M.go = function(new_method, buffer_id, window_id, clients, params, callback)
-- set method
method = new_method

Expand All @@ -1222,10 +1223,18 @@ M.go = function(new_method, buffer_id, window_id, clients, params)
end

if not data then
lib_notify.Info(string.format("no valid %s", method.name))
if callback then
callback()
else
lib_notify.Info(string.format("no valid %s", method.name))
end
return
end

if callback then
callback(data)
end

M.datas(data)

if window_id then
Expand Down
29 changes: 14 additions & 15 deletions lua/LspUI/reference/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ M.deinit = function()
command.unregister_command(command_key)
end

M.run = function()
--- @param callback fun(Lsp_position_wrap?)?
M.run = function(callback)
if not config.options.reference.enable then
lib_notify.Info("reference is not enabled!")
return
Expand All @@ -62,13 +63,6 @@ M.run = function()

current_buffer = vim.uri_to_bufnr(current_item.uri)

clients = util.get_clients(current_buffer)

if clients == nil then
lib_notify.Warn("no client supports reference!")
return
end

if current_item.range then
--- @type lsp.TextDocumentPositionParams
params = {
Expand All @@ -87,23 +81,28 @@ M.run = function()
return
end
else
clients = util.get_clients(current_buffer)
window = api.nvim_get_current_win()
params = util.make_params(window)
end

if clients == nil then
clients = util.get_clients(current_buffer)

if clients == nil then
if callback then
callback()
else
lib_notify.Warn("no client supports reference!")
return
end

window = api.nvim_get_current_win()
params = util.make_params(window)
return
end

pos_abstract.go(
pos_abstract.method.reference,
current_buffer,
window,
clients,
params
params,
callback
)
end

Expand Down
29 changes: 14 additions & 15 deletions lua/LspUI/type_definition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ M.deinit = function()
command.unregister_command(command_key)
end

M.run = function()
--- @param callback fun(Lsp_position_wrap?)?
M.run = function(callback)
if not config.options.type_definition.enable then
lib_notify.Info("type_definition is not enabled!")
return
Expand All @@ -63,13 +64,6 @@ M.run = function()

current_buffer = vim.uri_to_bufnr(current_item.uri)

clients = util.get_clients(current_buffer)

if clients == nil then
lib_notify.Warn("no client supports type_definition!")
return
end

if current_item.range then
--- @type lsp.TextDocumentPositionParams
params = {
Expand All @@ -85,23 +79,28 @@ M.run = function()
return
end
else
clients = util.get_clients(current_buffer)
window = api.nvim_get_current_win()
params = util.make_params(window)
end

if clients == nil then
clients = util.get_clients(current_buffer)

if clients == nil then
if callback then
callback()
else
lib_notify.Warn("no client supports type_definition!")
return
end

window = api.nvim_get_current_win()
params = util.make_params(window)
return
end

pos_abstract.go(
pos_abstract.method.type_definition,
current_buffer,
window,
clients,
params
params,
callback
)
end

Expand Down

0 comments on commit 111f821

Please sign in to comment.