Skip to content

Commit e76c405

Browse files
committed
escape using the same fn
1 parent 14f39b5 commit e76c405

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

analysis/src/Protocol.ml

+24-22
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ type codeAction = {
9191
edit: codeActionEdit;
9292
}
9393

94+
let wrapInQuotes s = "\"" ^ Json.escape s ^ "\""
95+
9496
let null = "null"
9597
let array l = "[" ^ String.concat ", " l ^ "]"
9698

@@ -103,7 +105,8 @@ let stringifyRange r =
103105
(stringifyPosition r.end_)
104106

105107
let stringifyMarkupContent (m : markupContent) =
106-
Printf.sprintf {|{"kind": "%s", "value": "%s"}|} m.kind (Json.escape m.value)
108+
Printf.sprintf {|{"kind": %s, "value": %s}|} (wrapInQuotes m.kind)
109+
(wrapInQuotes m.value)
107110

108111
(** None values are not emitted in the output. *)
109112
let stringifyObject ?(startOnNewline = false) ?(indentation = 1) properties =
@@ -120,8 +123,6 @@ let stringifyObject ?(startOnNewline = false) ?(indentation = 1) properties =
120123
|> String.concat ",\n")
121124
^ "\n" ^ indentationStr ^ "}"
122125

123-
let wrapInQuotes s = "\"" ^ Json.escape s ^ "\""
124-
125126
let optWrapInQuotes s =
126127
match s with
127128
| None -> None
@@ -162,7 +163,7 @@ let stringifyHover value =
162163
(stringifyMarkupContent {kind = "markdown"; value})
163164

164165
let stringifyLocation (h : location) =
165-
Printf.sprintf {|{"uri": "%s", "range": %s}|} (Json.escape h.uri)
166+
Printf.sprintf {|{"uri": %s, "range": %s}|} (wrapInQuotes h.uri)
166167
(stringifyRange h.range)
167168

168169
let stringifyDocumentSymbolItems items =
@@ -209,27 +210,27 @@ let stringifyDocumentSymbolItems items =
209210
let stringifyRenameFile {oldUri; newUri} =
210211
Printf.sprintf {|{
211212
"kind": "rename",
212-
"oldUri": "%s",
213-
"newUri": "%s"
213+
"oldUri": %s,
214+
"newUri": %s
214215
}|}
215-
(Json.escape oldUri) (Json.escape newUri)
216+
(wrapInQuotes oldUri) (wrapInQuotes newUri)
216217

217218
let stringifyTextEdit (te : textEdit) =
218219
Printf.sprintf {|{
219220
"range": %s,
220-
"newText": "%s"
221+
"newText": %s
221222
}|}
222-
(stringifyRange te.range) (Json.escape te.newText)
223+
(stringifyRange te.range) (wrapInQuotes te.newText)
223224

224225
let stringifyoptionalVersionedTextDocumentIdentifier td =
225226
Printf.sprintf {|{
226227
"version": %s,
227-
"uri": "%s"
228+
"uri": %s
228229
}|}
229230
(match td.version with
230231
| None -> null
231232
| Some v -> string_of_int v)
232-
(Json.escape td.uri)
233+
(wrapInQuotes td.uri)
233234

234235
let stringifyTextDocumentEdit tde =
235236
Printf.sprintf {|{
@@ -276,26 +277,27 @@ let stringifyCodeActionEdit cae =
276277
(cae.documentChanges |> List.map stringifyDocumentChange |> array)
277278

278279
let stringifyCodeAction ca =
279-
Printf.sprintf {|{"title": "%s", "kind": "%s", "edit": %s}|} ca.title
280-
(codeActionKindToString ca.codeActionKind)
280+
Printf.sprintf {|{"title": %s, "kind": %s, "edit": %s}|}
281+
(wrapInQuotes ca.title)
282+
(wrapInQuotes (codeActionKindToString ca.codeActionKind))
281283
(ca.edit |> stringifyCodeActionEdit)
282284

283285
let stringifyHint hint =
284286
Printf.sprintf
285287
{|{
286288
"position": %s,
287-
"label": "%s",
289+
"label": %s,
288290
"kind": %i,
289291
"paddingLeft": %b,
290292
"paddingRight": %b
291293
}|}
292294
(stringifyPosition hint.position)
293-
(Json.escape hint.label) hint.kind hint.paddingLeft hint.paddingRight
295+
(wrapInQuotes hint.label) hint.kind hint.paddingLeft hint.paddingRight
294296

295297
let stringifyCommand (command : command) =
296-
Printf.sprintf {|{"title": "%s", "command": "%s"}|}
297-
(Json.escape command.title)
298-
(Json.escape command.command)
298+
Printf.sprintf {|{"title": %s, "command": %s}|}
299+
(wrapInQuotes command.title)
300+
(wrapInQuotes command.command)
299301

300302
let stringifyCodeLens (codeLens : codeLens) =
301303
Printf.sprintf
@@ -319,10 +321,10 @@ let stringifySignatureInformation (signatureInformation : signatureInformation)
319321
=
320322
Printf.sprintf
321323
{|{
322-
"label": "%s",
324+
"label": %s,
323325
"parameters": %s%s
324326
}|}
325-
(Json.escape signatureInformation.label)
327+
(wrapInQuotes signatureInformation.label)
326328
(signatureInformation.parameters
327329
|> List.map stringifyParameterInformation
328330
|> array)
@@ -352,8 +354,8 @@ let stringifyDiagnostic d =
352354
Printf.sprintf
353355
{|{
354356
"range": %s,
355-
"message": "%s",
357+
"message": %s,
356358
"severity": %d,
357359
"source": "ReScript"
358360
}|}
359-
(stringifyRange d.range) (Json.escape d.message) d.severity
361+
(stringifyRange d.range) (wrapInQuotes d.message) d.severity

0 commit comments

Comments
 (0)