Skip to content
Open
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
40 changes: 0 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"@types/dateformat": "~3",
"@types/debounce": "^1.2.1",
"@types/dedent": "^0.7.0",
"@types/find-in-files": "^0.5.1",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/mocha": "^10.0.10",
Expand Down Expand Up @@ -111,7 +110,6 @@
"eol": "^0.9.1",
"eventemitter3": "^4.0.7",
"fast-glob": "^3.2.11",
"find-in-files": "^0.5.0",
"fs-extra": "^10.0.0",
"glob": "^7.2.0",
"natural-orderby": "^2.0.3",
Expand Down
49 changes: 0 additions & 49 deletions src/FileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as findInFiles from 'find-in-files';
import * as fsExtra from 'fs-extra';
import * as glob from 'glob';
import * as path from 'path';
import { promisify } from 'util';
import { util as rokuDeployUtil } from 'roku-deploy';
const globp = promisify(glob);

export class FileUtils {
Expand Down Expand Up @@ -253,53 +251,6 @@ export class FileUtils {
return result;
}

/**
* Given a path to a folder, search all files until an entry point is found.
* (An entry point is a function that roku uses as the Main function to start the program).
* @param projectPath - a path to a Roku project
*/
public async findEntryPoint(projectPath: string) {
let results = {
...await findInFiles.find({ term: 'sub\\s+RunScreenSaver\\s*\\(', flags: 'ig' }, projectPath, /.*\.brs/),
...await findInFiles.find({ term: 'function\\s+RunScreenSaver\\s*\\(', flags: 'ig' }, projectPath, /.*\.brs/),
...await findInFiles.find({ term: 'sub\\s+RunUserInterface\\s*\\(', flags: 'ig' }, projectPath, /.*\.brs/),
...await findInFiles.find({ term: 'function\\s+RunUserInterface\\s*\\(', flags: 'ig' }, projectPath, /.*\.brs/),
...await findInFiles.find({ term: 'sub\\s+main\\s*\\(', flags: 'ig' }, projectPath, /.*\.brs/),
...await findInFiles.find({ term: 'function\\s+main\\s*\\(', flags: 'ig' }, projectPath, /.*\.brs/)
};
let keys = Object.keys(results);
if (keys.length === 0) {
throw new Error('Unable to find an entry point. Please make sure that you have a RunUserInterface, RunScreenSaver, or Main sub/function declared in your BrightScript project');
}

let entryPath = keys[0];

let entryLineContents = results[entryPath].line[0];

let lineNumber: number;
//load the file contents
let contents = await fsExtra.readFile(entryPath);
let lines = contents.toString().split(/\r?\n/g);
//loop through the lines until we find the entry line
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
if (line.includes(entryLineContents)) {
lineNumber = i + 1;
break;
}
}
let relativePath = fileUtils.removeLeadingSlash(
rokuDeployUtil.stringReplaceInsensitive(entryPath, projectPath, '')
);

return {
relativePath: relativePath,
pathAbsolute: entryPath,
contents: entryLineContents,
lineNumber: lineNumber
};
}

/**
* If a string has a leading slash, remove it
*/
Expand Down
77 changes: 0 additions & 77 deletions src/debugSession/BrightScriptDebugSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { DebugProtocol } from '@vscode/debugprotocol/lib/debugProtocol';
import { DebugSession, InitializedEvent, Logger as DapLogger, logger as dapLogger, OutputEvent, ProgressEndEvent, ProgressStartEvent, ProgressUpdateEvent } from '@vscode/debugadapter';
import { BrightScriptDebugSession } from './BrightScriptDebugSession';
import type { AugmentedVariable } from './BrightScriptDebugSession';
import { fileUtils } from '../FileUtils';
import type { StackFrame } from '../adapters/TelnetAdapter';
import { PrimativeType, TelnetAdapter } from '../adapters/TelnetAdapter';
import { defer, util } from '../util';
Expand Down Expand Up @@ -999,81 +998,6 @@ describe('BrightScriptDebugSession', () => {
});
});

describe('findMainFunction', () => {
let folder;
afterEach(() => {
fsExtra.emptyDirSync('./.tmp');
fsExtra.rmdirSync('./.tmp');
});

async function doTest(fileContents: string, lineContents: string, lineNumber: number) {
fsExtra.emptyDirSync('./.tmp');
folder = path.resolve('./.tmp/findMainFunctionTests/');
fsExtra.mkdirSync(folder);

let filePath = path.resolve(`${folder}/main.brs`);

//prevent actually talking to the file system...just hardcode the list to exactly our main file
(session.rokuDeploy as any).getFilePaths = () => {
return [{
src: filePath,
dest: filePath
}];
};

fsExtra.writeFileSync(filePath, fileContents);
(session as any).launchConfiguration = {
files: [
folder + '/**/*'
]
};
let entryPoint = await fileUtils.findEntryPoint(folder);
expect(entryPoint.pathAbsolute).to.equal(filePath);
expect(entryPoint.lineNumber).to.equal(lineNumber);
expect(entryPoint.contents).to.equal(lineContents);
}

it('works for RunUserInterface', async () => {
await doTest('\nsub RunUserInterface()\nend sub', 'sub RunUserInterface()', 2);
//works with args
await doTest('\n\nsub RunUserInterface(args as Dynamic)\nend sub', 'sub RunUserInterface(args as Dynamic)', 3);
//works with extra spacing
await doTest('\n\nsub RunUserInterface()\nend sub', 'sub RunUserInterface()', 3);
await doTest('\n\nsub RunUserInterface ()\nend sub', 'sub RunUserInterface ()', 3);
});

it('works for sub main', async () => {
await doTest('\nsub Main()\nend sub', 'sub Main()', 2);
//works with args
await doTest('sub Main(args as Dynamic)\nend sub', 'sub Main(args as Dynamic)', 1);
//works with extra spacing
await doTest('sub Main()\nend sub', 'sub Main()', 1);
await doTest('sub Main ()\nend sub', 'sub Main ()', 1);
});

it('works for function main', async () => {
await doTest('function Main()\nend function', 'function Main()', 1);
await doTest('function Main(args as Dynamic)\nend function', 'function Main(args as Dynamic)', 1);
//works with extra spacing
await doTest('function Main()\nend function', 'function Main()', 1);
await doTest('function Main ()\nend function', 'function Main ()', 1);
});

it('works for sub RunScreenSaver', async () => {
await doTest('sub RunScreenSaver()\nend sub', 'sub RunScreenSaver()', 1);
//works with extra spacing
await doTest('sub RunScreenSaver()\nend sub', 'sub RunScreenSaver()', 1);
await doTest('sub RunScreenSaver ()\nend sub', 'sub RunScreenSaver ()', 1);
});

it('works for function RunScreenSaver', async () => {
await doTest('function RunScreenSaver()\nend function', 'function RunScreenSaver()', 1);
//works with extra spacing
await doTest('function RunScreenSaver()\nend function', 'function RunScreenSaver()', 1);
await doTest('function RunScreenSaver ()\nend function', 'function RunScreenSaver ()', 1);
});
});

describe('initRendezvousTracking', () => {
it('clears history when disabled', async () => {
const stub = sinon.stub(session, 'sendEvent');
Expand Down Expand Up @@ -1185,7 +1109,6 @@ describe('BrightScriptDebugSession', () => {
let stub = sinon.stub(session.projectManager, 'registerEntryBreakpoint').returns(Promise.resolve());
await session.handleEntryBreakpoint();
expect(stub.called).to.be.true;
expect(stub.args[0][0]).to.equal(stagingDir);
});
it('does NOT register the entry breakpoint when stopOnEntry is enabled', async () => {
(session as any).launchConfiguration = { stopOnEntry: false };
Expand Down
2 changes: 1 addition & 1 deletion src/debugSession/BrightScriptDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3322,7 +3322,7 @@ export class BrightScriptDebugSession extends LoggingDebugSession {
if (!this.enableDebugProtocol) {
this.entryBreakpointWasHandled = true;
if (this.launchConfiguration.stopOnEntry || this.launchConfiguration.deepLinkUrl) {
await this.projectManager.registerEntryBreakpoint(this.projectManager.mainProject.stagingDir);
await this.projectManager.registerEntryBreakpoint();
}
}
}
Expand Down
Loading