jellydn / hurl.nvim

Hurl.nvim is a Neovim plugin designed to run HTTP requests directly from `.hurl` files. Elevate your API development workflow by executing and viewing responses without leaving your editor.
https://gyazo.com/19492e8b5366cec3f22d5fd97a63f37a
MIT License
129 stars 14 forks source link

Nui popup is not working well #170

Closed realtica closed 2 days ago

realtica commented 1 month ago

Details: Nvim 0.10.0

Hello,

For some info like Global variables the popup works well but for results, only works in split mode.. help me please.

image

sweep-ai[bot] commented 1 month ago

🚀 Here's the PR! #171

💎 Sweep Pro: You have unlimited Sweep issues

Actions

Step 1: 🔎 Searching

(Click to expand) Here are the code search results. I'm now analyzing these search results to write the PR. https://github.com/jellydn/hurl.nvim/blob/d5cce0bcb831d5543485bbb6fb7fc50e5d8a752d/lua/hurl/popup.lua#L1-L167 https://github.com/jellydn/hurl.nvim/blob/d5cce0bcb831d5543485bbb6fb7fc50e5d8a752d/lua/hurl/utils.lua#L1-L280 https://github.com/jellydn/hurl.nvim/blob/d5cce0bcb831d5543485bbb6fb7fc50e5d8a752d/README.md#L1-L374 https://github.com/jellydn/hurl.nvim/blob/d5cce0bcb831d5543485bbb6fb7fc50e5d8a752d/lua/hurl/split.lua#L1-L84

Step 2: ⌨️ Coding

I'm going to follow the following steps to help you solve the GitHub issue:

  1. Investigate why the popup mode is not working properly for displaying API response results.
  2. Fix the issue preventing API responses from being displayed in the popup.
  3. Verify that API responses are displayed properly in the popup after the fix.

Here are the changes we decided to make. I'm done making edits and now I'm just validating the changes using a linter to catch any mistakes like syntax errors or undefined variables:

lua/hurl/popup.lua

Modify the logic for displaying the response headers in the `M.show` function:
--- 
+++ 
@@ -1,10 +1,5 @@
   -- Add headers to the top
   local headers_table = utils.render_header_table(data.headers)
-  -- Hide header block if empty headers
-  if headers_table.line == 0 then
-    vim.api.nvim_win_close(popups.top.winid, true)
-  else
-    if headers_table.line > 0 then
-      vim.api.nvim_buf_set_lines(popups.top.bufnr, 0, 1, false, headers_table.headers)
-    end
+  if headers_table.line > 0 then
+    vim.api.nvim_buf_set_lines(popups.top.bufnr, 0, 1, false, headers_table.headers)
   end

lua/hurl/popup.lua

Modify the logic for displaying the response body in the `M.show` function:
--- 
+++ 
@@ -1,11 +1,8 @@
   local content = utils.format(data.body, type)
-  if not content then
-    utils.log_info('No content')
-    return
-  end
+  if content then
+    -- Add content to the bottom
+    vim.api.nvim_buf_set_lines(popups.bottom.bufnr, 0, -1, false, content)

-  -- Add content to the bottom
-  vim.api.nvim_buf_set_lines(popups.bottom.bufnr, 0, -1, false, content)
-
-  -- Set content to highlight, refer https://github.com/MunifTanjim/nui.nvim/issues/76#issuecomment-1001358770
-  vim.api.nvim_buf_set_option(popups.bottom.bufnr, 'filetype', type)
+    -- Set content to highlight
+    vim.api.nvim_buf_set_option(popups.bottom.bufnr, 'filetype', type)
+  end

Step 3: 🔄️ Validating

Your changes have been successfully made to the branch sweep/nui_popup_is_not_working_well. I have validated these changes using a syntax checker and a linter.


[!TIP] To recreate the pull request, edit the issue title or description.

This is an automated message generated by Sweep AI.

jellydn commented 1 month ago

Thanks @realtica I will take a look on this issue sometime this week.

jellydn commented 1 month ago

Hi @realtica Could you help me to reproduce this issue? I tried but it's fine on my end.

jellydn commented 2 days ago

Fixed with my latest commit.