diff --git a/src/LanguageServer.ts b/src/LanguageServer.ts index 9c4af50c3..be668b315 100644 --- a/src/LanguageServer.ts +++ b/src/LanguageServer.ts @@ -526,7 +526,7 @@ export class LanguageServer { timestamp: Date.now(), index: this.busyStatusIndex, activeRuns: [...this.projectManager.busyStatusTracker.activeRuns] - }).catch(logAndIgnoreError); + })?.catch(logAndIgnoreError); } private busyStatusIndex = -1; diff --git a/src/files/BrsFile.spec.ts b/src/files/BrsFile.spec.ts index c71c83457..1f787809a 100644 --- a/src/files/BrsFile.spec.ts +++ b/src/files/BrsFile.spec.ts @@ -47,6 +47,15 @@ describe('BrsFile', () => { program.dispose(); }); + describe('dispose', () => { + it('does not crash the program after it has been disposed', () => { + const file = program.setFile('source/main.bs', `sub main(): end sub`); + file.dispose(); + program.validate(); + expectZeroDiagnostics(program); + }); + }); + describe('allowBrighterScriptInBrightScript', () => { it('is false by default', () => { program.setFile('source/main.brs', ` diff --git a/src/lexer/Lexer.ts b/src/lexer/Lexer.ts index ac970644a..b7c7809b8 100644 --- a/src/lexer/Lexer.ts +++ b/src/lexer/Lexer.ts @@ -126,7 +126,7 @@ export class Lexer { * @returns `true` if the lexer has read to (or past) the end of its input, otherwise `false`. */ private isAtEnd() { - return this.current >= this.source.length; + return !this.source || this.current >= this.source.length; } /**