Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server: improve autocompletion #25

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export function activate(context: ExtensionContext) {
documentSelector: [{ scheme: "file", language: "publicodes" }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: [
workspace.createFileSystemWatcher("**/.clientrc"),
workspace.createFileSystemWatcher("**/.publicodes"),
],
fileEvents: [workspace.createFileSystemWatcher("**/.clientrc")],
},
markdown: {
isTrusted: true,
Expand Down
48 changes: 34 additions & 14 deletions client/src/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ suite("Should do completion", () => {
await testCompletion(docUri, new vscode.Position(7, 20), true);
});

test("Complete in expressions", async () => {
await testCompletion(docUri, new vscode.Position(2, 18), false);
});
// TODO: implement correct test
// test("Complete in expressions", async () => {
// await testCompletion(docUri, new vscode.Position(11, 12), false, [
// ruleItem("rule a"),
// ruleItem("b"),
// ruleItem("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 +42,32 @@ 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
);
},
);
console.log(actualRulesCompletionItems);
console.log(expectedRulesCompletionItems);
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:
2 changes: 1 addition & 1 deletion language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"increaseIndentPattern": "^\\s*.*(:|-) ?(&\\w+)?(\\{[^}\"']*|\\([^)\"']*)?$",
"decreaseIndentPattern": "^\\s+\\}$"
},
"wordPattern": "(^.?[^\\s]+)+|([^\\s\n={[][\\w\\-\\./$%&*:\"']+)",
"wordPattern": "",
"onEnterRules": [
{
"beforeText": "^\\s*(moyenne|somme|une de ces conditions|toutes ces conditions|variations|le maximum de|le minimum de|suggestions|références|les règles)\\:\\s*$",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
"editor.tabSize": 2,
"editor.autoIndent": "advanced",
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
"other": "on",
"comments": "off",
"strings": "on"
},
"editor.wordBasedSuggestions": "off",
"editor.semanticHighlight.enable": true,
Expand Down
Loading