Skip to content

Commit

Permalink
Support when previousToken is missing.
Browse files Browse the repository at this point in the history
Fixes #357
  • Loading branch information
TwitchBronBron committed Mar 12, 2021
1 parent 471884d commit 8791733
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { EmptyStatement } from './parser/Statement';
import { expectZeroDiagnostics, trim, trimMap } from './testHelpers.spec';
import { doesNotThrow } from 'assert';
import { Logger } from './Logger';
import { createToken } from './astUtils';
import { TokenKind } from './lexer';

let sinon = sinonImport.createSandbox();
let tmpPath = s`${process.cwd()}/.tmp`;
Expand Down Expand Up @@ -1802,6 +1804,15 @@ describe('Program', () => {
});

describe('getSignatureHelp', () => {
it('does not crash when second previousToken is undefined', () => {
const file = program.addOrReplaceFile<BrsFile>('source/main.brs', ` `);
sinon.stub(file, 'getPreviousToken').returns(undefined);
//should not crash
expect(
file['getClassFromMReference'](util.createPosition(2, 3), createToken(TokenKind.Dot, '.'), null)
).to.be.undefined;
});

it('works with no leading whitespace when the cursor is after the open paren', () => {
program.addOrReplaceFile('source/main.brs', `sub main()\nsayHello()\nend sub\nsub sayHello(name)\nend sub`);
let signatureHelp = program.getSignatureHelp(
Expand Down
2 changes: 1 addition & 1 deletion src/files/BrsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ export class BrsFile {
if (previousToken?.kind === TokenKind.Dot) {
previousToken = this.getPreviousToken(previousToken);
}
if (previousToken.kind === TokenKind.Identifier && previousToken.text.toLowerCase() === 'm' && isClassMethodStatement(functionScope.func.functionStatement)) {
if (previousToken?.kind === TokenKind.Identifier && previousToken?.text.toLowerCase() === 'm' && isClassMethodStatement(functionScope.func.functionStatement)) {
return { item: this.parser.references.classStatements.find((cs) => util.rangeContains(cs.range, position)), file: this };
}
return undefined;
Expand Down

0 comments on commit 8791733

Please sign in to comment.