Skip to content

Commit

Permalink
fix: fix win32 detection (#33)
Browse files Browse the repository at this point in the history
* Introduce a util function to check for win32 in vim.fn correctly
* Replace all checks for win32 with the new function
  • Loading branch information
ww-daniel-mora committed Mar 22, 2023
1 parent 8029bdc commit 3a1f45b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lua/codeium/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local io = require("codeium.io")
local log = require("codeium.log")
local update = require("codeium.update")
local notify = require("codeium.notify")
local util = require("codeium.util")
local api_key = nil

local function find_port(manager_dir, start_time)
Expand Down Expand Up @@ -178,7 +179,7 @@ function Server:new()
local manager_dir = config.manager_path
if not manager_dir then
manager_dir = io.tempdir("codeium/manager")
if vim.fn.has("win32") == 1 then
if util.has_win32() then
vim.fn.mkdir(manager_dir, "p")
end
end
Expand Down
7 changes: 4 additions & 3 deletions lua/codeium/io.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local Path = require("plenary.path")
local Job = require("plenary.job")
local curl = require("plenary.curl")
local config = require("codeium.config")
local util = require("codeium.util")
local default_mod = 438 -- 666

local M = {}
Expand Down Expand Up @@ -204,7 +205,7 @@ function M.get_system_info()
return system_info_cache
end

if vim.fn.has("win32") == 1 then
if util.has_win32() then
system_info_cache = {
os = "windows",
arch = "x86_64",
Expand Down Expand Up @@ -300,7 +301,7 @@ end

function M.generate_uuid()
local uuid
if vim.fn.has("win32") then
if util.has_win32() then
uuid = string.gsub("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", "[xy]", function(c)
return string.format("%x", (c == "x") and (math.random(16) - 1) or (((math.random(16) - 1) % 4) + 8))
end)
Expand All @@ -318,7 +319,7 @@ function M.generate_uuid()
end

function M.gunzip(path, callback)
if vim.fn.has("win32") then
if util.has_win32() then
M.job({
"powershell.exe",
"-noprofile",
Expand Down
4 changes: 4 additions & 0 deletions lua/codeium/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ function M.get_newline(bufnr)
return enums.line_endings[vim.api.nvim_buf_get_option(bufnr, "fileformat")] or "\n"
end

function M.has_win32()
return vim.call("exists", "*win32") == 1
end

return M

0 comments on commit 3a1f45b

Please sign in to comment.