Skip to content

Commit

Permalink
Fix off-by-one
Browse files Browse the repository at this point in the history
  • Loading branch information
nikeee committed May 29, 2023
1 parent b57efe1 commit 53ba730
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/service/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getHoverContents(n: SyntaxNode): string | undefined {
if (n.symbol?.references) {
const nodeIdentifierRefs = n.symbol?.references;
const labelMentions = nodeIdentifierRefs.map(e => e.symbol?.members?.get("label")?.firstMention.parent as IdEqualsIdStatement | null | undefined);
for (let i = labelMentions.length; i > 0; i--) {
for (let i = labelMentions.length; i >= 0; i--) {
const s = labelMentions[i];
if (s?.rightId) {
return `(node) ${getIdentifierText(n)}: ${getIdentifierText(s.rightId)}`;
Expand Down
28 changes: 28 additions & 0 deletions tests/providers/hover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,32 @@ describe("Hover Handling", () => {
let h = hoverOnCode(22);
expect(h.contents).toEqual("(node) c: xd");
});

/**
* See https://github.com/nikeee/dot-language-support/issues/83
*/
test("should correctly show node labels on hover (other node)", () => {
const hoverOnCode = hoverSample(`digraph G {
vp [label="View Profile"];
vf [label="View Friends"];
vp -> vf;
}`);
let h = hoverOnCode(75);
expect(h.contents).toEqual("(node) vp: View Profile");
});

/**
* See https://github.com/nikeee/dot-language-support/issues/83
*/
test("should correctly show node labels on hover (other node)", () => {
const hoverOnCode = hoverSample(`digraph G {
vp [label="View Profile"];
vf [label="View Friends"];
vp -> vf;
}`);
let h = hoverOnCode(81);
expect(h.contents).toEqual("(node) vf: View Friends");
});
});

0 comments on commit 53ba730

Please sign in to comment.