From d61bafeda3ef5fa2eda89dc03b68e983ad80ece5 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Tue, 28 May 2024 09:54:33 -0400 Subject: [PATCH] Fix crash with optional chaining in signature help (#1207) --- src/Program.spec.ts | 13 +++++++++++++ src/bscPlugin/CallExpressionInfo.ts | 9 +++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Program.spec.ts b/src/Program.spec.ts index 34ebd498d..83184a08e 100644 --- a/src/Program.spec.ts +++ b/src/Program.spec.ts @@ -2369,6 +2369,19 @@ describe('Program', () => { expect(signatureHelp[0]?.signature).to.not.exist; }); + it('does not crash when parts is undefined', () => { + program.setFile('source/main.bs', ` + sub main() + print m.b["c"].hello?(12345) + end sub + `); + program.validate(); + expectZeroDiagnostics(program); + // 123|45 + let signatureHelp = getSignatureHelp(2, 45); + expect(signatureHelp).is.empty; + }); + describe('gets signature info for regular function call', () => { it('does not get help when on method name', () => { program.setFile('source/main.bs', ` diff --git a/src/bscPlugin/CallExpressionInfo.ts b/src/bscPlugin/CallExpressionInfo.ts index 42c9ecfc7..d1112524d 100644 --- a/src/bscPlugin/CallExpressionInfo.ts +++ b/src/bscPlugin/CallExpressionInfo.ts @@ -79,9 +79,11 @@ export class CallExpressionInfo { } else { let parts = util.getAllDottedGetParts(callExpression.callee); - parts.splice(parts?.length - 1, 1); - this.dotPart = parts.map(x => x.text).join('.'); - this.namespace = this.getNamespace(); + if (parts) { + parts.splice(parts?.length - 1, 1); + this.dotPart = parts.map(x => x.text).join('.'); + this.namespace = this.getNamespace(); + } } } @@ -162,4 +164,3 @@ export class CallExpressionInfo { } } -