Skip to content

Commit

Permalink
Assign .program to the builder BEFORE calling afterProgram (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron authored Jan 11, 2024
1 parent 872c2df commit dc0fc65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
17 changes: 16 additions & 1 deletion src/ProgramBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { standardizePath as s, util } from './util';
import { Logger, LogLevel } from './Logger';
import * as diagnosticUtils from './diagnosticUtils';
import type { BscFile, BsDiagnostic } from '.';
import { Range } from '.';
import { Deferred, Range } from '.';
import { DiagnosticSeverity } from 'vscode-languageserver';
import { BrsFile } from './files/BrsFile';
import { expectZeroDiagnostics } from './testHelpers.spec';
Expand Down Expand Up @@ -41,6 +41,21 @@ describe('ProgramBuilder', () => {
builder.dispose();
});

it('includes .program in the afterProgramCreate event', async () => {
builder = new ProgramBuilder();
const deferred = new Deferred<Program>();
builder.plugins.add({
name: 'test',
afterProgramCreate: () => {
deferred.resolve(builder.program);
}
});
builder['createProgram']();
expect(
await deferred.promise
).to.exist;
});

describe('loadAllFilesAST', () => {
it('loads .bs, .brs, .xml files', async () => {
sinon.stub(util, 'getFilePaths').returns(Promise.resolve([{
Expand Down
9 changes: 5 additions & 4 deletions src/ProgramBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ProgramBuilder {
}
this.logger.logLevel = this.options.logLevel as LogLevel;

this.program = this.createProgram();
this.createProgram();

//parse every file in the entire project
await this.loadAllFilesAST();
Expand All @@ -139,10 +139,11 @@ export class ProgramBuilder {
}

protected createProgram() {
const program = new Program(this.options, this.logger, this.plugins);
this.program = new Program(this.options, this.logger, this.plugins);

this.plugins.emit('afterProgramCreate', program);
return program;
this.plugins.emit('afterProgramCreate', this.program);

return this.program;
}

protected loadPlugins() {
Expand Down

0 comments on commit dc0fc65

Please sign in to comment.