Skip to content

Commit

Permalink
Rename Program addOrReplaceFile to `setFile
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed May 6, 2021
1 parent da2025f commit ce53294
Show file tree
Hide file tree
Showing 21 changed files with 545 additions and 545 deletions.
6 changes: 3 additions & 3 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ describe('LanguageServer', () => {
${additionalXmlContents}
<script type="text/brightscript" uri="${name}.brs" />
</component>`;
program.addOrReplaceFile(filePath, contents);
program.setFile(filePath, contents);
}

function addScriptFile(name: string, contents: string, extension = 'brs') {
const pkgPath = `pkg:/components/${name}.${extension}`;
const file = program.addOrReplaceFile<XmlFile>(pkgPath, contents);
const file = program.setFile<XmlFile>(pkgPath, contents);
const document = TextDocument.create(util.pathToUri(file.srcPath), 'brightscript', 1, contents);
svr.documents._documents[document.uri] = document;
return document;
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('LanguageServer', () => {
getFileContents: sinon.stub().callsFake(() => Promise.resolve('')) as any,
rootDir: rootDir,
program: {
addOrReplaceFile: <any>addOrReplaceFileStub
setFile: <any>addOrReplaceFileStub
}
}
} as Workspace;
Expand Down
6 changes: 3 additions & 3 deletions src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ export class LanguageServer {

//if we got a dest path, then the program wants this file
if (destPath) {
program.addOrReplaceFile(
program.setFile(
{
src: change.srcPath,
dest: rokuDeploy.getDestPath(change.srcPath, options.files, rootDir)
Expand All @@ -856,7 +856,7 @@ export class LanguageServer {
//sometimes "changed" events are emitted on files that were actually deleted,
//so determine file existance and act accordingly
if (await util.pathExists(change.srcPath)) {
program.addOrReplaceFile(
program.setFile(
{
src: change.srcPath,
dest: rokuDeploy.getDestPath(change.srcPath, options.files, rootDir)
Expand Down Expand Up @@ -932,7 +932,7 @@ export class LanguageServer {
if (workspace.builder.program.hasFile(filePath)) {
let rootDir = workspace.builder.program.options.rootDir ?? workspace.builder.program.options.cwd;
let dest = rokuDeploy.getDestPath(filePath, workspace.builder.program.options.files, rootDir);
workspace.builder.program.addOrReplaceFile({
workspace.builder.program.setFile({
src: filePath,
dest: dest
}, documentText);
Expand Down
350 changes: 175 additions & 175 deletions src/Program.spec.ts

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,15 @@ export class Program {
/**
* Update internal maps with this file reference
*/
private setFile(file: BscFile) {
private assignFile(file: BscFile) {
this.files[file.srcPath.toLowerCase()] = file;
this.pkgMap[file.pkgPath.toLowerCase()] = file;
}

/**
* Remove this file from internal maps
*/
private unsetFile(file: BscFile) {
private unassignFile(file: BscFile) {
delete this.files[file.srcPath.toLowerCase()];
delete this.pkgMap[file.pkgPath.toLowerCase()];
}
Expand All @@ -364,14 +364,14 @@ export class Program {
* @param srcDestOrPkgPath the absolute path, or the pkg path (i.e. `pkg:/path/to/file.brs`) or the destPath (i.e. `path/to/file.brs` relative to `pkg:/`)
* @param fileContents the file contents
*/
public addOrReplaceFile<T extends BscFile>(srcDestOrPkgPath: string, fileContents: string): T;
public setFile<T extends BscFile>(srcDestOrPkgPath: string, fileContents: string): T;
/**
* Load a file into the program. If that file already exists, it is replaced.
* @param fileEntry an object that specifies src and dest for the file.
* @param fileContents the file contents. If not provided, the file will be loaded from disk
*/
public addOrReplaceFile<T extends BscFile>(fileEntry: FileObj, fileContents: string): T;
public addOrReplaceFile<T extends BscFile>(fileParam: FileObj | string, fileContents: string): T {
public setFile<T extends BscFile>(fileEntry: FileObj, fileContents: string): T;
public setFile<T extends BscFile>(fileParam: FileObj | string, fileContents: string): T {
assert.ok(fileParam, 'fileParam is required');
let srcPath: string;
let pkgPath: string;
Expand Down Expand Up @@ -434,7 +434,7 @@ export class Program {
}

//add the file to the program
this.setFile(brsFile);
this.assignFile(brsFile);

this.plugins.emit('beforeFileParse', beforeFileParseEvent);

Expand All @@ -457,7 +457,7 @@ export class Program {
) {
let xmlFile = new XmlFile(srcPath, pkgPath, this);

this.setFile(xmlFile);
this.assignFile(xmlFile);

//add the file to the program
this.plugins.emit('beforeFileParse', beforeFileParseEvent);
Expand Down Expand Up @@ -547,7 +547,7 @@ export class Program {
});
}
//remove the file from the program
this.unsetFile(file);
this.unassignFile(file);

this.dependencyGraph.remove(file.dependencyGraphKey);

Expand Down
4 changes: 2 additions & 2 deletions src/ProgramBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('ProgramBuilder', () => {
dest: 'file4.xml'
}]));

let stub = sinon.stub(builder.program, 'addOrReplaceFile');
let stub = sinon.stub(builder.program, 'setFile');
sinon.stub(builder, 'getFileContents').returns(Promise.resolve(''));
await builder['loadAllFilesAST']();
expect(stub.getCalls()).to.be.lengthOf(3);
Expand All @@ -70,7 +70,7 @@ describe('ProgramBuilder', () => {
fsExtra.outputFileSync(s`${rootDir}/source/main.d.bs`, '');
fsExtra.outputFileSync(s`${rootDir}/source/lib.d.bs`, '');
fsExtra.outputFileSync(s`${rootDir}/source/lib.brs`, '');
const stub = sinon.stub(builder.program, 'addOrReplaceFile');
const stub = sinon.stub(builder.program, 'setFile');
await builder['loadAllFilesAST']();
const srcPaths = stub.getCalls().map(x => x.args[0].src);
//the d files should be first
Expand Down
6 changes: 3 additions & 3 deletions src/ProgramBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class ProgramBuilder {
util.driveLetterToLower(this.rootDir)
)
};
this.program.addOrReplaceFile(
this.program.setFile(
fileObj,
await this.getFileContents(fileObj.src, false)
);
Expand Down Expand Up @@ -470,7 +470,7 @@ export class ProgramBuilder {
await Promise.all(
typedefFiles.map(async (fileObj) => {
try {
this.program.addOrReplaceFile(
this.program.setFile(
fileObj,
await this.getFileContents(fileObj.src)
);
Expand All @@ -490,7 +490,7 @@ export class ProgramBuilder {

//only process certain file types
if (acceptableExtensions.includes(fileExtension)) {
this.program.addOrReplaceFile(
this.program.setFile(
fileObj,
await this.getFileContents(fileObj.src)
);
Expand Down

0 comments on commit ce53294

Please sign in to comment.