Skip to content

Commit e547e0d

Browse files
committed
Fix: Use built in functions
1 parent 3022b5c commit e547e0d

1 file changed

Lines changed: 5 additions & 19 deletions

File tree

lua/cmake-tools/scanner.lua

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ local function execute_command(cmd)
1717
return true, 0, result
1818
end
1919

20-
local function file_exists(path)
21-
if path == nil then
22-
vim.notify("Path is empty", vim.log.levels.ERROR)
23-
return
24-
end
25-
local file = io.open(path, "r")
26-
if file then
27-
file:close()
28-
return true
29-
else
30-
return false
31-
end
32-
end
33-
3420
local function split_path(path_env)
3521
local paths = {}
3622
local sep = package.config:sub(1, 1) == "\\" and ";" or ":"
@@ -71,7 +57,7 @@ local function find_compiler_pair(dir, c_compiler)
7157
return nil
7258
end
7359
local cxx_path = dir .. "/" .. cxx_name
74-
if file_exists(cxx_path) then
60+
if vim.fn.filereadable(cxx_path) then
7561
return cxx_path
7662
end
7763
return nil
@@ -82,15 +68,15 @@ local function find_linker_pair(dir, linker_name)
8268
return nil
8369
end
8470
local linker_path = dir .. "/" .. linker_name
85-
if file_exists(linker_path) then
71+
if vim.fn.filereadable(linker_path) then
8672
return linker_path
8773
end
8874
return nil
8975
end
9076

9177
local function get_toolchain_file()
9278
local toolchainFile = os.getenv("CMAKE_TOOLCHAIN_FILE")
93-
if toolchainFile and file_exists(toolchainFile) then
79+
if toolchainFile and vim.fn.filereadable(toolchainFile) then
9480
return toolchainFile
9581
end
9682
return nil
@@ -139,7 +125,7 @@ function scanner.scan_for_kits()
139125
end
140126
local toolchainFile = get_toolchain_file()
141127
local gcc_path = dir .. "/gcc"
142-
if file_exists(gcc_path) then
128+
if vim.fn.filereadable(gcc_path) then
143129
local gcc_version = get_gcc_version(gcc_path)
144130
local gxx_path = find_compiler_pair(dir, gcc_path)
145131
if gxx_path then
@@ -157,7 +143,7 @@ function scanner.scan_for_kits()
157143
end
158144

159145
local clang_path = dir .. "/clang"
160-
if file_exists(clang_path) then
146+
if vim.fn.filereadable(clang_path) then
161147
local clang_version = get_clang_version(clang_path)
162148
local clangxx_path = find_compiler_pair(dir, clang_path)
163149
if clangxx_path then

0 commit comments

Comments
 (0)