Skip to content

Commit e62babc

Browse files
authored
fix: make ffi/LuaJIT an optional dependency (#1111)
closes #1087
1 parent 71e36bb commit e62babc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lua/neo-tree/utils.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
local vim = vim
22
local log = require("neo-tree.log")
33
local bit = require("bit")
4-
local ffi = require("ffi")
4+
local ffi_available, ffi = pcall(require, "ffi")
55

66
local FILE_ATTRIBUTE_HIDDEN = 0x2
77

8-
ffi.cdef([[
9-
int GetFileAttributesA(const char *path);
10-
]])
8+
if ffi_available then
9+
ffi.cdef([[
10+
int GetFileAttributesA(const char *path);
11+
]])
12+
end
1113

1214
-- Backwards compatibility
1315
table.pack = table.pack or function(...)
@@ -923,10 +925,11 @@ end
923925
---@param path string
924926
---@return boolean
925927
function M.is_hidden(path)
926-
if not M.is_windows then
928+
if ffi_available and M.is_windows then
929+
return bit.band(ffi.C.GetFileAttributesA(path), FILE_ATTRIBUTE_HIDDEN) ~= 0
930+
else
927931
return false
928932
end
929-
return bit.band(ffi.C.GetFileAttributesA(path), FILE_ATTRIBUTE_HIDDEN) ~= 0
930933
end
931934

932935
---Returns a new list that is the result of dedeuplicating a list.

0 commit comments

Comments
 (0)