Skip to content

Commit 14bf786

Browse files
authored
perf: use vim.loop.os_uname() for is_arm (#513)
1 parent f7e2dc7 commit 14bf786

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

lua/copilot/lsp/binary.lua

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,8 @@ function M.init()
235235
end
236236

237237
---@return boolean
238-
local function is_arm()
239-
local fh, err = assert(io.popen("uname -m 2>/dev/null", "r"))
240-
if err then
241-
logger.error("could not determine if cpu is arm, assuming it is not: " .. err)
242-
return false -- we assume not arm
243-
end
244-
245-
local os_name
246-
if fh then
247-
os_name = fh:read()
248-
fh:close()
249-
end
250-
251-
return os_name == "aarch64" or string.sub(os_name, 1, 3) == "arm"
238+
local function is_arm(machine)
239+
return machine == "aarch64" or machine:sub(1, 3) == "arm"
252240
end
253241

254242
---@return boolean
@@ -298,9 +286,10 @@ function M.get_copilot_server_info()
298286
local path = ""
299287
local extracted_filename = "copilot-language-server"
300288
local filename = "copilot-language-server-" .. copilot_version
301-
local os = vim.loop.os_uname().sysname
289+
local uname = vim.loop.os_uname()
290+
local os = uname.sysname
302291
if os == "Linux" then
303-
if is_arm() then
292+
if is_arm(uname.machine) then
304293
path = "linux-arm64"
305294
elseif not is_musl() then
306295
path = "linux-x64"
@@ -309,7 +298,7 @@ function M.get_copilot_server_info()
309298
path = "js"
310299
end
311300
elseif os == "Darwin" then
312-
if is_arm() then
301+
if is_arm(uname.machine) then
313302
path = "darwin-arm64"
314303
else
315304
path = "darwin-x64"

0 commit comments

Comments
 (0)