@@ -33,11 +33,22 @@ type signatureHelp = {
33
33
activeParameter : int option ;
34
34
}
35
35
36
+ (* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#insertTextFormat *)
37
+ type insertTextFormat = PlainText | Snippet
38
+
39
+ let insertTextFormatToInt f =
40
+ match f with
41
+ | PlainText -> 1
42
+ | Snippet -> 2
43
+
36
44
type completionItem = {
37
45
label : string ;
38
46
kind : int ;
39
47
tags : int list ;
40
48
detail : string ;
49
+ sortText : string option ;
50
+ insertTextFormat : insertTextFormat option ;
51
+ insertText : string option ;
41
52
documentation : markupContent option ;
42
53
}
43
54
@@ -86,21 +97,45 @@ let stringifyRange r =
86
97
let stringifyMarkupContent (m : markupContent ) =
87
98
Printf. sprintf {| {" kind" : " %s" , " value" : " %s" }| } m.kind (Json. escape m.value)
88
99
100
+ (* * None values are not emitted in the output. *)
101
+ let stringifyObject properties =
102
+ {| {
103
+ | }
104
+ ^ (properties
105
+ |> List. filter_map (fun (key , value ) ->
106
+ match value with
107
+ | None -> None
108
+ | Some v -> Some (Printf. sprintf {| " %s" : % s| } key v))
109
+ |> String. concat " ,\n " )
110
+ ^ " \n }"
111
+
112
+ let wrapInQuotes s = " \" " ^ s ^ " \" "
113
+
114
+ let optWrapInQuotes s =
115
+ match s with
116
+ | None -> None
117
+ | Some s -> Some (wrapInQuotes s)
118
+
89
119
let stringifyCompletionItem c =
90
- Printf. sprintf
91
- {| {
92
- " label" : " %s" ,
93
- " kind" : % i,
94
- " tags" : % s,
95
- " detail" : " %s" ,
96
- " documentation" : % s
97
- }| }
98
- (Json. escape c.label) c.kind
99
- (c.tags |> List. map string_of_int |> array )
100
- (Json. escape c.detail)
101
- (match c.documentation with
102
- | None -> null
103
- | Some doc -> stringifyMarkupContent doc)
120
+ stringifyObject
121
+ [
122
+ (" label" , Some (wrapInQuotes (Json. escape c.label)));
123
+ (" kind" , Some (string_of_int c.kind));
124
+ (" tags" , Some (c.tags |> List. map string_of_int |> array ));
125
+ (" detail" , Some (wrapInQuotes (Json. escape c.detail)));
126
+ ( " documentation" ,
127
+ Some
128
+ (match c.documentation with
129
+ | None -> null
130
+ | Some doc -> stringifyMarkupContent doc) );
131
+ (" sortText" , optWrapInQuotes c.sortText);
132
+ (" insertText" , optWrapInQuotes c.insertText);
133
+ ( " insertTextFormat" ,
134
+ match c.insertTextFormat with
135
+ | None -> None
136
+ | Some insertTextFormat ->
137
+ Some (Printf. sprintf " %i" (insertTextFormatToInt insertTextFormat)) );
138
+ ]
104
139
105
140
let stringifyHover value =
106
141
Printf. sprintf {| {" contents" : % s}| }
0 commit comments