Skip to content

Commit

Permalink
fix: Fix token query
Browse files Browse the repository at this point in the history
  • Loading branch information
famoser committed Feb 12, 2024
1 parent 47bac36 commit 1243313
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions server/src/parseTree/get_matching_parse_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const getMatchingParseTreeInternal = (parseTree: ParseTree, caretPosition: Caret
const checkCaretPositionOverlapsToken = (caretPosition: CaretPosition, token: Token) => {
return token.text &&
token.line === caretPosition.line &&
token.charPositionInLine <= caretPosition.column &&
token.charPositionInLine + (token.text?.length ?? 0) >= caretPosition.column;

caretPosition.column >= token.charPositionInLine &&
caretPosition.column < token.charPositionInLine + token.text.length;
};
2 changes: 1 addition & 1 deletion server/src/parseTree/get_signature_position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const getSignaturePosition = (tokens: TokenStream, position: Position): S

return {
signatureToken: currentSignatureToken,
signatureTokenPosition: Position.create(currentSignatureToken.line - 1, currentSignatureToken.charPositionInLine + 1),
signatureTokenPosition: Position.create(currentSignatureToken.line - 1, currentSignatureToken.charPositionInLine),
parameterPosition: commasBeforePositionInCurrentSignature
};
};
18 changes: 9 additions & 9 deletions server/tests/go_to_definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,47 @@ describe('go to definition', function () {

it("finds global scope variable", async () => {
const code = `channel c. channel d. process \nout(c, c)`;
const click = {line: 1, character: 5};
const click = {line: 1, character: 4};
const target = {line: 0, character: 8};

await assertSingleFileNavigation(code, click, target, 1);
});

it("override local scope variable", async () => {
const code = `channel c. process \nnew c:channel; \nout(c, c)`;
const click = {line: 2, character: 5};
const click = {line: 2, character: 4};
const target = {line: 1, character: 4};

await assertSingleFileNavigation(code, click, target, 1);
});

it("pattern variable", async () => {
const code = `channel c. process \nin(c, b:bitstring); \nout(c, b)`;
const click = {line: 2, character: 8};
const click = {line: 2, character: 7};
const target = {line: 1, character: 6};

await assertSingleFileNavigation(code, click, target, 1);
});

it("complex pattern variable", async () => {
const code = `channel c. process \nin(c, (=2, b:bitstring)); \nout(c, b)`;
const click = {line: 2, character: 8};
const click = {line: 2, character: 7};
const target = {line: 1, character: 11};

await assertSingleFileNavigation(code, click, target, 1);
});

it("override variable", async () => {
const code = `channel c. free b: bitstring. process \nin(c, b:bitstring); \nout(c, b)`;
const click = {line: 2, character: 8};
const click = {line: 2, character: 7};
const target = {line: 1, character: 6};

await assertSingleFileNavigation(code, click, target, 1);
});

it("do not override match variable", async () => {
const code = `channel c. free b: bitstring. process \nin(c, =b); \nout(c, b)`;
const click = {line: 2, character: 8};
const click = {line: 2, character: 7};
const target = {line: 0, character: 16};

await assertSingleFileNavigation(code, click, target, 1);
Expand All @@ -105,15 +105,15 @@ process System`;

it("consider query variables", async () => {
const code = `free b: bitstring.\nquery x:bitstring; attacker(x). process 0`;
const click = {line: 1, character: 29};
const click = {line: 1, character: 28};
const target = {line: 1, character: 6};

await assertSingleFileNavigation(code, click, target, 1);
});

it("consider let arguments", async () => {
const code = `let Proc(c: channel) = \nin(c, b:bitstring).\nprocess 0`;
const click = {line: 1, character: 4};
const click = {line: 1, character: 3};
const target = {line: 0, character: 9};

await assertSingleFileNavigation(code, click, target, 1);
Expand All @@ -133,7 +133,7 @@ process System`;

const uri = 'main.pv';
const code = 'process \nout(c, c)';
const click = {line: 1, character: 5};
const click = {line: 1, character: 4};
const target = {line: 0, character: 8};

const documentManager = new MockDocumentManager();
Expand Down

0 comments on commit 1243313

Please sign in to comment.