Release 1.0.0
This commit is contained in:
parent
c9db603737
commit
41108de00e
|
@ -29,7 +29,7 @@
|
||||||
"colors": [
|
"colors": [
|
||||||
{
|
{
|
||||||
"id": "QuicklyGenerator.StructSelected",
|
"id": "QuicklyGenerator.StructSelected",
|
||||||
"description": "Background decoration color for large numbers",
|
"description": "Background decoration color for struct selected",
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"dark": "#3bcf1655",
|
"dark": "#3bcf1655",
|
||||||
"light": "#d45b0a55",
|
"light": "#d45b0a55",
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "Go-Quickly-Generator.Go-Gen-GetSet",
|
"command": "Go-Quickly-Generator.Go-Gen-GetSet",
|
||||||
"title": "Generator Get Set",
|
"title": "Go: Generate Get Set",
|
||||||
"category": "go-quickly-generator"
|
"category": "go-quickly-generator"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
118
src/extension.ts
118
src/extension.ts
|
@ -94,31 +94,31 @@ function activate(context: vscode.ExtensionContext) {
|
||||||
let editor = vscode.window.activeTextEditor;
|
let editor = vscode.window.activeTextEditor;
|
||||||
if (sinfo && editor) {
|
if (sinfo && editor) {
|
||||||
|
|
||||||
let decoration = <vscode.DecorationOptions>{ range: new vscode.Range(sinfo.Range[0], 0, sinfo.Range[1] + 1, 0) };
|
let decoration = <vscode.DecorationOptions>{ range: new vscode.Range(sinfo.Range[0], 0, sinfo.Range[1] + 1, 0) };
|
||||||
editor.setDecorations(dtype, [decoration]);
|
editor.setDecorations(dtype, [decoration]);
|
||||||
|
|
||||||
vscode.window.showQuickPick(["Getter", "Setter"], <vscode.QuickPickOptions>{ canPickMany: true, placeHolder: "select generator type getter or setter" }).then(items => {
|
vscode.window.showQuickPick(["Getter", "Setter"], <vscode.QuickPickOptions>{ canPickMany: true, placeHolder: "select generator type getter or setter" }).then(items => {
|
||||||
console.log(items);
|
console.log(items);
|
||||||
|
|
||||||
if(items) {
|
if (items) {
|
||||||
let myitems = items as any as string[];
|
let myitems = items as any as string[];
|
||||||
let gtype = GeneratorType.Unknown;
|
let gtype = GeneratorType.Unknown;
|
||||||
myitems.forEach((value) => {
|
myitems.forEach((value) => {
|
||||||
let sel = typeMap.get(value);
|
let sel = typeMap.get(value);
|
||||||
if (sel) {
|
if (sel) {
|
||||||
gtype = gtype | sel;
|
gtype = gtype | sel;
|
||||||
}
|
|
||||||
});
|
|
||||||
if (sinfo) {
|
|
||||||
GeneratorSetGet(sinfo, gtype);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
if (sinfo) {
|
||||||
|
GeneratorSetGet(sinfo, gtype);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let editor = vscode.window.activeTextEditor;
|
let editor = vscode.window.activeTextEditor;
|
||||||
if(editor) {
|
if (editor) {
|
||||||
editor.setDecorations(dtype, []);
|
editor.setDecorations(dtype, []);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
vscode.window.showErrorMessage("there is no struct(go) to focus. you can move point to struct(go)");
|
vscode.window.showErrorMessage("there is no struct(go) to focus. you can move point to struct(go)");
|
||||||
}
|
}
|
||||||
|
@ -173,10 +173,12 @@ function GeneratorSetGet(sinfo: StructInfo, stype: GeneratorType) {
|
||||||
|
|
||||||
const options = <vscode.QuickPickOptions>{ canPickMany: true, placeHolder: "select the fields that would be generator get set" };
|
const options = <vscode.QuickPickOptions>{ canPickMany: true, placeHolder: "select the fields that would be generator get set" };
|
||||||
var items: vscode.QuickPickItem[] = [];
|
var items: vscode.QuickPickItem[] = [];
|
||||||
|
|
||||||
var obj = {
|
var obj = {
|
||||||
info: sinfo,
|
info: sinfo,
|
||||||
exists: existsStructFunctions,
|
exists: existsStructFunctions,
|
||||||
items: function () {
|
|
||||||
|
fields2items: function () {
|
||||||
this.info.Fields.forEach((value, key) => {
|
this.info.Fields.forEach((value, key) => {
|
||||||
if (this.exists.has(key)) {
|
if (this.exists.has(key)) {
|
||||||
vscode.window.showInformationMessage("Get" + key + " or Set" + key + " is Exists");
|
vscode.window.showInformationMessage("Get" + key + " or Set" + key + " is Exists");
|
||||||
|
@ -191,45 +193,47 @@ function GeneratorSetGet(sinfo: StructInfo, stype: GeneratorType) {
|
||||||
},
|
},
|
||||||
|
|
||||||
pick: function () {
|
pick: function () {
|
||||||
this.items();
|
this.fields2items();
|
||||||
vscode.window.showQuickPick(items, options).then((item) => {
|
if (items.length) {
|
||||||
if (item) {
|
vscode.window.showQuickPick(items, options).then((item) => {
|
||||||
let fields = item as any as vscode.QuickPickItem[];
|
if (item) {
|
||||||
let sname = getAbbreviation(this.info.Name) as string;
|
let fields = item as any as vscode.QuickPickItem[];
|
||||||
let structString = `func (${sname} *${this.info.Name})`;
|
let sname = getAbbreviation(this.info.Name) as string;
|
||||||
|
let structString = `func (${sname} *${this.info.Name})`;
|
||||||
|
|
||||||
fields.forEach((qitem) => {
|
fields.forEach((qitem) => {
|
||||||
let field = this.info.Fields.get(qitem.description as string);
|
let field = this.info.Fields.get(qitem.description as string);
|
||||||
if (field) {
|
if (field) {
|
||||||
|
|
||||||
let editor = vscode.window.activeTextEditor;
|
let editor = vscode.window.activeTextEditor;
|
||||||
if (editor) {
|
if (editor) {
|
||||||
|
|
||||||
let keyName = field.Name[0].toUpperCase() + field.Name.substr(1);
|
let keyName = field.Name[0].toUpperCase() + field.Name.substr(1);
|
||||||
let funcitonName = field.Parent.replace(new RegExp("\\.", "g"), "") + keyName;
|
let funcitonName = field.Parent.replace(new RegExp("\\.", "g"), "") + keyName;
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
if (stype & GeneratorType.Setter) {
|
if (stype & GeneratorType.Setter) {
|
||||||
let prefix = "Set";
|
let prefix = "Set";
|
||||||
let setFunction = prefix + funcitonName;
|
let setFunction = prefix + funcitonName;
|
||||||
let params = `(${field.Name} ${field.Type})`;
|
let params = `(${field.Name} ${field.Type})`;
|
||||||
let comment = `// ${setFunction} ${prefix} ${field.Name} ${field.Type}\n`;
|
let comment = `// ${setFunction} ${prefix} ${field.Name} ${field.Type}\n`;
|
||||||
let ss = new vscode.SnippetString(`\n${comment}${structString} ${setFunction}${params} {\n\t${sname}${field.Parent}${field.Name} = ${field.Name}\n}\n`);
|
let ss = new vscode.SnippetString(`\n${comment}${structString} ${setFunction}${params} {\n\t${sname}${field.Parent}${field.Name} = ${field.Name}\n}\n`);
|
||||||
editor.insertSnippet(ss, new vscode.Position(this.info.Range[1] + 1, 0));
|
editor.insertSnippet(ss, new vscode.Position(this.info.Range[1] + 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stype & GeneratorType.Getter) {
|
if (stype & GeneratorType.Getter) {
|
||||||
let prefix = "Get";
|
let prefix = "Get";
|
||||||
let getFunction = prefix + funcitonName;
|
let getFunction = prefix + funcitonName;
|
||||||
let comment = `// ${getFunction} ${prefix} return ${field.Name} ${field.Type}\n`;
|
let comment = `// ${getFunction} ${prefix} return ${field.Name} ${field.Type}\n`;
|
||||||
let ss = new vscode.SnippetString(`\n${comment}${structString} ${getFunction}() ${field.Type} {\n\treturn ${sname}${field.Parent}${field.Name}\n}\n`);
|
let ss = new vscode.SnippetString(`\n${comment}${structString} ${getFunction}() ${field.Type} {\n\treturn ${sname}${field.Parent}${field.Name}\n}\n`);
|
||||||
editor.insertSnippet(ss, new vscode.Position(this.info.Range[1] + 1, 0));
|
editor.insertSnippet(ss, new vscode.Position(this.info.Range[1] + 1, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -245,11 +249,9 @@ function GetStruct(): StructInfo | undefined {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let selection = editor.selection;
|
let selection = editor.selection;
|
||||||
// vscode.window.showInformationMessage( editor.document.version.toString() );
|
|
||||||
// vscode.window.showInformationMessage( text );
|
|
||||||
let selectline = selection.active.line;
|
let selectline = selection.active.line;
|
||||||
let regex = "type +([^ ]+) +struct";
|
let regex = "type +([^ ]+) +struct";
|
||||||
// lineText.text.match()
|
|
||||||
for (let i = selectline; i >= 0; i--) {
|
for (let i = selectline; i >= 0; i--) {
|
||||||
let lineText = editor.document.lineAt(i);
|
let lineText = editor.document.lineAt(i);
|
||||||
let matchs = lineText.text.match(regex);
|
let matchs = lineText.text.match(regex);
|
||||||
|
@ -384,5 +386,7 @@ function getFieldRange(editor: vscode.TextEditor, pair: string[], startline: num
|
||||||
// export function getStruct(editor: vscode.TextEditor) {
|
// export function getStruct(editor: vscode.TextEditor) {
|
||||||
// }
|
// }
|
||||||
// this method is called when your extension is deactivated
|
// this method is called when your extension is deactivated
|
||||||
function deactivate() { }
|
function deactivate() {
|
||||||
|
|
||||||
|
}
|
||||||
exports.deactivate = deactivate;
|
exports.deactivate = deactivate;
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (ms *MyStruct2) GetValue() int {
|
||||||
return ms.Value
|
return ms.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoFunc 非常丑陋
|
// DoFunc 非常丑陋的兼容
|
||||||
func DoFunc(a func(
|
func DoFunc(a func(
|
||||||
a int,
|
a int,
|
||||||
b struct {
|
b struct {
|
||||||
|
@ -58,64 +58,16 @@ func DoFunc(a func(
|
||||||
// ExStruct 升级
|
// ExStruct 升级
|
||||||
type ExStruct struct {
|
type ExStruct struct {
|
||||||
ChildStruct struct {
|
ChildStruct struct {
|
||||||
A int
|
age int
|
||||||
B interface{}
|
Height interface{}
|
||||||
girl string
|
girl string
|
||||||
boy int
|
boy int
|
||||||
}
|
}
|
||||||
C string
|
Age string
|
||||||
D func(a int, b string)
|
Do func(a int, b string)
|
||||||
child string
|
child string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChildStructBoy Get return boy int
|
|
||||||
func (es *ExStruct) GetChildStructBoy() int {
|
|
||||||
return es.ChildStruct.boy
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetChildStructBoy Set boy int
|
|
||||||
func (es *ExStruct) SetChildStructBoy(boy int) {
|
|
||||||
es.ChildStruct.boy = boy
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetChildStructGirl Get return girl string
|
|
||||||
func (es *ExStruct) GetChildStructGirl() string {
|
|
||||||
return es.ChildStruct.girl
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetChildStructGirl Set girl string
|
|
||||||
func (es *ExStruct) SetChildStructGirl(girl string) {
|
|
||||||
es.ChildStruct.girl = girl
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetChildStructGirl
|
|
||||||
|
|
||||||
// GetChildStructB Get return B interface{}
|
|
||||||
func (es *ExStruct) GetChildStructB() interface{} {
|
|
||||||
return es.ChildStruct.B
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetChildStructB Set B interface{}
|
|
||||||
func (es *ExStruct) SetChildStructB(B interface{}) {
|
|
||||||
es.ChildStruct.B = B
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetChildStructA set
|
|
||||||
func (es *ExStruct) SetChildStructA(a int) {
|
|
||||||
es.ChildStruct.A = a
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetChildStructA get
|
|
||||||
func (es *ExStruct) GetChildStructA() int {
|
|
||||||
return es.ChildStruct.A
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetC get
|
|
||||||
func (es *ExStruct) GetC(a int) {
|
|
||||||
es.ChildStruct.A = a
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := ExStruct{}
|
a := ExStruct{}
|
||||||
b := MyStruct{}
|
b := MyStruct{}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user