Skip to content

Commit

Permalink
fix: bug with completion in incomplete alg (#516)
Browse files Browse the repository at this point in the history
Fix bug with completion in incomplete alg
  • Loading branch information
vetlek authored Feb 29, 2024
1 parent a15c593 commit c912b81
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
29 changes: 20 additions & 9 deletions server/src/language-service/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,25 @@ export function getCalcCompletion(
const metaInfoProvider = SepticMetaInfoProvider.getInstance();
const compItems: CompletionItem[] = [];
let ref = cnfg.getXvrRefFromOffset(offset);
let range: Range = ref
? {
start: doc.positionAt(ref.location.start),
end: doc.positionAt(ref.location.end),
}
: {
start: doc.positionAt(offset),
end: doc.positionAt(offset),
};
let range: Range;
if (ref) {
range = {
start: doc.positionAt(ref.location.start),
end: doc.positionAt(ref.location.end),
};
} else {
let pos = doc.positionAt(offset);
let line = doc.getText({
start: Position.create(pos.line, 0),
end: Position.create(pos.line, Infinity),
});
let existing = getExistingCompletion(line, pos.character - 1);
range = {
start: doc.positionAt(offset - existing.str.length),
end: pos,
};
}

getRelevantXvrsCalc(refProvider.getAllXvrObjects()).forEach((xvr) => {
compItems.push(xvrToCompletionItem(xvr, range));
});
Expand Down Expand Up @@ -385,6 +395,7 @@ function xvrToCompletionItem(obj: SepticObject, range: Range): CompletionItem {
kind: CompletionItemKind.Variable,
detail: obj.type,
data: obj.identifier!.name,
filterText: obj.identifier!.name,
textEdit: TextEdit.replace(range, obj.identifier!.name),
};
}
Expand Down
12 changes: 12 additions & 0 deletions server/src/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ describe("Test calc completion", () => {
).length
).to.equal(2);
});
it("Completion suggest Xvrs and Calcs in incomplete alg", () => {
const text = `Mvr: TestMvr\nEvr: TestEvr\nCalcPvr: TestCalc\nAlg= "(TestMvr + T "\n`;
const doc = TextDocument.create("test.cnfg", "septic", 0, text);
const cnfg = parseSeptic(doc.getText());
const offset = doc.offsetAt(Position.create(3, 17));
const compItems = getCalcCompletion(offset, cnfg, doc, cnfg);
expect(
compItems.filter(
(item) => item.kind === CompletionItemKind.Variable
).length
).to.equal(2);
});
it("Completion don't suggest SopcXvrs", () => {
const text = `SopcMvr: TestMvr\nSopcEvr: TestEvr\nCalcPvr: TestCalc\nAlg= " "\n`;
const doc = TextDocument.create("test.cnfg", "septic", 0, text);
Expand Down

0 comments on commit c912b81

Please sign in to comment.