Skip to content

Commit

Permalink
Not all the BrsFile fields need to be filled at parse time (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe authored Oct 12, 2020
1 parent e87498f commit dd84831
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/files/BrsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ export class BrsFile {

public functionCalls = [] as FunctionCall[];

public functionScopes = [] as FunctionScope[];
private _functionScopes: FunctionScope[];

public get functionScopes(): FunctionScope[] {
if (!this._functionScopes) {
this.createFunctionScopes();
}
return this._functionScopes;
}

/**
* files referenced by import statements
Expand Down Expand Up @@ -177,15 +184,9 @@ export class BrsFile {
//extract all callables from this file
this.findCallables();

//traverse the ast and find all functions and create a scope object
this.createFunctionScopes();

//find all places where a sub/function is being called
this.findFunctionCalls();

//scan the full text for any word that looks like a variable
this.findPropertyNameCompletions();

this.findAndValidateImportAndImportStatements();

//attach this file to every diagnostic
Expand Down Expand Up @@ -307,7 +308,7 @@ export class BrsFile {
return x && x.kind === TokenKind.Identifier;
});

this.propertyNameCompletions = [];
this._propertyNameCompletions = [];
let names = {};
for (let identifier of identifiers) {
let ancestors = this.getAncestors(identifier.key);
Expand Down Expand Up @@ -340,14 +341,21 @@ export class BrsFile {
}

names[name] = true;
this.propertyNameCompletions.push({
this._propertyNameCompletions.push({
label: name,
kind: CompletionItemKind.Text
});
}
}

public propertyNameCompletions = [] as CompletionItem[];
private _propertyNameCompletions: CompletionItem[];

public get propertyNameCompletions(): CompletionItem[] {
if (!this._propertyNameCompletions) {
this.findPropertyNameCompletions();
}
return this._propertyNameCompletions;
}

/**
* Find all comment flags in the source code. These enable or disable diagnostic messages.
Expand Down Expand Up @@ -432,6 +440,8 @@ export class BrsFile {
let functions = this.parser.references.functionExpressions;

//create a functionScope for every function
this._functionScopes = [];

for (let func of functions) {
let scope = new FunctionScope(func);

Expand Down Expand Up @@ -460,7 +470,7 @@ export class BrsFile {
this.scopesByFunc.set(func, scope);

//find every statement in the scope
this.functionScopes.push(scope);
this._functionScopes.push(scope);
}

//find every variable assignment in the whole file
Expand Down

0 comments on commit dd84831

Please sign in to comment.