generated from nvimdev/nvim-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent
b1ba767
commit 1137aec
Showing
17 changed files
with
1,548 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"diagnostics.globals": ["describe", "it"], | ||
"diagnostics.disable": ["undefined-field"] | ||
"diagnostics.globals": ["describe", "it", "vim"], | ||
"diagnostics.disable": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Get all todos | ||
GET https://wattpm-demo.fly.dev/express/api/todo | ||
|
||
HTTP 200 | ||
[Asserts] | ||
jsonpath "$.status" == "success" | ||
header "server" contains "Fly" | ||
|
||
|
||
# Throw error if text is not provided | ||
POST https://wattpm-demo.fly.dev/express/api/todo | ||
Content-Type: application/json | ||
{} | ||
HTTP 400 | ||
[Asserts] | ||
jsonpath "$.status" == "error" | ||
jsonpath "$.message" == "Text is required" | ||
|
||
# Create a new todo | ||
POST https://wattpm-demo.fly.dev/express/api/todo | ||
Content-Type: application/json | ||
{ | ||
"text": "Call Express API from hurl.nvim at {{now}}" | ||
} | ||
HTTP 201 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
local M = {} | ||
|
||
-- Add virtual text for Hurl entries by finding HTTP verbs | ||
function M.add_virtual_text_for_hurl_entries() | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) | ||
|
||
-- Create a dedicated namespace for Hurl entry markers | ||
local ns_id = vim.api.nvim_create_namespace('hurl_entries') | ||
|
||
-- Clear existing virtual text before adding new ones | ||
vim.api.nvim_buf_clear_namespace(bufnr, ns_id, 0, -1) | ||
|
||
-- Define all supported HTTP methods | ||
local http_methods = { | ||
'GET', | ||
'POST', | ||
'PUT', | ||
'DELETE', | ||
'PATCH', | ||
'HEAD', | ||
'OPTIONS', | ||
} | ||
|
||
local entry_number = 1 | ||
for i, line in ipairs(lines) do | ||
-- Match any HTTP method, ignoring preceding whitespace and comments | ||
local method = line:match('^%s*#?%s*([A-Z]+)') | ||
if method and vim.tbl_contains(http_methods, method) then | ||
vim.api.nvim_buf_set_virtual_text(bufnr, ns_id, i - 1, { | ||
{ 'Entry #' .. entry_number, 'Comment' }, | ||
}, {}) | ||
entry_number = entry_number + 1 | ||
end | ||
end | ||
end | ||
|
||
-- Setup function to attach buffer autocmd | ||
function M.setup() | ||
local group = vim.api.nvim_create_augroup('HurlEntryMarkers', { clear = true }) | ||
|
||
-- Handle buffer events | ||
vim.api.nvim_create_autocmd({ | ||
'BufEnter', | ||
'TextChanged', | ||
'InsertLeave', | ||
}, { | ||
group = group, | ||
pattern = '*.hurl', | ||
callback = function() | ||
M.add_virtual_text_for_hurl_entries() | ||
end, | ||
}) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,60 @@ | ||
local utils = require('hurl.utils') | ||
local M = {} | ||
|
||
--- Show the last request in the history | ||
---@param response table | ||
M.show = function(response) | ||
local container = require('hurl.' .. _HURL_GLOBAL_CONFIG.mode) | ||
if not response.headers then | ||
-- Do not show anything if there is no response | ||
return | ||
-- Store the last 10 responses | ||
local response_history = {} | ||
local max_history_size = 10 | ||
|
||
-- Add a response to the history | ||
local function add_to_history(response) | ||
table.insert(response_history, 1, response) | ||
if #response_history > max_history_size then | ||
table.remove(response_history) | ||
end | ||
end | ||
|
||
local content_type = response.headers['content-type'] | ||
or response.headers['Content-Type'] | ||
or response.headers['Content-type'] | ||
or 'unknown' | ||
-- Show the last response | ||
function M.show_last_response() | ||
if #response_history == 0 then | ||
utils.notify('No response history available', vim.log.levels.INFO) | ||
return | ||
end | ||
|
||
utils.log_info('Detected content type: ' .. content_type) | ||
if response.headers['content-length'] == '0' then | ||
utils.log_info('hurl: empty response') | ||
utils.notify('hurl: empty response', vim.log.levels.INFO) | ||
local last_response = response_history[1] | ||
local ok, display = pcall(require, 'hurl.' .. (_HURL_GLOBAL_CONFIG.mode or 'split')) | ||
if not ok then | ||
utils.notify('Failed to load display module: ' .. display, vim.log.levels.ERROR) | ||
return | ||
end | ||
if utils.is_json_response(content_type) then | ||
container.show(response, 'json') | ||
|
||
display.show(last_response, last_response.display_type or 'text') | ||
end | ||
|
||
-- Function to be called after each successful request | ||
function M.update_history(response) | ||
-- Ensure response_time is a number | ||
response.response_time = tonumber(response.response_time) or '-' | ||
|
||
-- Determine the content type and set display_type | ||
local content_type = response.headers['Content-Type'] | ||
or response.headers['content-type'] | ||
or 'text/plain' | ||
|
||
if content_type:find('json') then | ||
response.display_type = 'json' | ||
elseif content_type:find('html') then | ||
response.display_type = 'html' | ||
elseif content_type:find('xml') then | ||
response.display_type = 'xml' | ||
else | ||
if utils.is_html_response(content_type) then | ||
container.show(response, 'html') | ||
else | ||
if utils.is_xml_response(content_type) then | ||
container.show(response, 'xml') | ||
else | ||
container.show(response, 'text') | ||
end | ||
end | ||
response.display_type = 'text' | ||
end | ||
|
||
add_to_history(response) | ||
end | ||
|
||
function M.get_last_response() | ||
return response_history[1] | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.