Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve "no such file or directory" error in scratchpad #254

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/kulala/globals/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local M = {}

local plugin_tmp_dir = FS.get_plugin_tmp_dir()

M.VERSION = "4.0.0"
M.VERSION = "4.0.1"
M.UI_ID = "kulala://ui"
M.SCRATCHPAD_ID = "kulala://scratchpad"
M.HEADERS_FILE = plugin_tmp_dir .. "/headers.txt"
Expand Down
10 changes: 7 additions & 3 deletions lua/kulala/parser/scripts/engines/javascript/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@ local generate_one = function(script_type, is_external_file, script_data)
return nil, nil
end
local script_cwd
-- buf_dir is "kulala:" when the buffer is scratch buffer
-- in this case, use current working directory for script_cwd and base_dir
local buf_dir = FS.get_current_buffer_dir()

if is_external_file then
-- if script_data starts with ./ or ../, it is a relative path
if string.match(script_data, "^%./") or string.match(script_data, "^%../") then
local local_script_path = script_data:gsub("^%./", "")
script_data = FS.join_paths(FS.get_current_buffer_dir(), local_script_path)
local base_dir = buf_dir == "kulala:" and vim.loop.cwd() or buf_dir
script_data = FS.join_paths(base_dir, local_script_path)
end
script_cwd = FS.get_dir_by_filepath(script_data)
script_cwd = buf_dir == "kulala:" and vim.loop.cwd() or FS.get_dir_by_filepath(script_data)
userscript = FS.read_file(script_data)
else
script_cwd = FS.get_current_buffer_dir()
script_cwd = buf_dir == "kulala:" and vim.loop.cwd() or buf_dir
userscript = vim.fn.join(script_data, "\n")
end
base_file = base_file .. "\n" .. userscript
Expand Down