Skip to content

Commit a66d82a

Browse files
authored
Merge pull request #253 from ulugbekna/fix-completion-bug
Fix completion bug #252
2 parents b264d8f + b898846 commit a66d82a

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

ocaml-lsp-server/src/compl.ml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ let item index full_entry ~compl_info =
135135
~sortText:(Printf.sprintf "%04d" index)
136136
~data:compl_info ?textEdit ()
137137

138-
let completion_kinds =
139-
[ `Constructor; `Labels; `Modules; `Modules_type; `Types; `Values; `Variants ]
140-
141138
let complete doc lsp_position =
142139
let position = Position.logical lsp_position in
143140

@@ -149,8 +146,7 @@ let complete doc lsp_position =
149146
Document.with_pipeline_exn doc @@ fun pipeline ->
150147
let completion =
151148
let complete =
152-
Query_protocol.Complete_prefix
153-
(prefix, position, completion_kinds, false, true)
149+
Query_protocol.Complete_prefix (prefix, position, [], false, true)
154150
in
155151
Query_commands.dispatch pipeline complete
156152
in
@@ -179,9 +175,7 @@ let complete doc lsp_position =
179175
match items with
180176
| _ :: _ -> items
181177
| [] ->
182-
let expand =
183-
Query_protocol.Expand_prefix (prefix, position, completion_kinds, true)
184-
in
178+
let expand = Query_protocol.Expand_prefix (prefix, position, [], true) in
185179
let { Query_protocol.Compl.entries; context = _ } =
186180
Query_commands.dispatch pipeline expand
187181
in

ocaml-lsp-server/test/e2e/__tests__/textDocument-completion.test.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ describe_opt("textDocument/completion", () => {
250250
expect(items_top5).toMatchInlineSnapshot(`
251251
Array [
252252
Object {
253-
"label": "()",
253+
"label": "somenum",
254254
"textEdit": Object {
255-
"newText": "()",
255+
"newText": "somenum",
256256
"range": Object {
257257
"end": Object {
258258
"character": 12,
@@ -266,9 +266,9 @@ describe_opt("textDocument/completion", () => {
266266
},
267267
},
268268
Object {
269-
"label": "::",
269+
"label": "x",
270270
"textEdit": Object {
271-
"newText": "::",
271+
"newText": "x",
272272
"range": Object {
273273
"end": Object {
274274
"character": 12,
@@ -282,9 +282,9 @@ describe_opt("textDocument/completion", () => {
282282
},
283283
},
284284
Object {
285-
"label": "Assert_failure",
285+
"label": "y",
286286
"textEdit": Object {
287-
"newText": "Assert_failure",
287+
"newText": "y",
288288
"range": Object {
289289
"end": Object {
290290
"character": 12,
@@ -298,9 +298,9 @@ describe_opt("textDocument/completion", () => {
298298
},
299299
},
300300
Object {
301-
"label": "Division_by_zero",
301+
"label": "max_int",
302302
"textEdit": Object {
303-
"newText": "Division_by_zero",
303+
"newText": "max_int",
304304
"range": Object {
305305
"end": Object {
306306
"character": 12,
@@ -314,9 +314,9 @@ describe_opt("textDocument/completion", () => {
314314
},
315315
},
316316
Object {
317-
"label": "End_of_file",
317+
"label": "min_int",
318318
"textEdit": Object {
319-
"newText": "End_of_file",
319+
"newText": "min_int",
320320
"range": Object {
321321
"end": Object {
322322
"character": 12,
@@ -432,33 +432,33 @@ describe_opt("textDocument/completion", () => {
432432
},
433433
},
434434
{
435-
label: "ListLabels.t",
435+
label: "ListLabels.append",
436436
textEdit: {
437437
range: {
438438
start: { line: 0, character: 8 },
439439
end: { line: 0, character: 10 },
440440
},
441-
newText: "ListLabels.t",
441+
newText: "ListLabels.append",
442442
},
443443
},
444444
{
445-
label: "ListLabels.append",
445+
label: "ListLabels.assoc",
446446
textEdit: {
447447
range: {
448448
start: { line: 0, character: 8 },
449449
end: { line: 0, character: 10 },
450450
},
451-
newText: "ListLabels.append",
451+
newText: "ListLabels.assoc",
452452
},
453453
},
454454
{
455-
label: "ListLabels.assoc",
455+
label: "ListLabels.assoc_opt",
456456
textEdit: {
457457
range: {
458458
start: { line: 0, character: 8 },
459459
end: { line: 0, character: 10 },
460460
},
461-
newText: "ListLabels.assoc",
461+
newText: "ListLabels.assoc_opt",
462462
},
463463
},
464464
]);
@@ -563,4 +563,18 @@ describe_opt("textDocument/completion", () => {
563563
]
564564
`);
565565
});
566+
567+
it("completion doesn't autocomplete record fields", async () => {
568+
openDocument(outdent`
569+
type r = {
570+
x: int;
571+
y: string
572+
}
573+
574+
let _ =
575+
`);
576+
577+
let items: Array<any> = await queryCompletion(Types.Position.create(5, 8));
578+
expect(items.filter(compl => compl.label === "x" || compl.label === "y")).toHaveLength(0);
579+
})
566580
});

0 commit comments

Comments
 (0)