This commit is contained in:
Ramya Achutha Rao 2019-03-02 19:45:04 -08:00
Родитель 4dec459432
Коммит 3703d35f50
22 изменённых файлов: 186 добавлений и 70 удалений

Просмотреть файл

@ -132,21 +132,21 @@ export class NearestNeighborDict<K, V> {
public static NUMERIC_DISTANCE_FUNCTION = (a: number, b: number) => a > b ? a - b : b - a;
public static DEFAULT_COMPARE_FUNCTION = (a: any, b: any) => a > b ? 1 : a < b ? -1 : 0;
protected _root: Node<K, V> = null;
protected root: Node<K, V> = null;
/**
* Creates a new AVL Tree.
*/
constructor(
start: Node<K, V>,
private _distance: DistanceFunction<K>,
private _compare: CompareFunction<K> = NearestNeighborDict.DEFAULT_COMPARE_FUNCTION
private distance: DistanceFunction<K>,
private compare: CompareFunction<K> = NearestNeighborDict.DEFAULT_COMPARE_FUNCTION
) {
this.insert(start.key, start.value);
}
public height() {
return this._root.height;
return this.root.height;
}
/**
@ -155,7 +155,7 @@ export class NearestNeighborDict<K, V> {
* @param value The value being inserted.
*/
public insert(key: K, value?: V): void {
this._root = this._insert(key, value, this._root);
this.root = this._insert(key, value, this.root);
}
/**
@ -170,9 +170,9 @@ export class NearestNeighborDict<K, V> {
return new Node(key, value);
}
if (this._compare(key, root.key) < 0) {
if (this.compare(key, root.key) < 0) {
root.left = this._insert(key, value, root.left);
} else if (this._compare(key, root.key) > 0) {
} else if (this.compare(key, root.key) > 0) {
root.right = this._insert(key, value, root.right);
} else {
return root;
@ -183,7 +183,7 @@ export class NearestNeighborDict<K, V> {
const balanceState = this._getBalanceState(root);
if (balanceState === BalanceState.UNBALANCED_LEFT) {
if (this._compare(key, root.left.key) < 0) {
if (this.compare(key, root.left.key) < 0) {
// Left left case
root = root.rotateRight();
} else {
@ -194,7 +194,7 @@ export class NearestNeighborDict<K, V> {
}
if (balanceState === BalanceState.UNBALANCED_RIGHT) {
if (this._compare(key, root.right.key) > 0) {
if (this.compare(key, root.right.key) > 0) {
// Right right case
root = root.rotateLeft();
} else {
@ -213,7 +213,7 @@ export class NearestNeighborDict<K, V> {
* @return The (key, value) pair of the node with key nearest the given key in value.
*/
public getNearest(key: K): Node<K, V> {
return this._getNearest(key, this._root, this._root);
return this._getNearest(key, this.root, this.root);
}
/**
@ -224,12 +224,12 @@ export class NearestNeighborDict<K, V> {
* @return The (key, value) pair of the node with key nearest the given key in value.
*/
private _getNearest(key: K, root: Node<K, V>, closest: Node<K, V>): Node<K, V> {
const result = this._compare(key, root.key);
const result = this.compare(key, root.key);
if (result === 0) {
return root;
}
closest = this._distance(key, root.key) < this._distance(key, closest.key) ? root : closest;
closest = this.distance(key, root.key) < this.distance(key, closest.key) ? root : closest;
if (result < 0) {
return root.left ? this._getNearest(key, root.left, closest) : closest;
@ -260,4 +260,4 @@ export class NearestNeighborDict<K, V> {
}
}
}
}
}

Просмотреть файл

@ -357,7 +357,7 @@ class Delve {
logError('Process exiting with code: ' + code);
if (this.onclose) { this.onclose(code); }
});
this.debugProcess.on('error', function (err) {
this.debugProcess.on('error', function(err) {
reject(err);
});
resolve();
@ -465,7 +465,7 @@ class Delve {
logError('Process exiting with code: ' + code);
if (this.onclose) { this.onclose(code); }
});
this.debugProcess.on('error', function (err) {
this.debugProcess.on('error', function(err) {
reject(err);
});
});
@ -548,7 +548,7 @@ class Delve {
class GoDebugSession extends LoggingDebugSession {
private _variableHandles: Handles<DebugVariable>;
private variableHandles: Handles<DebugVariable>;
private breakpoints: Map<string, DebugBreakpoint[]>;
private skipStopEventOnce: boolean; // Editing breakpoints requires halting delve, skip sending Stop Event to VS Code in such cases
private goroutines: Set<number>;
@ -565,7 +565,7 @@ class GoDebugSession extends LoggingDebugSession {
private showGlobalVariables: boolean = false;
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) {
super('', debuggerLinesStartAt1, isServer);
this._variableHandles = new Handles<DebugVariable>();
this.variableHandles = new Handles<DebugVariable>();
this.skipStopEventOnce = false;
this.goroutines = new Set<number>();
this.debugState = null;
@ -955,7 +955,7 @@ class GoDebugSession extends LoggingDebugSession {
fullyQualifiedName: '',
};
scopes.push(new Scope('Local', this._variableHandles.create(localVariables), false));
scopes.push(new Scope('Local', this.variableHandles.create(localVariables), false));
response.body = { scopes };
if (!this.showGlobalVariables) {
@ -1005,7 +1005,7 @@ class GoDebugSession extends LoggingDebugSession {
unreadable: '',
fullyQualifiedName: '',
};
scopes.push(new Scope('Global', this._variableHandles.create(globalVariables), false));
scopes.push(new Scope('Global', this.variableHandles.create(globalVariables), false));
this.sendResponse(response);
log('ScopesResponse');
});
@ -1067,23 +1067,23 @@ class GoDebugSession extends LoggingDebugSession {
}
return {
result: `<${v.type}>(0x${v.children[0].addr.toString(16)})`,
variablesReference: v.children.length > 0 ? this._variableHandles.create(v) : 0
variablesReference: v.children.length > 0 ? this.variableHandles.create(v) : 0
};
}
} else if (v.kind === GoReflectKind.Slice) {
return {
result: '<' + v.type + '> (length: ' + v.len + ', cap: ' + v.cap + ')',
variablesReference: this._variableHandles.create(v)
variablesReference: this.variableHandles.create(v)
};
} else if (v.kind === GoReflectKind.Map) {
return {
result: '<' + v.type + '> (length: ' + v.len + ')',
variablesReference: this._variableHandles.create(v)
variablesReference: this.variableHandles.create(v)
};
} else if (v.kind === GoReflectKind.Array) {
return {
result: '<' + v.type + '>',
variablesReference: this._variableHandles.create(v)
variablesReference: this.variableHandles.create(v)
};
} else if (v.kind === GoReflectKind.String) {
let val = v.value;
@ -1105,14 +1105,14 @@ class GoDebugSession extends LoggingDebugSession {
}
return {
result: v.value || ('<' + v.type + '>'),
variablesReference: v.children.length > 0 ? this._variableHandles.create(v) : 0
variablesReference: v.children.length > 0 ? this.variableHandles.create(v) : 0
};
}
}
protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): void {
log('VariablesRequest');
let vari = this._variableHandles.get(args.variablesReference);
let vari = this.variableHandles.get(args.variablesReference);
let variablesPromise: Promise<DebugProtocol.Variable[]>;
const loadChildren = async (exp: string, v: DebugVariable) => {
// from https://github.com/go-delve/delve/blob/master/Documentation/api/ClientHowto.md#looking-into-variables
@ -1176,7 +1176,7 @@ class GoDebugSession extends LoggingDebugSession {
}
private cleanupHandles(): void {
this._variableHandles.reset();
this.variableHandles.reset();
this.stackFrameHandles.reset();
}

Просмотреть файл

@ -21,4 +21,4 @@ export abstract class GoBaseCodeLensProvider implements vscode.CodeLensProvider
return [];
}
}
}

Просмотреть файл

@ -88,7 +88,9 @@ export function updateCodeCoverageDecorators(coverageDecoratorConfig: any) {
decoratorConfig.type = coverageDecoratorConfig;
} else {
for (let k in coverageDecoratorConfig) {
decoratorConfig[k] = coverageDecoratorConfig[k];
if (coverageDecoratorConfig.hasOwnProperty(k)) {
decoratorConfig[k] = coverageDecoratorConfig[k];
}
}
}
setDecorators();
@ -150,7 +152,7 @@ export function applyCodeCoverageToAllEditors(coverProfilePath: string, packageD
output: undefined
});
lines.on('line', function (data: string) {
lines.on('line', function(data: string) {
// go test coverageprofile generates output:
// filename:StartLine.StartColumn,EndLine.EndColumn Hits CoverCount
// The first line will be "mode: set" which will be ignored
@ -325,4 +327,4 @@ export function isPartOfComment(e: vscode.TextDocumentChangeEvent): boolean {
const idx = text.search('//');
return (idx > -1 && idx <= change.range.start.character);
});
}
}

Просмотреть файл

@ -106,4 +106,4 @@ export class GoDocumentFormattingEditProvider implements vscode.DocumentFormatti
}
});
}
}
}

Просмотреть файл

@ -57,4 +57,4 @@ function runGoImpl(args: string[], insertPos: vscode.Position) {
if (p.pid) {
p.stdin.end();
}
}
}

Просмотреть файл

@ -44,4 +44,4 @@ export function installCurrentPackage() {
cp.execFile(goRuntimePath, args, { env, cwd }, (err, stdout, stderr) => {
outputChannel.appendLine(err ? `Installation failed: ${stderr}` : `Installation successful`);
});
}
}

Просмотреть файл

@ -15,7 +15,7 @@ import { goLiveErrorsEnabled } from './goLiveErrors';
let updatesDeclinedTools: string[] = [];
let installsDeclinedTools: string[] = [];
const _allTools: { [key: string]: string } = {
const allToolsWithImportPaths: { [key: string]: string } = {
'gocode': 'github.com/mdempsky/gocode',
'gocode-gomod': 'github.com/stamblerre/gocode',
'gopkgs': 'github.com/uudashr/gopkgs/cmd/gopkgs',
@ -47,7 +47,7 @@ function getToolImportPath(tool: string, goVersion: SemVersion) {
if (tool === 'gocode' && goVersion && goVersion.major < 2 && goVersion.minor < 9) {
return 'github.com/nsf/gocode';
}
return _allTools[tool];
return allToolsWithImportPaths[tool];
}
// Tools used explicitly by the basic features of the extension

Просмотреть файл

@ -46,7 +46,7 @@ export function parseLiveFile(e: vscode.TextDocumentChangeEvent) {
if (runner != null) {
clearTimeout(runner);
}
runner = setTimeout(function () {
runner = setTimeout(function() {
processFile(e);
runner = null;
}, vscode.workspace.getConfiguration('go', e.document.uri)['liveErrors']['delay']);

Просмотреть файл

@ -144,4 +144,4 @@ function runGomodifytags(args: string[]) {
if (p.pid) {
p.stdin.end(input);
}
}
}

Просмотреть файл

@ -156,4 +156,4 @@ export function getCurrentPackage(cwd: string): Promise<string> {
resolve(pkgs[0]);
});
});
}
}

Просмотреть файл

@ -98,7 +98,7 @@ function gopkgs(workDir?: string): Promise<Map<string, string>> {
function getAllPackagesNoCache(workDir: string): Promise<Map<string, string>> {
return new Promise<Map<string, string>>((resolve, reject) => {
// Use subscription style to guard costly/long running invocation
let callback = function (pkgMap: Map<string, string>) {
let callback = function(pkgMap: Map<string, string>) {
resolve(pkgMap);
};

Просмотреть файл

@ -138,7 +138,7 @@ export function parseEnvFile(path: string): { [key: string]: string } {
});
return env;
} catch (e) {
throw (`Cannot load environment variables from file ${path}`);
throw new Error(`Cannot load environment variables from file ${path}`);
}
}
@ -190,4 +190,4 @@ export function getCurrentGoWorkspaceFromGOPATH(gopath: string, currentFileDirPa
// Workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
export function fixDriveCasingInWindows(pathToFix: string): string {
return (process.platform === 'win32' && pathToFix) ? pathToFix.substr(0, 1).toUpperCase() + pathToFix.substr(1) : pathToFix;
}
}

Просмотреть файл

@ -96,4 +96,4 @@ export class GoReferencesCodeLensProvider extends GoBaseCodeLensProvider {
);
});
}
}
}

Просмотреть файл

@ -141,4 +141,4 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
return Promise.all([testPromise, benchmarkPromise]).then(() => codelens);
}
}
}

Просмотреть файл

@ -67,8 +67,7 @@ export class GoSignatureHelpProvider implements SignatureHelpProvider {
result.activeSignature = 0;
result.activeParameter = Math.min(theCall.commas.length, si.parameters.length - 1);
return result;
}
catch (e) {
} catch (e) {
return null;
}
}
@ -125,4 +124,4 @@ export class GoSignatureHelpProvider implements SignatureHelpProvider {
}
return null;
}
}
}

Просмотреть файл

@ -127,7 +127,7 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider,
if (memberType && memberType.length === 4) {
suggestionItem = new vscode.CompletionItem(memberType[3], vscodeKindFromGoCodeClass(memberType[1], ''));
}
return resolve(suggestionItem ? [suggestionItem] : []);
return resolve(suggestionItem ? [suggestionItem] : []);
}
// prevent completion when typing in a line comment that doesnt start from the beginning of the line
const commentIndex = lineText.indexOf('//');

Просмотреть файл

@ -66,7 +66,7 @@ export function testAtCursor(goConfig: vscode.WorkspaceConfiguration, cmd: TestA
} else if (cmd === 'benchmark' || cmd === 'test') {
await runTestAtCursor(editor, testFunctionName, testFunctions, goConfig, cmd, args);
} else {
throw 'Unsupported command.';
throw new Error('Unsupported command.');
}
} catch (err) {
console.error(err);

Просмотреть файл

@ -116,4 +116,4 @@ export class GoTypeDefinitionProvider implements vscode.TypeDefinitionProvider {
);
});
}
}
}

Просмотреть файл

@ -310,11 +310,7 @@ export function isGoPathSet(): boolean {
return true;
}
export function sendTelemetryEvent(eventName: string, properties?: {
[key: string]: string;
}, measures?: {
[key: string]: number;
}): void {
export function sendTelemetryEvent(eventName: string, properties?: { [key: string]: string }, measures?: { [key: string]: number }): void {
telemtryReporter = telemtryReporter ? telemtryReporter : new TelemetryReporter(extensionId, extensionVersion, aiKey);
telemtryReporter.sendTelemetryEvent(eventName, properties, measures);
@ -410,7 +406,7 @@ export function getToolsEnvVars(): any {
}
export function substituteEnv(input: string): string {
return input.replace(/\${env:([^}]+)}/g, function (match, capture) {
return input.replace(/\${env:([^}]+)}/g, function(match, capture) {
return process.env[capture.trim()] || '';
});
}
@ -443,8 +439,7 @@ export function getCurrentGoPath(workspaceUri?: vscode.Uri): string {
if (fs.statSync(path.join(currentRoot, 'src')).isDirectory()) {
inferredGopath = currentRoot;
}
}
catch (e) {
} catch (e) {
// No op
}
}

Просмотреть файл

@ -278,12 +278,14 @@ It returns the number of bytes written and any write error encountered.
assert.equal(sortedDiagnostics.length > 0, true, `Failed to get linter results`);
let matchCount = 0;
for (let i in expected) {
for (let j in sortedDiagnostics) {
if (expected[i].line
&& (expected[i].line === sortedDiagnostics[j].line)
&& (expected[i].severity === sortedDiagnostics[j].severity)
&& (expected[i].msg === sortedDiagnostics[j].msg)) {
matchCount++;
if (expected.hasOwnProperty(i)) {
for (let j in sortedDiagnostics) {
if (expected[i].line
&& (expected[i].line === sortedDiagnostics[j].line)
&& (expected[i].severity === sortedDiagnostics[j].severity)
&& (expected[i].msg === sortedDiagnostics[j].msg)) {
matchCount++;
}
}
}
}
@ -400,11 +402,13 @@ It returns the number of bytes written and any write error encountered.
assert.equal(sortedDiagnostics.length > 0, true, `Failed to get linter results`);
let matchCount = 0;
for (let i in expected) {
for (let j in sortedDiagnostics) {
if ((expected[i].line === sortedDiagnostics[j].line)
&& (expected[i].severity === sortedDiagnostics[j].severity)
&& (expected[i].msg === sortedDiagnostics[j].msg)) {
matchCount++;
if (expected.hasOwnProperty(i)) {
for (let j in sortedDiagnostics) {
if ((expected[i].line === sortedDiagnostics[j].line)
&& (expected[i].severity === sortedDiagnostics[j].severity)
&& (expected[i].msg === sortedDiagnostics[j].msg)) {
matchCount++;
}
}
}
}
@ -556,7 +560,7 @@ It returns the number of bytes written and any write error encountered.
let uri = vscode.Uri.file(path.join(fixturePath, 'outlineTest', 'test.go'));
vscode.workspace.openTextDocument(uri).then(document => {
new GoDocumentSymbolProvider().provideDocumentSymbols(document, null).then(symbols => {
let groupedSymbolNames = symbols.reduce(function (map: any, symbol) {
let groupedSymbolNames = symbols.reduce(function(map: any, symbol) {
map[symbol.kind] = (map[symbol.kind] || []).concat([symbol.name]);
return map;
}, {});

Просмотреть файл

@ -1,29 +1,141 @@
{
"rules": {
"adjacent-overload-signatures": true,
"align": {
"options": [
"parameters",
"statements"
]
},
// "arrow-parens": true,
"arrow-return-shorthand": true,
"ban-types": {
"options": [
[
"Object",
"Avoid using the `Object` type. Did you mean `object`?"
],
[
"Function",
"Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
],
[
"Boolean",
"Avoid using the `Boolean` type. Did you mean `boolean`?"
],
[
"Number",
"Avoid using the `Number` type. Did you mean `number`?"
],
[
"String",
"Avoid using the `String` type. Did you mean `string`?"
],
[
"Symbol",
"Avoid using the `Symbol` type. Did you mean `symbol`?"
]
]
},
// "callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
// "curly": true,
"eofline": true,
"forin": true,
"import-spacing": true,
"indent": [
true,
"tabs"
],
// "interface-name": {
// "options": ["always-prefix"]
// },
"interface-over-type-literal": true,
// "jsdoc-format": true,
"label-position": true,
"max-classes-per-file": {
"options": 2
},
// "max-line-length": { "options": 120 },
// "member-access": true,
// "member-ordering": {
// "options": {
// "order": "statics-first"
// }
// },
"new-parens": true,
"no-arg": true,
"no-conditional-assignment": true,
// "no-consecutive-blank-lines": true,
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-duplicate-variable": true,
// "no-empty": true,
"no-empty-interface": true,
"no-eval": true,
"no-internal-module": true,
"no-invalid-this": false,
"no-misused-new": true,
"no-namespace": true,
"no-reference": true,
"no-reference-import": true,
// "no-shadowed-variable": true,
"no-string-throw": true,
"no-trailing-whitespace": true,
"no-unnecessary-initializer": true,
"no-unsafe-finally": true,
"no-unused-expression": true,
"no-var-keyword": true,
// "no-var-requires": true,
// "object-literal-key-quotes": { "options": "consistent-as-needed" },
// "object-literal-shorthand": true,
// "object-literal-sort-keys": true,
"one-line": [
true,
"check-catch",
// "check-else",
"check-finally",
"check-open-brace",
"check-whitespace"
],
// "one-variable-per-declaration": { "options": ["ignore-for-loop"] },
// "only-arrow-functions": {
// "options": ["allow-declarations", "allow-named-functions"]
// },
// "ordered-imports": {
// "options": {
// "import-sources-order": "case-insensitive",
// "module-source-path": "full",
// "named-imports-order": "case-insensitive"
// }
// },
// "prefer-const": true,
// "prefer-for-of": true,
"quotemark": [
true,
"single"
],
// "radix": true,
"semicolon": true,
"space-before-function-paren": {
"options": {
"anonymous": "never",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}
},
"trailing-comma": {
"options": {
"esSpecCompliant": true
}
},
"triple-equals": [
true,
"allow-null-check"
@ -38,9 +150,13 @@
"variable-declaration": "nospace"
}
],
"unified-signatures": true,
"use-isnan": true,
"variable-name": [
true,
"ban-keywords"
"ban-keywords",
"check-format",
"allow-pascal-case"
],
"whitespace": [
true,