Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setFile method, deprecate addOrReplaceFile #510

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/targets/parse-brs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = async (suite, name, brighterscript, projectPath, options) => {
const promises = [];
for (const file of files) {
promises.push(
builder.program.addOrReplaceFile(file.pkgPath, file.fileContents)
(builder.program.addOrReplaceFile ?? builder.program.setFile)(file.pkgPath, file.fileContents)
);
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Expand Down
2 changes: 1 addition & 1 deletion scripts/compile-doc-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class DocCompiler {
//use the current bsconfig
...(this.bsconfig ?? {})
});
const file = program.addOrReplaceFile({ src: `${__dirname}/rootDir/source/main.bs`, dest: 'source/main.bs' }, code);
const file = program.setFile({ src: `${__dirname}/rootDir/source/main.bs`, dest: 'source/main.bs' }, code);
program.validate();
let tranpileResult = file.transpile();
return tranpileResult.code;
Expand Down
2 changes: 1 addition & 1 deletion src/FunctionScope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('FunctionScope', () => {
});

it('returns variables defined above the specified line number', () => {
let file = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub main()
var1 = 1
var2 = 2
Expand Down
14 changes: 7 additions & 7 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,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 filePath = s`components/${name}.${extension}`;
const file = program.addOrReplaceFile(filePath, contents);
const file = program.setFile(filePath, contents);
if (file) {
const document = TextDocument.create(util.pathToUri(file.pathAbsolute), 'brightscript', 1, contents);
svr.documents._documents[document.uri] = document;
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('LanguageServer', () => {

describe('handleFileChanges', () => {
it('only adds files that match the files array', async () => {
let addOrReplaceFileStub = sinon.stub().returns(Promise.resolve());
let setFileStub = sinon.stub().returns(Promise.resolve());
const workspace = {
builder: {
options: {
Expand All @@ -282,7 +282,7 @@ describe('LanguageServer', () => {
getFileContents: sinon.stub().callsFake(() => Promise.resolve('')) as any,
rootDir: rootDir,
program: {
addOrReplaceFile: <any>addOrReplaceFileStub
setFile: <any>setFileStub
}
}
} as Workspace;
Expand All @@ -295,20 +295,20 @@ describe('LanguageServer', () => {
pathAbsolute: mainPath
}]);

expect(addOrReplaceFileStub.getCalls()[0]?.args[0]).to.eql({
expect(setFileStub.getCalls()[0]?.args[0]).to.eql({
src: mainPath,
dest: s`source/main.brs`
});

let libPath = s`${rootDir}/components/lib.brs`;

expect(addOrReplaceFileStub.callCount).to.equal(1);
expect(setFileStub.callCount).to.equal(1);
await server.handleFileChanges(workspace, [{
type: FileChangeType.Created,
pathAbsolute: libPath
}]);
//the function should have ignored the lib file, so no additional files were added
expect(addOrReplaceFileStub.callCount).to.equal(1);
expect(setFileStub.callCount).to.equal(1);
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ export class LanguageServer {

//if we got a dest path, then the program wants this file
if (destPath) {
program.addOrReplaceFile(
program.setFile(
{
src: change.pathAbsolute,
dest: rokuDeploy.getDestPath(change.pathAbsolute, options.files, rootDir)
Expand All @@ -864,7 +864,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.pathAbsolute)) {
program.addOrReplaceFile(
program.setFile(
{
src: change.pathAbsolute,
dest: rokuDeploy.getDestPath(change.pathAbsolute, options.files, rootDir)
Expand Down Expand Up @@ -930,7 +930,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
Loading