local params_raw = ...
local params = vim.json.decode(params_raw)
params.position.line = params.position.line + 1
local function navigate_to_file(file_uri)
local file_path = vim.uri_to_fname(file_uri)
if vim.fn.filereadable(file_path) == 0 then
return vim.json.encode({ err_msg = "File not found or not readable: " .. file_path })
end
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_valid(buf) then
local bufname = vim.api.nvim_buf_get_name(buf)
local buf_path = vim.fn.fnamemodify(bufname, ":p")
local target_path = vim.fn.fnamemodify(file_path, ":p")
if buf_path == target_path then
vim.cmd("buffer " .. buf)
return true
end
end
end
vim.cmd("edit " .. vim.fn.fnameescape(file_path))
return true
end
local result = navigate_to_file(params.textDocument.uri)
if type(result) == "string" then
return result
end
local current_buf = vim.api.nvim_get_current_buf()
vim.api.nvim_win_set_cursor(0, { params.position.line, params.position.character })
local current_bufname = vim.api.nvim_buf_get_name(current_buf)
local line = vim.api.nvim_get_current_line()
return vim.json.encode({
result = {
success = true,
buffer_name = current_bufname,
line = line,
},
})