预发布.
This commit is contained in:
parent
7a53ca4d8c
commit
c9db603737
11
package.json
11
package.json
|
@ -26,6 +26,17 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"colors": [
|
||||||
|
{
|
||||||
|
"id": "QuicklyGenerator.StructSelected",
|
||||||
|
"description": "Background decoration color for large numbers",
|
||||||
|
"defaults": {
|
||||||
|
"dark": "#3bcf1655",
|
||||||
|
"light": "#d45b0a55",
|
||||||
|
"highContrast": "#9806db55"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "Go-Quickly-Generator.Go-Gen-GetSet",
|
"command": "Go-Quickly-Generator.Go-Gen-GetSet",
|
||||||
|
|
|
@ -55,10 +55,8 @@ class Field {
|
||||||
this.Parent = parent;
|
this.Parent = parent;
|
||||||
this.Type = type;
|
this.Type = type;
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Range = range;
|
this.Range = range
|
||||||
|
|
||||||
this.Key = (this.Parent.substr(1) + this.Name[0].toUpperCase() + this.Name.substr(1)).replace(new RegExp("\\.", "g"), "");
|
this.Key = (this.Parent.substr(1) + this.Name[0].toUpperCase() + this.Name.substr(1)).replace(new RegExp("\\.", "g"), "");
|
||||||
// TODO: 大小写Map的问题
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
|
@ -66,8 +64,13 @@ class Field {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let typeMap = new Map<string, GeneratorType>() ;
|
let typeMap = new Map<string, GeneratorType>();
|
||||||
let typeCharMap = new Map<GeneratorType, string>() ;
|
let typeCharMap = new Map<GeneratorType, string>();
|
||||||
|
|
||||||
|
const dtype = vscode.window.createTextEditorDecorationType({
|
||||||
|
cursor: 'crosshair',
|
||||||
|
backgroundColor: { id: 'QuicklyGenerator.StructSelected' }
|
||||||
|
});
|
||||||
|
|
||||||
// this method is called when your extension is activated
|
// this method is called when your extension is activated
|
||||||
// your extension is activated the very first time the command is executed
|
// your extension is activated the very first time the command is executed
|
||||||
|
@ -88,43 +91,45 @@ function activate(context: vscode.ExtensionContext) {
|
||||||
// The code you place here will be executed every time your command is executed
|
// The code you place here will be executed every time your command is executed
|
||||||
// Display a message box to the user
|
// Display a message box to the user
|
||||||
let sinfo = GetStruct();
|
let sinfo = GetStruct();
|
||||||
if(sinfo) {
|
let editor = vscode.window.activeTextEditor;
|
||||||
|
if (sinfo && editor) {
|
||||||
|
|
||||||
vscode.window.showQuickPick(["Getter", "Setter"], <vscode.QuickPickOptions>{canPickMany: true, placeHolder: "select generator type getter or setter"}).then( items => {
|
let decoration = <vscode.DecorationOptions>{ range: new vscode.Range(sinfo.Range[0], 0, sinfo.Range[1] + 1, 0) };
|
||||||
|
editor.setDecorations(dtype, [decoration]);
|
||||||
|
|
||||||
|
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) {
|
||||||
let myitems = items as any as string[];
|
let myitems = items as any as string[];
|
||||||
let t = 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) {
|
||||||
t = t | sel;
|
gtype = gtype | sel;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(sinfo) {
|
if (sinfo) {
|
||||||
GeneratorSetGet(sinfo, t);
|
GeneratorSetGet(sinfo, gtype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let editor = vscode.window.activeTextEditor;
|
||||||
|
if(editor) {
|
||||||
|
editor.setDecorations(dtype, []);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// GeneratorSetGet(sinfo, GeneratorType.Getter | GeneratorType.Setter);
|
|
||||||
} 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)");
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// context.subscriptions.push(vscode.languages.registerCodeActionsProvider(
|
// context.subscriptions.push(vscode.languages.registerCodeActionsProvider(
|
||||||
// "go", new Provider(), { providedCodeActionKinds: [vscode.CodeActionKind.Source] }
|
// "go", new Provider(), { providedCodeActionKinds: [vscode.CodeActionKind.Source] }
|
||||||
// ));
|
// ));
|
||||||
|
|
||||||
|
|
||||||
context.subscriptions.push(vscode.commands.registerCommand('Go-Quickly-Generator.Getter', function () {
|
|
||||||
let editor = vscode.window.activeTextEditor;
|
|
||||||
if (editor !== undefined) {
|
|
||||||
const currentPos = editor.selection.active;
|
|
||||||
const lineCount = editor.document.lineCount;
|
|
||||||
// let selection = editor.selection;
|
|
||||||
// let lineText = editor.document.lineAt(selection.active);
|
|
||||||
// vscode.window.showInformationMessage( lineText.text );
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAbbreviation(name: string): string | undefined {
|
function getAbbreviation(name: string): string | undefined {
|
||||||
|
@ -142,7 +147,7 @@ function getAbbreviation(name: string): string | undefined {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum GeneratorType {
|
enum GeneratorType {
|
||||||
Unknown = 0 ,
|
Unknown = 0,
|
||||||
Setter = 1 << 0,
|
Setter = 1 << 0,
|
||||||
Getter = 1 << 1,
|
Getter = 1 << 1,
|
||||||
}
|
}
|
||||||
|
@ -201,21 +206,21 @@ function GeneratorSetGet(sinfo: StructInfo, stype: GeneratorType) {
|
||||||
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));
|
||||||
|
|
|
@ -25,6 +25,26 @@ type MyStruct2 struct {
|
||||||
S struct{ A struct{ C interface{} } }
|
S struct{ A struct{ C interface{} } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSAC Set C interface{}
|
||||||
|
func (ms *MyStruct2) SetSAC(C interface{}) {
|
||||||
|
ms.S.A.C = C
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetKey Get return Key string
|
||||||
|
func (ms *MyStruct2) GetKey() string {
|
||||||
|
return ms.Key
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetKey Set Key string
|
||||||
|
func (ms *MyStruct2) SetKey(Key string) {
|
||||||
|
ms.Key = Key
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetValue Get return Value int
|
||||||
|
func (ms *MyStruct2) GetValue() int {
|
||||||
|
return ms.Value
|
||||||
|
}
|
||||||
|
|
||||||
// DoFunc 非常丑陋
|
// DoFunc 非常丑陋
|
||||||
func DoFunc(a func(
|
func DoFunc(a func(
|
||||||
a int,
|
a int,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user