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

fix(hurl): fold not work if set foldexpr to `vim.treesitter.foldexpr()` #162

Closed wenjinnn closed 1 month ago

wenjinnn commented 2 months ago

Set filetype to hurl-nvim by default make vim.treesitter.foldexpr() not work, causes zc zo to fail in response buffer, it happens only on nvim 0.10. this commit check if edgy.nvim exists and then set filetype to hurl-nvim, otherwise just set filetype to input param type.

Also I was wondering if there have any way to set buf name safety with nui.nvim?

I tried to use vim.api.nvim_buf_set_name(split.bufnr, 'hurl-response') at split.show, but got a error when run a request second time, it seems like bufnr got wrong value or something. I would love to make a PR if I can fix it, right now the split result window have no name, maybe add a name will be nice.

Summary by CodeRabbit

codesandbox[bot] commented 2 months ago

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders
Open Preview

changeset-bot[bot] commented 2 months ago

⚠️ No Changeset found

Latest commit: f2fb792d781cfd8328136f5f73a710faa5c179c7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/wenjinnn/hurl.nvim/new/main?filename=.changeset/cuddly-ducks-double.md&value=---%0A%22%40fake-scope%2Ffake-pkg%22%3A%20patch%0A---%0A%0Afix(hurl)%3A%20fold%20not%20work%20if%20set%20foldexpr%20to%20%60vim.treesitter.foldexpr()%60%0A)

ellipsis-dev[bot] commented 2 months ago

Your free trial has expired. To keep using Ellipsis, sign up at https://app.ellipsis.dev for $20/seat/month or reach us at help@ellipsis.dev

coderabbitai[bot] commented 2 months ago

Walkthrough

The recent changes in the lua/hurl/split.lua file focus on optimizing the buffer options setup within the Split and M.show functions. The buf_options declaration has been moved from the Split function to a conditional block in M.show, which now also includes logic to conditionally set the filetype using edgy.nvim if available, and then based on the type parameter.

Changes

File Path Change Summary
lua/hurl/split.lua Removed initial buf_options declaration from Split function. Added conditional block in M.show to set filetype using edgy.nvim if available, and then based on the type parameter.

🐰✨ In code we trust, through changes we grow,
Buffers now smarter, with options in tow.
Edgy and nimble, the filetypes align,
Lua scripts dancing, in harmony they shine.
Hurl’s split evolves, with logic so fine,
A toast to the coders, on this bright design! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to full the review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
sweep-ai[bot] commented 2 months ago

Sweep: PR Review

Authors of pull request: @wenjinnn

lua/hurl/split.lua

Made the setting of the 'filetype' buffer option conditional based on the availability of 'edgy.nvim' and adjusted the timing of setting the filetype to the provided type parameter.


jellydn commented 2 months ago

Hi @wenjinnn

Also I was wondering if there have any way to set buf name safety with nui.nvim?

That's exactly what the author answered as below. The usage is correct.

buf_options = { filetype = 'hurl-nvim' },

https://github.com/MunifTanjim/nui.nvim/issues/76#issuecomment-1001358770

wenjinnn commented 2 months ago

Hi @wenjinnn

Also I was wondering if there have any way to set buf name safety with nui.nvim?

That's exactly what the author answered as below. The usage is correct.

buf_options = { filetype = 'hurl-nvim' },

MunifTanjim/nui.nvim#76 (comment)

Thanks for reply @jellydn . I think this issue you refers to just explain this PR. set filetype to hurl-nvim make treesitter parser can't identify which language are in the response buffer (I guess we just can't have filetype 'hurl-nvim' and get treesitter highlight together), the reason that we got treesitter highlight from response buffer is we set filetype to particular language later in show function:

  -- Set content to highlight, refer https://github.com/MunifTanjim/nui.nvim/issues/76#issuecomment-1001358770
  vim.api.nvim_buf_set_option(split.bufnr, 'filetype', type)

Although we got treesitter highlight, but we can't get foldlevel calculate by vim.treesitter.foldexpr(), cause the foldlevel calculate only happens at first filetype setup (Not 100% sure, but this is the result of my test), my configuration was like:

vim.opt.foldmethod = "expr"
vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'

Also I was wondering if there have any way to set buf name safety with nui.nvim?

And this is another problem I want to improve yet, just discuss in here. right now the response buffer have no name, it shows like: image I think give a buffer name like 'hurl-response' would be nice, please feel free to correct me.

jellydn commented 2 months ago

I think give a buffer name like 'hurl-response' would be nice, please feel free to correct me.

That sounds good @wenjinnn Let's do it. Thanks.

jellydn commented 1 month ago

Thanks @wenjinnn LGTM!

jellydn commented 1 month ago

One thing I noticed on this PR @wenjinnn the edgy integration won't work anymore.

        { title = "hurl.nvim", ft = "hurl-nvim", size = { width = 0.4 } },
wenjinnn commented 1 month ago

One thing I noticed on this PR @wenjinnn the edgy integration won't work anymore.

        { title = "hurl.nvim", ft = "hurl-nvim", size = { width = 0.4 } },

After we have buffer name, this setting could work with edgy.nvim, just a little wordy:

      left = {
        {
          ft = "json",
          title = "hurl-response",
        },
        {
          ft = "html",
          title = "hurl-response",
        },
        {
          ft = "text",
          title = "hurl-response",
        },
      },

I can update the README, and maybe remove all these lines at https://github.com/jellydn/hurl.nvim/blob/a185094058f75eb7f32ebf69f2dcc3361628290c/lua/hurl/split.lua#L22-L27 , since it not work anymore.

jellydn commented 1 month ago

One thing I noticed on this PR @wenjinnn the edgy integration won't work anymore.

        { title = "hurl.nvim", ft = "hurl-nvim", size = { width = 0.4 } },

After we have buffer name, this setting could work with edgy.nvim, just a little wordy:

      left = {
        {
          ft = "json",
          title = "hurl-response",
        },
        {
          ft = "html",
          title = "hurl-response",
        },
        {
          ft = "text",
          title = "hurl-response",
        },
      },

I can update the README, and maybe remove all these lines at

https://github.com/jellydn/hurl.nvim/blob/a185094058f75eb7f32ebf69f2dcc3361628290c/lua/hurl/split.lua#L22-L27

, since it not work anymore.

Well, that won't work as well. The ft will move all json/html/text files to the left. Do you try with https://github.com/folke/edgy.nvim by above setting? @wenjinnn

jellydn commented 1 month ago

FYI - Fixed with my commit, here is the working config https://github.com/jellydn/lazy-nvim-ide/blob/main/lua/plugins/extras/hurl.lua

image
wenjinnn commented 1 month ago

One thing I noticed on this PR @wenjinnn the edgy integration won't work anymore.

        { title = "hurl.nvim", ft = "hurl-nvim", size = { width = 0.4 } },

After we have buffer name, this setting could work with edgy.nvim, just a little wordy:

      left = {
        {
          ft = "json",
          title = "hurl-response",
        },
        {
          ft = "html",
          title = "hurl-response",
        },
        {
          ft = "text",
          title = "hurl-response",
        },
      },

I can update the README, and maybe remove all these lines at https://github.com/jellydn/hurl.nvim/blob/a185094058f75eb7f32ebf69f2dcc3361628290c/lua/hurl/split.lua#L22-L27

, since it not work anymore.

Well, that won't work as well. The ft will move all json/html/text files to the left. Do you try with https://github.com/folke/edgy.nvim by above setting? @wenjinnn

Oh sorry for that, I just try it once with edgy.nvim, cuz I don't really use it daily. I have misunderstood the title setting, fortunately we can still achieve this with filter, I do some more test with it, now this should work well:

        {
          ft = "json",
          filter = function(buf)
            return vim.fn.bufname(buf) == "hurl-response"
          end,
        },
        {
          ft = "html",
          filter = function(buf)
            return vim.fn.bufname(buf) == "hurl-response"
          end,
        },
        {
          ft = "text",
          filter = function(buf)
            return vim.fn.bufname(buf) == "hurl-response"
          end,
        },
wenjinnn commented 1 month ago

FYI - Fixed with my commit, here is the working config https://github.com/jellydn/lazy-nvim-ide/blob/main/lua/plugins/extras/hurl.lua image

This made fold level computing failed again. but I find a way to compatible with edgy.nvim and the treesitter foldexpr, I'll open another PR.