@@ -91,6 +91,8 @@ type codeAction = {
9191 edit : codeActionEdit ;
9292}
9393
94+ let wrapInQuotes s = " \" " ^ Json. escape s ^ " \" "
95+
9496let null = " null"
9597let array l = " [" ^ String. concat " , " l ^ " ]"
9698
@@ -103,7 +105,8 @@ let stringifyRange r =
103105 (stringifyPosition r.end_)
104106
105107let 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. *)
109112let 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-
125126let optWrapInQuotes s =
126127 match s with
127128 | None -> None
@@ -162,7 +163,7 @@ let stringifyHover value =
162163 (stringifyMarkupContent {kind = " markdown" ; value})
163164
164165let 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
168169let stringifyDocumentSymbolItems items =
@@ -209,27 +210,27 @@ let stringifyDocumentSymbolItems items =
209210let 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
217218let 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
224225let 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
234235let stringifyTextDocumentEdit tde =
235236 Printf. sprintf {| {
@@ -276,26 +277,27 @@ let stringifyCodeActionEdit cae =
276277 (cae.documentChanges |> List. map stringifyDocumentChange |> array )
277278
278279let 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
283285let 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
295297let 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
300302let 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