Skip to content

Commit

Permalink
wip: working on state retrieval and placeholder logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oysandvik94 committed Nov 29, 2024
1 parent 0e28f3b commit a3b762c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/curl/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ M.execute_curl = function()
on_exit = function(_, exit_code, _)
if exit_code ~= 0 then
notify.error("Curl failed")
buffers.set_output_buffer_content(executed_from_win, vim.split(error, "\n"))
buffers.set_error_buffer_content(executed_from_win, error)
return
end

Expand Down
9 changes: 9 additions & 0 deletions lua/curl/buffers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,13 @@ M.set_output_buffer_content = function(executed_from_win, content)
vim.api.nvim_buf_set_lines(OUTPUT_BUF_ID, 0, -1, false, flattened)
end

---comment
---@param executed_from_win number
---@param content table
M.set_error_buffer_content = function(executed_from_win, content)
open_result_buffer(executed_from_win)

vim.api.nvim_buf_set_lines(OUTPUT_BUF_ID, 0, -1, false, { content })
end

return M
19 changes: 18 additions & 1 deletion lua/curl/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local M = {}

local config = require("curl.config")
local tokenizer = require("curl.tokenizer")
local state = require("curl.state")

local highlight_curl_command = function(start_pos, end_pos)
local ns_id = vim.api.nvim_create_namespace("curl_command_highlight")
Expand Down Expand Up @@ -145,8 +146,24 @@ M.parse_curl_command = function(cursor_pos, lines)

local selection = {}
for i = first_line, last_line do
local line_to_add = cleaned_lines[i]
if not is_commented(cleaned_lines[i]) then
table.insert(selection, cleaned_lines[i])
for placeholder in string.gmatch(cleaned_lines[i], "%${(.-)}") do
vim.print("found plcaeholder")
local main_key, sub_key = placeholder:match("([^%.]+)%.([^%.]+)")
if main_key and sub_key then
vim.print("found key: " .. main_key)
vim.print("found subkey: " .. sub_key)
local value = state.get_value(main_key)
if value and value[sub_key] then
vim.print("found value")
line_to_add = line_to_add:gsub("%${" .. placeholder .. "}", value[sub_key])
table.insert(selection, line_to_add)
end
end
end

table.insert(selection, line_to_add)
end
end

Expand Down

0 comments on commit a3b762c

Please sign in to comment.