Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions lua/copilot/lsp_binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ local function extract_file(copilot_server_info, local_server_zip_filepath)
end

vim.fn.delete(local_server_zip_filepath)
vim.fn.rename(
vim.fs.joinpath(copilot_server_info.absolute_path, copilot_server_info.extracted_filename),
copilot_server_info.absolute_filepath
)
if copilot_server_info.path ~= "js" then
vim.fn.rename(
vim.fs.joinpath(copilot_server_info.absolute_path, copilot_server_info.extracted_filename),
copilot_server_info.absolute_filepath
)
end

return true
end
Expand Down Expand Up @@ -223,12 +225,14 @@ function M.ensure_client_is_downloaded()
return false
end

if not set_permissions(copilot_server_info.absolute_filepath) then
logger.error("could not set permissions for copilot-language-server")
return false
if copilot_server_info.path ~= "js" then
if not set_permissions(copilot_server_info.absolute_filepath) then
logger.error("could not set permissions for copilot-language-server")
return false
end
delete_all_except(copilot_server_info.absolute_path, copilot_server_info.filename)
end

delete_all_except(copilot_server_info.absolute_path, copilot_server_info.filename)
logger.notify("copilot-language-server downloaded")
return true
end
Expand All @@ -250,6 +254,22 @@ local function is_arm()
return os_name == "aarch64" or string.sub(os_name, 1, 3) == "arm"
end

---@return boolean
local function is_musl()
local fh, err = assert(io.popen("ldd --version 2>&1", "r"))
if err then
return false -- we assume glibc
end

local ldd_output
if fh then
ldd_output = fh:read()
fh:close()
end

return string.sub(ldd_output, 1, 4) == "musl"
end

---@return copilot_server_info
function M.get_copilot_server_info()
if M.copilot_server_info then
Expand All @@ -265,8 +285,11 @@ function M.get_copilot_server_info()
if os == "Linux" then
if is_arm() then
path = "linux-arm64"
else
elseif not is_musl() then
path = "linux-x64"
else
-- Fallback to plain nodejs project
path = "js"
end
elseif os == "Darwin" then
if is_arm() then
Expand All @@ -284,6 +307,11 @@ function M.get_copilot_server_info()
logger.error("could not determine OS, please report this issue with the output of `uname -a`")
end

if path == "js" then
filename = "language-server.js"
extracted_filename = ""
end

M.copilot_server_info = {
path = path,
filename = filename,
Expand Down