Skip to content

Commit

Permalink
wip(server): try to fix relative autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Sep 27, 2024
1 parent 4e7449b commit 4821458
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 82 deletions.
41 changes: 29 additions & 12 deletions client/src/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ suite("Should do completion", () => {
});

test("Complete in expressions", async () => {
await testCompletion(docUri, new vscode.Position(2, 18), false);
await testCompletion(docUri, new vscode.Position(11, 12), false, [
ruleItem("rule a"),
// ruleItem("rule a . b"),
// ruleItem("rule a . c"),
]);
});
});

async function testCompletion(
docUri: vscode.Uri,
position: vscode.Position,
shouldBeEmtpy: boolean,
// expectedCompletionList?: vscode.CompletionList,
shouldBeEmpty: boolean,
expectedRulesCompletionItems?: vscode.CompletionItem[],
) {
await activate(docUri);

Expand All @@ -37,17 +41,30 @@ async function testCompletion(
position,
)) as vscode.CompletionList;

if (shouldBeEmtpy) {
if (shouldBeEmpty) {
assert.ok(actualCompletionList.items.length === 0);
} else {
assert.ok(actualCompletionList.items.length > 0);
// assert.ok(
// actualCompletionList.items.length === expectedCompletionList.items.length,
// );
// expectedCompletionList.items.forEach((expectedItem, i) => {
// const actualItem = actualCompletionList.items[i];
// assert.equal(actualItem.label, expectedItem.label);
// assert.equal(actualItem.kind, expectedItem.kind);
// });
const actualRulesCompletionItems = actualCompletionList.items.filter(
(item) => {
return (
item.kind !== vscode.CompletionItemKind.Property &&
item.kind !== vscode.CompletionItemKind.Keyword
);
},
);
assert.ok(
actualRulesCompletionItems.length ===
expectedRulesCompletionItems?.length,
);
expectedRulesCompletionItems?.forEach((expectedItem, i) => {
const actualItem = actualRulesCompletionItems[i];
assert.equal(actualItem.label, expectedItem.label);
assert.equal(actualItem.kind, expectedItem.kind);
});
}
}

function ruleItem(label: string): vscode.CompletionItem {
return new vscode.CompletionItem(label, vscode.CompletionItemKind.Function);
}
4 changes: 2 additions & 2 deletions client/testFixture/completion.publicodes
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
rule a:
titre: Résultat
valeur: b + c
valeur: rule a . b + rule a . c

rule a . b:
valeur: 2
description: |
Description.

rule a . c: 3
rule a . c:
4 changes: 2 additions & 2 deletions client/testFixture/main.publicodes
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
rule a:
titre: Résultat
valeur: b + c
valeur: rule a . b + rule a . c

rule a . b:
valeur: 2
description: |
Description.

rule a . c: 3
rule a . c:
Loading

0 comments on commit 4821458

Please sign in to comment.