Cleanup .ts formatting
This commit is contained in:
Родитель
1436116547
Коммит
3cb996f434
|
@ -187,9 +187,9 @@ class Delve {
|
|||
if (err) return reject(err);
|
||||
// Add a slight delay to avoid issues on Linux with
|
||||
// Delve failing calls made shortly after connection.
|
||||
setTimeout(() =>
|
||||
setTimeout(() =>
|
||||
resolve(conn),
|
||||
200);
|
||||
200);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ class GoDebugSession extends DebugSession {
|
|||
this.delve.connection.then(() =>
|
||||
this.initialBreakpointsSetPromise
|
||||
).then(() => {
|
||||
if(args.stopOnEntry) {
|
||||
if (args.stopOnEntry) {
|
||||
this.sendEvent(new StoppedEvent("breakpoint", 0));
|
||||
console.log("StoppedEvent('breakpoint')");
|
||||
this.sendResponse(response);
|
||||
|
@ -303,7 +303,7 @@ class GoDebugSession extends DebugSession {
|
|||
super.disconnectRequest(response, args);
|
||||
console.log("DisconnectResponse");
|
||||
}
|
||||
|
||||
|
||||
protected setExceptionBreakPointsRequest(response: DebugProtocol.SetExceptionBreakpointsResponse, args: DebugProtocol.SetExceptionBreakpointsArguments): void {
|
||||
console.log("ExceptionBreakPointsRequest");
|
||||
// Wow - this is subtle - it appears that this event will always get
|
||||
|
@ -427,7 +427,7 @@ class GoDebugSession extends DebugSession {
|
|||
cap: 0,
|
||||
children: vars,
|
||||
unreadable: ""
|
||||
}
|
||||
}
|
||||
scopes.push(new Scope("Local", this._variableHandles.create(localVariables), false));
|
||||
response.body = { scopes };
|
||||
this.sendResponse(response);
|
||||
|
@ -435,15 +435,15 @@ class GoDebugSession extends DebugSession {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
private convertDebugVariableToProtocolVariable(v: DebugVariable, i: number): {result: string; variablesReference: number; } {
|
||||
|
||||
private convertDebugVariableToProtocolVariable(v: DebugVariable, i: number): { result: string; variablesReference: number; } {
|
||||
if (v.kind == GoReflectKind.Ptr || v.kind == GoReflectKind.UnsafePointer) {
|
||||
if (v.children[0].addr == 0) {
|
||||
return {
|
||||
result: "nil <" + v.type + ">",
|
||||
variablesReference: 0
|
||||
}
|
||||
} else if(v.children[0].type == "void") {
|
||||
} else if (v.children[0].type == "void") {
|
||||
return {
|
||||
result: "void",
|
||||
variablesReference: 0
|
||||
|
@ -454,19 +454,19 @@ class GoDebugSession extends DebugSession {
|
|||
variablesReference: v.children[0].children.length > 0 ? this._variableHandles.create(v.children[0]) : 0
|
||||
}
|
||||
}
|
||||
} else if(v.kind == GoReflectKind.Slice) {
|
||||
} else if (v.kind == GoReflectKind.Slice) {
|
||||
return {
|
||||
result: "<" + v.type.substring(7) + ">",
|
||||
variablesReference: this._variableHandles.create(v)
|
||||
}
|
||||
} else if(v.kind == GoReflectKind.Array) {
|
||||
} else if (v.kind == GoReflectKind.Array) {
|
||||
return {
|
||||
result: "<" + v.type + ">",
|
||||
variablesReference: this._variableHandles.create(v)
|
||||
}
|
||||
} else if(v.kind == GoReflectKind.String) {
|
||||
} else if (v.kind == GoReflectKind.String) {
|
||||
return {
|
||||
result: v.unreadable ? ("<" + v.unreadable + ">") : ('"' + v.value + '"'),
|
||||
result: v.unreadable ? ("<" + v.unreadable + ">") : ('"' + v.value + '"'),
|
||||
variablesReference: 0
|
||||
}
|
||||
} else {
|
||||
|
@ -481,31 +481,31 @@ class GoDebugSession extends DebugSession {
|
|||
console.log("VariablesRequest");
|
||||
var vari = this._variableHandles.get(args.variablesReference);
|
||||
let variables;
|
||||
if(vari.kind == GoReflectKind.Array || vari.kind == GoReflectKind.Map) {
|
||||
if (vari.kind == GoReflectKind.Array || vari.kind == GoReflectKind.Map) {
|
||||
variables = vari.children.map((v, i) => {
|
||||
let { result, variablesReference} = this.convertDebugVariableToProtocolVariable(v,i)
|
||||
let { result, variablesReference} = this.convertDebugVariableToProtocolVariable(v, i)
|
||||
return {
|
||||
name: "[" + i + "]",
|
||||
value: result,
|
||||
variablesReference
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
variables = vari.children.map((v, i) => {
|
||||
let { result, variablesReference} = this.convertDebugVariableToProtocolVariable(v,i)
|
||||
let { result, variablesReference} = this.convertDebugVariableToProtocolVariable(v, i)
|
||||
return {
|
||||
name: v.name,
|
||||
value: result,
|
||||
variablesReference
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
console.log(JSON.stringify(variables, null, ' '))
|
||||
response.body = { variables };
|
||||
this.sendResponse(response);
|
||||
console.log("VariablesResponse");
|
||||
}
|
||||
|
||||
|
||||
private handleReenterDebug(reason: string): void {
|
||||
if (this.debugState.exited) {
|
||||
this.sendEvent(new TerminatedEvent());
|
||||
|
@ -519,10 +519,10 @@ class GoDebugSession extends DebugSession {
|
|||
// Assume we need to stop all the threads we saw before...
|
||||
let needsToBeStopped = new Set<number>();
|
||||
this.threads.forEach(id => needsToBeStopped.add(id));
|
||||
for(var goroutine of goroutines) {
|
||||
for (var goroutine of goroutines) {
|
||||
// ...but delete from list of threads to stop if we still see it
|
||||
needsToBeStopped.delete(goroutine.id);
|
||||
if(!this.threads.has(goroutine.id)) {
|
||||
if (!this.threads.has(goroutine.id)) {
|
||||
// Send started event if it's new
|
||||
this.sendEvent(new ThreadEvent('started', goroutine.id));
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ class GoDebugSession extends DebugSession {
|
|||
this.sendEvent(new ThreadEvent('exited', id))
|
||||
this.threads.delete(id);
|
||||
});
|
||||
|
||||
|
||||
this.sendEvent(new StoppedEvent(reason, this.debugState.currentGoroutine.id));
|
||||
console.log("StoppedEvent('" + reason + "')");
|
||||
});
|
||||
|
|
|
@ -11,30 +11,30 @@ import * as _ from 'lodash';
|
|||
|
||||
export class GoCodeActionProvider implements vscode.CodeActionProvider {
|
||||
public provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): Thenable<vscode.Command[]> {
|
||||
|
||||
|
||||
let promises = context.diagnostics.map(diag => {
|
||||
// When a name is not found but could refer to a package, offer to add import
|
||||
if(diag.message.indexOf("undefined: ") == 0) {
|
||||
if (diag.message.indexOf("undefined: ") == 0) {
|
||||
let [_, name] = /^undefined: (\S*)/.exec(diag.message)
|
||||
return listPackages().then(packages => {
|
||||
let commands = packages
|
||||
.filter(pkg => pkg == name || pkg.endsWith("/" + name))
|
||||
.map(pkg => {
|
||||
return {
|
||||
title: "import \"" + pkg +"\"",
|
||||
command: "go.import.add",
|
||||
arguments: [pkg]
|
||||
}
|
||||
});
|
||||
return {
|
||||
title: "import \"" + pkg + "\"",
|
||||
command: "go.import.add",
|
||||
arguments: [pkg]
|
||||
}
|
||||
});
|
||||
return commands;
|
||||
});
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(arrs => {
|
||||
return Promise.all(promises).then(arrs => {
|
||||
return _.sortBy(
|
||||
_.uniq(_.flatten(arrs), x => x.title),
|
||||
_.uniq(_.flatten(arrs), x => x.title),
|
||||
x => x.title
|
||||
);
|
||||
});
|
||||
|
|
|
@ -55,9 +55,9 @@ export function definitionLocation(document: vscode.TextDocument, position: vsco
|
|||
var sigName = signature.substring(0, signature.indexOf(' '));
|
||||
var sigParams = signature.substring(signature.indexOf(' func') + 5);
|
||||
var searchSignature = "func " + sigName + sigParams;
|
||||
for(var i = 0; i < godocLines.length; i++) {
|
||||
if(godocLines[i] == searchSignature) {
|
||||
while(godocLines[++i].startsWith(' ')) {
|
||||
for (var i = 0; i < godocLines.length; i++) {
|
||||
if (godocLines[i] == searchSignature) {
|
||||
while (godocLines[++i].startsWith(' ')) {
|
||||
doc += godocLines[i].substring(4) + '\n';
|
||||
}
|
||||
break;
|
||||
|
@ -69,7 +69,7 @@ export function definitionLocation(document: vscode.TextDocument, position: vsco
|
|||
col: + col - 1,
|
||||
lines,
|
||||
doc
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
|
|
|
@ -131,14 +131,14 @@ export class Formatter {
|
|||
|
||||
export class GoDocumentFormattingEditProvider implements vscode.DocumentFormattingEditProvider {
|
||||
private formatter: Formatter;
|
||||
|
||||
|
||||
constructor() {
|
||||
this.formatter = new Formatter();
|
||||
this.formatter = new Formatter();
|
||||
}
|
||||
|
||||
|
||||
public provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): Thenable<vscode.TextEdit[]> {
|
||||
return document.save().then(() => {
|
||||
return this.formatter.formatDocument(document);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ export function addImport(arg: string) {
|
|||
return vscode.window.activeTextEditor.edit(editBuilder => {
|
||||
editBuilder.insert(new vscode.Position(lastSingleImport + 1, 0), 'import "' + imp + '"\n');
|
||||
});
|
||||
} else if(pkg && pkg.start >= 0) {
|
||||
} else if (pkg && pkg.start >= 0) {
|
||||
// There are no import declarations, but there is a package declaration
|
||||
return vscode.window.activeTextEditor.edit(editBuilder => {
|
||||
editBuilder.insert(new vscode.Position(pkg.start + 1, 0), '\nimport (\n\t"' + imp + '"\n)\n');
|
||||
|
|
|
@ -69,7 +69,7 @@ export function setupGoPathAndOfferToInstallTools() {
|
|||
command() {
|
||||
var channel = vscode.window.createOutputChannel('Go');
|
||||
channel.show();
|
||||
missing.forEach(tool => {
|
||||
missing.forEach(tool => {
|
||||
cp.exec("go get -u -v " + tool, { env: process.env }, (err, stdout, stderr) => {
|
||||
channel.append(stdout.toString());
|
||||
channel.append(stderr.toString());
|
||||
|
|
|
@ -92,12 +92,12 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
|
|||
item.kind = vscodeKindFromGoCodeClass(suggest.class);
|
||||
item.detail = suggest.type;
|
||||
let conf = vscode.workspace.getConfiguration('go');
|
||||
if(conf.get("useCodeSnippetsOnFunctionSuggest") && suggest.class == "func") {
|
||||
if (conf.get("useCodeSnippetsOnFunctionSuggest") && suggest.class == "func") {
|
||||
let params = parameters(suggest.type.substring(4)) // "func"
|
||||
let paramSnippets = [];
|
||||
for(let i in params) {
|
||||
for (let i in params) {
|
||||
let param = params[i].trim();
|
||||
if(param) {
|
||||
if (param) {
|
||||
paramSnippets.push("{{" + param + "}}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,12 @@ export class GoWorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider
|
|||
}
|
||||
let symArgs = vscode.workspace.getConfiguration('go')['symbols'];
|
||||
let args = [vscode.workspace.rootPath, query];
|
||||
if(symArgs != undefined && symArgs != "") {
|
||||
if (symArgs != undefined && symArgs != "") {
|
||||
args.unshift(symArgs)
|
||||
}
|
||||
var gosyms = getBinPath("go-symbols");
|
||||
return new Promise((resolve, reject) => {
|
||||
var p = cp.execFile(gosyms, args, {maxBuffer: 1024 * 1024}, (err, stdout, stderr) => {
|
||||
var p = cp.execFile(gosyms, args, { maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
|
||||
try {
|
||||
if (err && (<any>err).code == "ENOENT") {
|
||||
vscode.window.showInformationMessage("The 'go-symbols' command is not available. Use 'go get -u github.com/newhook/go-symbols' to install.");
|
||||
|
|
|
@ -150,8 +150,8 @@ function getTestFunctions(doc: vscode.TextDocument): Thenable<vscode.SymbolInfor
|
|||
return documentSymbolProvider
|
||||
.provideDocumentSymbols(doc, null)
|
||||
.then(symbols =>
|
||||
symbols.filter(sym =>
|
||||
sym.kind == vscode.SymbolKind.Function
|
||||
symbols.filter(sym =>
|
||||
sym.kind == vscode.SymbolKind.Function
|
||||
&& /Test.*/.exec(sym.name) != null)
|
||||
);
|
||||
}
|
||||
|
|
60
src/util.ts
60
src/util.ts
|
@ -17,26 +17,26 @@ export function byteOffsetAt(document: TextDocument, position: Position): number
|
|||
}
|
||||
|
||||
export interface Prelude {
|
||||
imports: Array<{kind: string; start: number; end: number;}>;
|
||||
pkg: {start: number; end: number;};
|
||||
imports: Array<{ kind: string; start: number; end: number; }>;
|
||||
pkg: { start: number; end: number; };
|
||||
}
|
||||
|
||||
export function parseFilePrelude(text: string): Prelude {
|
||||
let lines = text.split('\n');
|
||||
let ret: Prelude = {imports: [], pkg: null };
|
||||
let ret: Prelude = { imports: [], pkg: null };
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
let line = lines[i];
|
||||
if (line.match(/^(\s)*package(\s)+/)) {
|
||||
ret.pkg = {start: i, end: i};
|
||||
ret.pkg = { start: i, end: i };
|
||||
}
|
||||
if (line.match(/^(\s)*import(\s)+\(/)) {
|
||||
ret.imports.push({kind: "multi", start: i, end: -1});
|
||||
ret.imports.push({ kind: "multi", start: i, end: -1 });
|
||||
}
|
||||
if (line.match(/^(\s)*import(\s)+[^\(]/)) {
|
||||
ret.imports.push({kind: "single", start: i, end: i});
|
||||
ret.imports.push({ kind: "single", start: i, end: i });
|
||||
}
|
||||
if (line.match(/^(\s)*\)/)) {
|
||||
if(ret.imports[ret.imports.length - 1].end == -1) {
|
||||
if (ret.imports[ret.imports.length - 1].end == -1) {
|
||||
ret.imports[ret.imports.length - 1].end = i;
|
||||
}
|
||||
}
|
||||
|
@ -54,30 +54,30 @@ export function parseFilePrelude(text: string): Prelude {
|
|||
// Takes care of balancing parens so to not get confused by signatures like:
|
||||
// (pattern string, handler func(ResponseWriter, *Request)) {
|
||||
export function parameters(signature: string): string[] {
|
||||
var ret: string[] = [];
|
||||
var parenCount = 0;
|
||||
var lastStart = 1;
|
||||
for (var i = 1; i < signature.length; i++) {
|
||||
switch (signature[i]) {
|
||||
case '(':
|
||||
parenCount++;
|
||||
break;
|
||||
case ')':
|
||||
parenCount--;
|
||||
if (parenCount < 0) {
|
||||
if (i > lastStart) {
|
||||
ret.push(signature.substring(lastStart, i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if (parenCount == 0) {
|
||||
var ret: string[] = [];
|
||||
var parenCount = 0;
|
||||
var lastStart = 1;
|
||||
for (var i = 1; i < signature.length; i++) {
|
||||
switch (signature[i]) {
|
||||
case '(':
|
||||
parenCount++;
|
||||
break;
|
||||
case ')':
|
||||
parenCount--;
|
||||
if (parenCount < 0) {
|
||||
if (i > lastStart) {
|
||||
ret.push(signature.substring(lastStart, i));
|
||||
lastStart = i + 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if (parenCount == 0) {
|
||||
ret.push(signature.substring(lastStart, i));
|
||||
lastStart = i + 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import { GoCompletionItemProvider } from '../src/goSuggest';
|
|||
import { GoSignatureHelpProvider } from '../src/goSignature';
|
||||
|
||||
var fixtureSrc =
|
||||
`package main
|
||||
`package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -45,14 +45,14 @@ suite("Go Extension Tests", () => {
|
|||
let provider = new GoHoverProvider();
|
||||
let testCases: [vscode.Position, string][] = [
|
||||
//[new vscode.Position(3,3), '/usr/local/go/src/fmt'],
|
||||
[new vscode.Position(8,6), 'main func()'],
|
||||
[new vscode.Position(6,2), 'import (fmt "fmt")'],
|
||||
[new vscode.Position(6,6), 'Println func(a ...interface{}) (n int, err error)'],
|
||||
[new vscode.Position(9,3), 'print func(txt string)']
|
||||
[new vscode.Position(8, 6), 'main func()'],
|
||||
[new vscode.Position(6, 2), 'import (fmt "fmt")'],
|
||||
[new vscode.Position(6, 6), 'Println func(a ...interface{}) (n int, err error)'],
|
||||
[new vscode.Position(9, 3), 'print func(txt string)']
|
||||
];
|
||||
let uri = vscode.Uri.file(fixture);
|
||||
vscode.workspace.openTextDocument(uri).then((textDocument) => {
|
||||
let promises = testCases.map(([position, expected]) =>
|
||||
let promises = testCases.map(([position, expected]) =>
|
||||
provider.provideHover(textDocument, position, null).then(res => {
|
||||
assert.equal(res.contents.length, 1);
|
||||
assert.equal(expected, (<{ language: string; value: string }>res.contents[0]).value);
|
||||
|
@ -61,24 +61,24 @@ suite("Go Extension Tests", () => {
|
|||
return Promise.all(promises);
|
||||
}, (err) => {
|
||||
assert.ok(false, `error in OpenTextDocument ${err}`);
|
||||
}).then(() => done(),done);
|
||||
}).then(() => done(), done);
|
||||
});
|
||||
|
||||
test("Test Completion", (done) => {
|
||||
let provider = new GoCompletionItemProvider();
|
||||
let testCases: [vscode.Position, string[]][] = [
|
||||
[new vscode.Position(1,0), []],
|
||||
[new vscode.Position(4,1), ['main', 'print', 'fmt']],
|
||||
[new vscode.Position(6,4), ['fmt']],
|
||||
[new vscode.Position(7,0), ['main', 'print', 'fmt', 'txt']]
|
||||
[new vscode.Position(1, 0), []],
|
||||
[new vscode.Position(4, 1), ['main', 'print', 'fmt']],
|
||||
[new vscode.Position(6, 4), ['fmt']],
|
||||
[new vscode.Position(7, 0), ['main', 'print', 'fmt', 'txt']]
|
||||
];
|
||||
let uri = vscode.Uri.file(fixture);
|
||||
vscode.workspace.openTextDocument(uri).then((textDocument) => {
|
||||
let promises = testCases.map(([position, expected]) =>
|
||||
let promises = testCases.map(([position, expected]) =>
|
||||
provider.provideCompletionItems(textDocument, position, null).then(items => {
|
||||
let labels = items.map(x => x.label);
|
||||
for(let entry of expected) {
|
||||
if(labels.indexOf(entry) < 0) {
|
||||
for (let entry of expected) {
|
||||
if (labels.indexOf(entry) < 0) {
|
||||
assert.fail("", entry, "missing expected item in competion list");
|
||||
}
|
||||
}
|
||||
|
@ -87,18 +87,18 @@ suite("Go Extension Tests", () => {
|
|||
return Promise.all(promises);
|
||||
}, (err) => {
|
||||
assert.ok(false, `error in OpenTextDocument ${err}`);
|
||||
}).then(() => done(),done);
|
||||
}).then(() => done(), done);
|
||||
});
|
||||
|
||||
|
||||
test("Test Signature Help", (done) => {
|
||||
let provider = new GoSignatureHelpProvider();
|
||||
let testCases: [vscode.Position, string][] = [
|
||||
[new vscode.Position(6,13), "Println(a ...interface{}) (n int, err error)"],
|
||||
[new vscode.Position(9,7), "print(txt string)"]
|
||||
[new vscode.Position(6, 13), "Println(a ...interface{}) (n int, err error)"],
|
||||
[new vscode.Position(9, 7), "print(txt string)"]
|
||||
];
|
||||
let uri = vscode.Uri.file(fixture);
|
||||
vscode.workspace.openTextDocument(uri).then((textDocument) => {
|
||||
let promises = testCases.map(([position, expected]) =>
|
||||
let promises = testCases.map(([position, expected]) =>
|
||||
provider.provideSignatureHelp(textDocument, position, null).then(sigHelp => {
|
||||
assert.equal(sigHelp.signatures.length, 1, "unexpected number of overloads");
|
||||
assert.equal(sigHelp.signatures[0].label, expected)
|
||||
|
@ -107,6 +107,6 @@ suite("Go Extension Tests", () => {
|
|||
return Promise.all(promises);
|
||||
}, (err) => {
|
||||
assert.ok(false, `error in OpenTextDocument ${err}`);
|
||||
}).then(() => done(),done);
|
||||
}).then(() => done(), done);
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче