Skip to content

Commit 34beb95

Browse files
authored
fix(parser): add nvim_treesitter/main compatibility (#592)
* fix(parser): add nvim_treesitter/main compatibility * docs: update GraphQL * feat: add automatic bug reporting * fix(parser): update ts_grammar to support GRPC method * fix(grpc): allow inline flags with `:` * fix(ui): silence response formatting errors * feat(parser): allow variables in curl and grpc flags * feat(formatter): add sorting options
1 parent 90d80ce commit 34beb95

File tree

34 files changed

+3736
-3132
lines changed

34 files changed

+3736
-3132
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
name: Bug report
33
about: Create a report to help us improve
44
title: "[BUG] "
5-
labels: ''
5+
labels: bug
66
assignees: ''
77

88
---
99

10+
The easiest way to submit a bug report is to set the option `generate_bug_report` in the config.
11+
12+
This will offer to generate a bug report and open a GitHub Issue with it, when an error is encountered.
13+
14+
Alternatively, you can generate the report manually with `require("kulala").generate_bug_report()` or follow the template below.
15+
16+
#
17+
1018
**Describe the bug**
1119
A clear and concise description of what the bug is.
1220

docs/docs/getting-started/configuration-options.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ Example:
436436
}
437437
```
438438

439+
### generate_bug_report
440+
441+
Generate a bug report on error.
442+
443+
Default: `false`
444+
439445
## Scripts
440446

441447
### scripts.node_path_resolver
@@ -922,7 +928,12 @@ Function called when Kulala LSP attaches to the buffer
922928
enable = true,
923929
keymaps = false, -- disabled by default, as Kulala relies on default Neovim LSP keymaps
924930
formatter = {
925-
json_sort = true, -- sort JSON keys in request body
931+
sort = { -- enable/disable alphabetical sorting in request body
932+
metadata = true,
933+
variables = true,
934+
commands = true,
935+
json = true,
936+
},
926937
},
927938
on_attach = function(client, bufnr)
928939
-- custom on_attach function

docs/docs/usage/basic-usage.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ require("nvim-lightbulb").setup({
9797
9898
#### Directives
9999
100-
- `# @graphql` allows you to run a GraphQL query.
101100
- `# @accept chunked` allows you to accept Transfer-Encoding: chunked responses and streamed responses.
102101
- `# @curl-global-...` and `# @curl-...` allows you to set global and per-request flags for curl requests.
103102
- `# @grpc-global-...` and `# @grpc-...` allows you to set global and per-request flags for gRPC requests.

docs/docs/usage/custom-curl-flags.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Local flags take precedence over global flags.
2222

2323
If you need to apply curl flags to OAuth requests, you have to use `# @curl-global-..` flags.
2424

25+
In order for global flags to take effect, the request where they are defined must be run at least once.
2526
:::
2627

2728
### Some common curl flags you might want to use:

docs/docs/usage/graphql.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# GraphQL
22

3-
You can use the `GRAPHQL` method (preferred), `@graphql` directive or `X-REQUEST-TYPE: GraphQL` header to send GraphQL requests.
3+
Use `GRAPHQL` method to indicate a GRAPHQL request.
4+
5+
`@graphql` directive or `X-REQUEST-TYPE: GraphQL` header may also work, but are deprecated and will not activate all the features of the GraphQL request.
46

57
Create a file with the `.http` extension and write your GraphQL requests in it.
68

@@ -9,7 +11,6 @@ Create a file with the `.http` extension and write your GraphQL requests in it.
911
```http title="gql-with-variables.http"
1012
GRAPHQL https://swapi-graphql.netlify.app/.netlify/functions/index HTTP/1.1
1113
Accept: application/json
12-
X-REQUEST-TYPE: GraphQL
1314
1415
query Person($id: ID) {
1516
person(personID: $id) {
@@ -23,10 +24,8 @@ query Person($id: ID) {
2324
## Without variables
2425

2526
```http title="gql-without-variables.http"
26-
# @graphql
27-
POST https://swapi-graphql.netlify.app/.netlify/functions/index HTTP/1.1
27+
GRAPHQL https://swapi-graphql.netlify.app/.netlify/functions/index HTTP/1.1
2828
Accept: application/json
29-
X-REQUEST-TYPE: GraphQL
3029
3130
query Query {
3231
allFilms {

docs/docs/usage/grpc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ Content-Type: application/json
7070
:::warning
7171

7272
Flags set in variables override flags set in metatadata, which in turn override global flags.
73+
In order for global flags to take effect, the request where they are defined must be run at least once.
7374

7475
:::

docs/docs/usage/public-methods.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,12 @@ You can download the schema of a GraphQL server with:
129129
You need to have your cursor on a line with a GraphQL request.
130130

131131
The file will be downloaded to
132-
the the directory where the current file is located.
132+
the directory where the current file is located.
133133

134134
The filename will be
135-
`[http-file-name-without-extension].graphql-schema.json`.
135+
`[request name].graphql-schema.json`.
136136

137-
This file can be used in conjunction with
138-
the [kulala-cmp-graphql][kulala-cmp-graphql] plugin to
139-
provide autocompletion and type checking.
137+
This is required for the autocompletion and type checking to work.
140138

141139
### get_selected_env
142140

@@ -167,5 +165,9 @@ it'll try to load up a telescope prompt to
167165
select an environment or fallback to using `vim.ui.select`.
168166

169167
[scratchpad_default_contents]: ../getting-started/configuration-options#uiscratchpad_default_contents
170-
[kulala-cmp-graphql]: https://github.com/mistweaverco/kulala-cmp-graphql.nvim
171168
[env-files]: https://learn.microsoft.com/en-us/aspnet/core/test/http-files?view=aspnetcore-8.0#environment-files
169+
170+
### generate_bug_report
171+
172+
`require('kulala').generate_bug_report()`
173+
Generates a bug report and opens a GitHub issue with it.

docs/docs/usage/recipes.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,47 @@ Content-Type: {{content_type}}
4040
4141
------WebKitFormBoundary{{$timestamp}}--
4242
```
43+
44+
### Authenticating with browser-based auth
45+
46+
```http
47+
48+
### Acquire_XSRF_TOKEN
49+
50+
GET localhost:8000/login
51+
52+
> {%
53+
-- lua
54+
client.global.token = response.cookies["XSRF-TOKEN"].value
55+
client.global.decoded_token = vim.uri_decode(client.global.token)
56+
client.global.session = response.cookies["laravel_session"].value
57+
%}
58+
59+
### Authentication
60+
61+
POST localhost:8000/login
62+
Content-Type: application/json
63+
X-Xsrf-Token: {{decoded_token}}
64+
Cookie: XSRF-TOKEN={{token}}
65+
Cookie: laravel_session={{session}}
66+
Referer: http://localhost:8000/login
67+
68+
{
69+
"email": "mail@mail.com",
70+
"password": "passpass"
71+
}
72+
73+
> {%
74+
-- lua
75+
-- save the new set authenticated session
76+
client.global.session = response.cookies["laravel_session"].value
77+
%}
78+
79+
### Dashboard
80+
81+
run #Acquire_XSRF_TOKEN
82+
run #Authentication
83+
84+
GET http://localhost:8000/dashboard
85+
Cookie: laravel_session={{session}}
86+
```

lua/kulala/cmd/formatter.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local Json = require("kulala.utils.json")
44
local Xml = require("kulala.utils.xml")
55

66
local format_opts = Config.options.lsp.formatter
7-
format_opts = type(format_opts) == "table" and format_opts or { json_sort = true }
7+
format_opts = type(format_opts) == "table" and format_opts or { sort = { json = true } }
88

99
local M = {}
1010

@@ -191,7 +191,7 @@ format_rules = {
191191
local variable_declaration = ("@%s = %s"):format(name or "", value or "")
192192

193193
table.insert(current_section().variables, variable_declaration)
194-
table.sort(current_section().variables)
194+
_ = format_opts.sort.variables and table.sort(current_section().variables)
195195

196196
return variable_declaration
197197
end,
@@ -215,7 +215,7 @@ format_rules = {
215215
local metadata = str:format(name, value)
216216

217217
table.insert(current_section().metadata, metadata)
218-
table.sort(current_section().metadata)
218+
_ = format_opts.sort.metadata and table.sort(current_section().metadata)
219219

220220
return metadata
221221
end,
@@ -228,7 +228,7 @@ format_rules = {
228228
formatted = vars and formatted .. " (" .. vars .. ")" or formatted
229229

230230
table.insert(current_section().commands, formatted)
231-
table.sort(current_section().commands)
231+
_ = format_opts.sort.commands and table.sort(current_section().commands)
232232

233233
return formatted
234234
end,
@@ -238,7 +238,8 @@ format_rules = {
238238

239239
local method = get_fields(node, "method") or "GET"
240240
local target_url = get_fields(node, "url") or ""
241-
local http_version = get_fields(node, "version") or "HTTP/1.1"
241+
local http_version = get_fields(node, "version")
242+
or (method ~= "GRPC" and method ~= "WEBSOCKET" and method ~= "WS" and "HTTP/1.1" or "")
242243

243244
local request = current_section().request
244245
request.url = ("%s %s %s"):format(method, target_url, http_version)
@@ -289,15 +290,15 @@ format_rules = {
289290

290291
["json_body"] = function(node)
291292
local json = get_text(node)
292-
local formatted = Json.format(json, { sort = format_opts.json_sort }) or json
293+
local formatted = Json.format(json, { sort = format_opts.sort.json }) or json
293294

294295
current_section().request.body = formatted:gsub("\n*$", "")
295296
return formatted
296297
end,
297298

298299
["graphql_body"] = function(node)
299300
local body = get_text(node)
300-
local formatted = Graphql.format(body, { sort = format_opts.json_sort }) or body
301+
local formatted = Graphql.format(body, { sort = format_opts.sort.json }) or body
301302

302303
current_section().request.body = formatted:gsub("\n*$", "")
303304
return formatted

lua/kulala/cmd/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function queue.run_next(self)
6565

6666
if not (status and cb_status) then
6767
self:reset()
68-
Logger.error(("Errors running a scheduled task: %s %s"):format(errors or "", cb_errors))
68+
Logger.error(("Errors running a scheduled task: %s %s"):format(errors or "", cb_errors), 1, true)
6969
end
7070

7171
self.done = self.done + 1
@@ -261,7 +261,7 @@ local function process_errors(request, request_status, processing_errors)
261261
)
262262

263263
Logger.error(message, 2)
264-
_ = processing_errors and Logger.error(processing_errors, 2)
264+
_ = processing_errors and Logger.error(processing_errors, 2, true)
265265

266266
request_status.errors = processing_errors and request_status.errors .. "\n" .. processing_errors
267267
or request_status.errors

0 commit comments

Comments
 (0)