Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand request data #1227

Open
lbgws2 opened this issue Aug 25, 2024 · 4 comments
Open

expand request data #1227

lbgws2 opened this issue Aug 25, 2024 · 4 comments

Comments

@lbgws2
Copy link

lbgws2 commented Aug 25, 2024

Hello everyone, I am a newcomer who has just started working with luasnip. I would like to use luasnip to complete the following functions

This is an open request address, request_test

I want to request data through Python code or curl to generate a list of titles. After return, I can select a title to complete it through nvim-cmp. I have reviewed the documentation and referenced other people's code, but I still don't know how to implement it

If possible, could you provide an example to help me understand how it was implemented

@L3MON4D3
Copy link
Owner

Hi :)
I'm not 100% sure what you're asking:

I want to request data through Python code or curl to generate a list of titles

Should these be generated after expanding a snippet, or should these be used to generate a bunch of snippets?

to help me understand how it was implemented

What is it in this case? I don't think we have any examples that do requests 😅

@lbgws2
Copy link
Author

lbgws2 commented Aug 30, 2024

Hi :) I'm not 100% sure what you're asking:

I want to request data through Python code or curl to generate a list of titles

Should these be generated after expanding a snippet, or should these be used to generate a bunch of snippets?

to help me understand how it was implemented

What is it in this case? I don't think we have any examples that do requests 😅

Sorry, this was my mistake
For example, if a trigger word is defined as "rq", the script will use curl or Python to initiate a network request and return the following data:
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
},
{
"userId": 1,
"id": 3,
"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut",
"body": "et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut"
}
]
Format the returned JSON array using JQ, retrieve a field such as "title", and return a list of title fields for selection

@lbgws2
Copy link
Author

lbgws2 commented Aug 30, 2024

There are two main issues,

  1. How to use Luasnip to initiate network requests
  2. How to format the return result and generate a list of options

@L3MON4D3
Copy link
Owner

Ah, okay:
you can use a dynamicNode to generate nodes upon expanding.
In your case you'd want to generate a choiceNode since that allows switching between multiple options (and theres a cmp-source for it, https://github.com/L3MON4D3/cmp-luasnip-choice should work right now, but I can't promise it will continue to do so)

Regarding the request, you may want use something like luacurl since that would not require the separate bash+curl+jq, but you can try this first.

If you can massage the data into a more concrete format I can give you some more tips on the choiceNode :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants