Skip to content

Commit

Permalink
feat: add cache for command in paths
Browse files Browse the repository at this point in the history
  • Loading branch information
adalessa committed Dec 27, 2023
1 parent c5e0071 commit dd2abe7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lua/laravel/paths.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
local api = require "laravel.api"

local cache = {}

local M = {}

local function exec(cmd)
if not cache[cmd] then
cache[cmd] = api.php_execute(cmd)
end
return cache[cmd]
end

local function get_cwd()
return vim.fn.getcwd()
end

local function get_base_path()
return api.php_execute("base_path()").stdout[1]
return exec("base_path()").stdout[1]
end

local function map_path(path)
return path:gsub(get_base_path():gsub("-", "%%-"), get_cwd())
end

function M.resource_path(resource)
local path = api.php_execute(string.format("resource_path('%s')", resource)).stdout[1]
local path = exec(string.format("resource_path('%s')", resource)).stdout[1]

return map_path(path)
end
Expand Down

0 comments on commit dd2abe7

Please sign in to comment.