-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hello, I have found your add on, and I must say great work; however, I am perplexed. I looke through the snippents and the posts on your repository and it works fine for some people (I did see a few people expressing dipleasure but no solution attatched). I am not a competent programmer especially in lua, so I am just wondering if anyone has any idea why it doesn't work.
I had placed the code in AI and this is what it had to say about it. I don't know much about lua so I figured it would give me a good understanding of what's going on.
"""The provided Lua code for the Lite-XL build plugin has several issues that need addressing:
**Typo in StatusView Alignment:**
Issue: The alignment key is misspelled as alignemnt in the status view item, causing incorrect alignment.
Fix: Correct the spelling to alignment.
**Incorrect Argument Splitting:**
Issue: split_argument_string uses a simple space split, failing to handle quoted arguments with spaces.
Fix: Replace split(" ", ...) with the argument_string_to_table function to properly parse arguments.
**Unquoted Paths on Windows:**
Issue: Command paths with spaces aren't quoted when using os.execute on Windows, leading to errors.
Fix: Enclose paths in quotes when constructing the command string.
**Incorrect Scrollable Height Calculation:**
Issue: get_scrollable_size adds an extra item height, causing scrollbar issues.
Fix: Remove + 1 to correctly calculate the height based on the number of messages.
**File Handling in save_state:**
Issue: Missing error checking and file closing after writing the state.
Fix: Use proper error handling and close the file handle after writing.
**Project Directory Check in jump_to_file:**
Issue: Only checks the first project directory, potentially missing files in others.
Fix: Iterate over all core.project_directories and check each one.
**Handling ANSI Reset Codes:**
Issue: Failing to reset text color after ANSI reset codes (e.g., \x1b[0m).
Fix: Update the ANSI parsing logic to handle reset codes and revert to the default color.
Step-by-Step Fixes:
**Correct Alignment Typo:**
core.status_view:add_item({
predicate = function() return build.current_target and build.targets[build.current_target] end,
name = "build:target",
alignment = StatusView.Item.RIGHT, -- Corrected spelling
-- ... rest of the code
})
**Fix Argument Splitting:**
function build.split_argument_string(arguments)
if type(arguments) == "string" then
return argument_string_to_table(arguments) -- Use proper parser
end
return arguments
end
Quote Paths on Windows:
lua
Copy
-- In build.get_command for Windows:
if PLATFORM == "Windows" then
command = { 'cmd', '/c', ('"%s"'):format(table.concat(command, ' ')) } -- Ensure quotes
end
**Correct Scrollable Size:**
function BuildMessageView:get_scrollable_size()
return #self.messages * self:get_item_height() -- Removed +1
end
**Handle File Saving Properly:**
save_state = function()
local file = io.open(filename, "wb")
if file then
file:write("return " .. common.serialize(build.state))
file:flush()
file:close()
else
core.error("Failed to save build state")
end
end
**Check All Project Directories:**
local function jump_to_file(file, line, col)
file = system.absolute_path(file)
for _, dir in ipairs(core.project_directories) do
if common.path_belongs_to(file, dir) then
-- Open the file
break
end
end
end
**Handle ANSI Reset Codes:**
-- In BuildMessageView:draw()
local default_color = style.text
local current_color = default_color
-- ...
if v:find("\x1b") then
local x = ox + style.padding.x
local remaining = v
while #remaining > 0 do
local s, e, code = remaining:find("\x1b%[(%d+;)?(%d+)m")
if not s then break end
-- Handle reset code (0)
local color_code = tonumber(code)
if color_code == 0 then
current_color = default_color
else
current_color = ansi_colors[color_code] or default_color
end
-- Draw text before the code
local text = remaining:sub(1, s-1)
x = common.draw_text(style.code_font, current_color, text, "left", x, oy + yoffset, 0, h)
remaining = remaining:sub(e + 1)
end
-- Draw remaining text
common.draw_text(style.code_font, current_color, remaining, "left", x, oy + yoffset, 0, h)
These fixes address the main issues, improving argument handling, path quoting, error resilience, and user interface correctness."""
I don't know how much od this makes sense but please have a look into the issure for me, I beg!

