LuaSnip
LuaSnip copied to clipboard
expand request data
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
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 :sweat_smile:
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
itin 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
There are two main issues,
- How to use Luasnip to initiate network requests
- How to format the return result and generate a list of options
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 :)