Skip to content

Commit

Permalink
Merge branch 'master' into webpack-build
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron authored Oct 2, 2019
2 parents 2bd2bd2 + 5ec6ddd commit a2a1da5
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 13 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).



## [1.20.0] - 2019-10-01
### Added
- "port is in use" crash message when serving component libraries
### Changed
- The Roku stacktrace includes all function names back as fully lower case. The extension reads the original files and attempts to find the correct case for every function. These results were not being cached, but are now cached in order to improve performance.
### Fixed
- some syntax colors related to object function calls



## [1.19.6] - 2019-09-23
### Fixed
- bugs in language grammar (syntax highlighting)
Expand Down Expand Up @@ -351,6 +363,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



[1.20.0]: https://github.com/RokuCommunity/vscode-brightscript-language/compare/v1.19.6...v1.20.0
[1.19.6]: https://github.com/RokuCommunity/vscode-brightscript-language/compare/v1.19.5...v1.19.6
[1.19.5]: https://github.com/RokuCommunity/vscode-brightscript-language/compare/v1.19.4...v1.19.5
[1.19.4]: https://github.com/RokuCommunity/vscode-brightscript-language/compare/v1.19.3...v1.19.4
Expand Down
15 changes: 14 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "brightscript",
"displayName": "BrightScript Language",
"version": "1.19.6",
"version": "1.20.0",
"publisher": "celsoaf",
"description": "Language support for Roku's BrightScript language.",
"author": {
Expand Down Expand Up @@ -49,6 +49,7 @@
"fast-xml-parser": "^3.12.16",
"find-in-files": "^0.5.0",
"fs-extra": "^7.0.1",
"get-port": "^5.0.0",
"glob": "^7.1.3",
"hoek": "^6.1.2",
"iconv-lite": "0.4.24",
Expand Down
41 changes: 36 additions & 5 deletions src/BrightScriptDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,38 @@ export class BrightScriptDebugSession extends DebugSession {
this.sendResponse(response);
}

/**
* The stacktrace sent by Roku forces all BrightScript function names to lower case.
* This function will scan the source file, and attempt to find the exact casing from the function definition.
* Also, this function caches results, so it should be drastically faster than the previous implementation
* that would read the source file every time
*/
private async getCorrectFunctionNameCase(sourceFilePath: string, functionName: string) {
let lowerSourceFilePath = sourceFilePath.toLowerCase();
let lowerFunctionName = functionName.toLowerCase();
//create the lookup if it doesn't exist
if (!this.functionNameCaseLookup[lowerSourceFilePath]) {
this.functionNameCaseLookup[lowerSourceFilePath] = {};

let fileContents = (await fsExtra.readFile(sourceFilePath)).toString();
//read the file contents
let regexp = /^\s*(?:sub|function)\s+([a-z0-9_]+)/gim;
let match: RegExpMatchArray;

//create a cache of all function names in this file
while (match = regexp.exec(fileContents)) {
let correctFunctionName = match[1];
this.functionNameCaseLookup[lowerSourceFilePath][correctFunctionName.toLowerCase()] = correctFunctionName;
}
}
return this.functionNameCaseLookup[lowerSourceFilePath][lowerFunctionName];
}
private functionNameCaseLookup = {} as {
[lowerSourceFilePath: string]: {
[lowerFunctionName: string]: string
}
};

protected async stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments) {
this.log('stackTraceRequest');
let frames = [];
Expand All @@ -672,18 +704,17 @@ export class BrightScriptDebugSession extends DebugSession {
let stackTrace = await this.rokuAdapter.getStackTrace();

for (let debugFrame of stackTrace) {

let clientPath = this.convertDebuggerPathToClient(debugFrame.filePath);
let clientLineNumber = this.convertDebuggerLineToClientLine(debugFrame.filePath, debugFrame.lineNumber);
//the stacktrace returns function identifiers in all lower case. Try to get the actual case
//load the contents of the file and get the correct casing for the function identifier
try {
let fileContents = (await fsExtra.readFile(clientPath)).toString();
let match = new RegExp(`(?:sub|function)\\s+(${debugFrame.functionIdentifier})`, 'i').exec(fileContents);
if (match) {
debugFrame.functionIdentifier = match[1];
let functionName = await this.getCorrectFunctionNameCase(clientPath, debugFrame.functionIdentifier);
if (functionName) {
debugFrame.functionIdentifier = functionName;
}
} catch (e) {
console.error(e);
}

let frame = new StackFrame(
Expand Down
7 changes: 7 additions & 0 deletions src/ComponentLibraryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import * as os from 'os';
import * as path from 'path';
import * as url from 'url';

import { util } from './util';

export class ComponentLibraryServer {

public componentLibrariesOutDir: string;

public startStaticFileHosting(componentLibrariesOutDir: string, port: number, sendDebugLogLine) {

// Make sure the requested port is not already being used by another service
if (util.isPortInUse(port)) {
throw new Error(`Could not host component library files.\nPort ${port} is currently occupied.`);
}

this.componentLibrariesOutDir = componentLibrariesOutDir;

// #region prepare static file hosting
Expand Down
28 changes: 28 additions & 0 deletions src/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import * as assert from 'assert';
import { expect } from 'chai';
import * as fsExtra from 'fs-extra';
import * as getPort from 'get-port';
import * as net from 'net';
import * as path from 'path';
import * as sinonActual from 'sinon';

Expand Down Expand Up @@ -135,6 +137,32 @@ describe('Util', () => {
});
});

describe('isPortInUse', () => {
let otherServer: net.Server;
let port: number;

beforeEach(async () => {
port = await getPort();
otherServer = await new Promise<net.Server>((resolve, reject) => {
const tester = net.createServer()
.once('listening', () => resolve(tester))
.listen(port);
});
});

it('should detect when a port is in use', async () => {
assert.equal(true, await util.isPortInUse(port));
});

it('should detect when a port is not in use', async () => {
assert.equal(false, await util.isPortInUse(port + 1));
});

afterEach(async () => {
await otherServer.close();
});
});

describe('objectDiff', () => {
let objectA;
let objectB;
Expand Down
14 changes: 14 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as fsExtra from 'fs-extra';
import * as net from 'net';
import * as path from 'path';

const extensions = ['.js', '.ts', '.json', '.jsx', '.tsx', '.vue', '.css', '.mcss', '.scss', '.less', '.html'];
Expand Down Expand Up @@ -115,6 +116,19 @@ class Util {
}
}

/**
* Checks to see if the port is already in use
* @param port target port to check
*/
public async isPortInUse(port: number): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
const tester = net.createServer()
.once('error', (err: any) => (err.code === 'EADDRINUSE' ? resolve(true) : reject(err)))
.once('listening', () => tester.once('close', () => resolve(false)).close())
.listen(port);
});
}

/**
* With return the differences in two objects
* @param obj1 base target
Expand Down
9 changes: 3 additions & 6 deletions syntaxes/brightscript.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,9 @@
]
},
"object_properties": {
"match": "(?i:\\b([a-z_][a-z0-9_]*)\\.([a-z_][a-z0-9_]*))",
"match": "(?i:\\b\\.((?:[a-z0-9_])*)(?!\\s*\\()\\b)",
"captures": {
"1": {
"name": "entity.name.variable.local.brs"
},
"2": {
"name": "variable.other.object.property.brs"
}
}
Expand Down Expand Up @@ -191,7 +188,7 @@
"name": "entity.name.variable.local.brs"
}
},
"match": "(?i:\\b([a-z_][a-z0-9_\\$%!#]*)\\b)"
"match": "(?i:\\b(?<!\\.)([a-z_][a-z0-9_\\$%!#]*)\\b)"
},
"storage_types": {
"comment": "Included 'dim' because it didn't warrant its own matcher",
Expand Down Expand Up @@ -336,4 +333,4 @@
"name": "keyword.preprocessor.brs"
}
}
}
}

0 comments on commit a2a1da5

Please sign in to comment.