TODO: 识别出注释的行.
This commit is contained in:
parent
b88cbd8391
commit
037fe62588
114
src/extension.ts
114
src/extension.ts
@ -4,23 +4,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { resolve } from 'url';
|
||||
import { rejects } from 'assert';
|
||||
import { prototype } from 'events';
|
||||
|
||||
class StructInfo {
|
||||
ShorthandName: string;
|
||||
Name: string;
|
||||
Range: number[];
|
||||
Fields: Field[];
|
||||
Fields: Map<string, Field>;
|
||||
|
||||
constructor(name: string, fields: Field[], range: number[]) {
|
||||
this.Name = name;
|
||||
|
||||
var sname: string = "";
|
||||
sname += this.Name[0].toLowerCase();
|
||||
for (let i = 1; i < this.Name.length; i++) {
|
||||
let c = this.Name.charCodeAt(i);
|
||||
if (c <= 90 && c >= 65) {
|
||||
sname += this.Name[i].toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
this.ShorthandName = this.Name;
|
||||
this.Range = range;
|
||||
this.Fields = fields;
|
||||
|
||||
this.Fields = new Map<string, Field>();
|
||||
fields.forEach((value)=>{
|
||||
this.Fields.set(value.Key, value);
|
||||
});
|
||||
}
|
||||
|
||||
getFieldsString(): string[] {
|
||||
var result: string[] = [];
|
||||
|
||||
this.Fields.forEach((field, index) => {
|
||||
result.push( "("+index+") " + this.Name + field.Parent + field.Name + " " + field.Type);
|
||||
result.push(this.Name + field.toString());
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -32,12 +51,18 @@ class Field {
|
||||
Type: string;
|
||||
Name: string;
|
||||
Range: number[];
|
||||
Key: string;
|
||||
|
||||
constructor(parent: string, type: string, name: string, range: number[]) {
|
||||
this.Parent = parent;
|
||||
this.Type = type;
|
||||
this.Name = name;
|
||||
this.Range = range;
|
||||
this.Key = (this.Parent.substr(1) + this.Name).replace(".", "");
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.Parent.substr(1) + this.Name + " " + this.Type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,13 +78,88 @@ function activate(context: vscode.ExtensionContext) {
|
||||
let sinfo = GetStruct();
|
||||
if (sinfo) {
|
||||
console.log(sinfo);
|
||||
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
if (editor !== undefined) {
|
||||
|
||||
let regexFunction = `func {0,}\\(.+${sinfo.Name} {0,}\\) {0,}[GS]et([a-zA-Z_]+) {0,}\\(`;
|
||||
// console.log(regexFunction);
|
||||
let existsStructFunctions: Set<string> = new Set<string>();
|
||||
for (let n = 0; n < editor.document.lineCount; n++) {
|
||||
let line = editor.document.lineAt(n);
|
||||
let matches = line.text.match(regexFunction);
|
||||
if (matches !== null) {
|
||||
console.log(matches[0], matches[1]);
|
||||
existsStructFunctions.add(matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
const options = <vscode.QuickPickOptions>{ canPickMany: true, placeHolder: "select the fields that would be generator get set" };
|
||||
vscode.window.showQuickPick(sinfo.getFieldsString(), options).then( (input)=>{
|
||||
if(typeof(input) !== "string") {
|
||||
var selections: string[] = input as any;
|
||||
console.log(selections); // TODO:
|
||||
var items: vscode.QuickPickItem[] = [];
|
||||
var obj = {
|
||||
info: sinfo,
|
||||
exists: existsStructFunctions,
|
||||
items: function() {
|
||||
this.info.Fields.forEach( (value, key) => {
|
||||
if(this.exists.has(key)) {
|
||||
vscode.window.showInformationMessage("Get" + key + "or Set" + key + " is Exists");
|
||||
} else {
|
||||
items.push( <vscode.QuickPickItem> {
|
||||
label: value.toString(),
|
||||
detail: this.info.Name,
|
||||
description: key,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
pick: function() {
|
||||
this.items();
|
||||
vscode.window.showQuickPick(items, options).then( (item) => {
|
||||
if(item) {
|
||||
console.log("123", item, this.info.Name);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
obj.pick();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// const pickThen = function (input: string | undefined) {
|
||||
// if (typeof (input) !== "string") {
|
||||
// var selections: string[] = input as any;
|
||||
// console.log(selections); // TODO: search exists function
|
||||
// selections.forEach((selection) => {
|
||||
// let infos = selection.match(`(\\d+)\\) ([^\\.]+)([^ ]+) (.+)`);
|
||||
// if (infos) {
|
||||
// // console.log("infos", selection, infos);
|
||||
// console.log("arguments", arguments, prototype);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// vscode.window.showQuickPick(sinfo.getFieldsString(), options).then( (input) => {
|
||||
// if(typeof(input) !== "string") {
|
||||
// var selections: string[] = input as any;
|
||||
// console.log(selections); // TODO: search exists function
|
||||
|
||||
// selections.forEach( (selection)=>{
|
||||
// let infos = selection.match(`(\\d+)\\) ([^\\.]+)([^ ]+) (.+)`);
|
||||
// if(infos) {
|
||||
// console.log("infos",selection, infos);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -50,6 +50,16 @@ func (e *ExStruct) SetChildStructA(a int) {
|
||||
e.ChildStruct.A = a
|
||||
}
|
||||
|
||||
// GetChildStructA get
|
||||
func (e *ExStruct) GetChildStructA(a int) {
|
||||
e.ChildStruct.A = a
|
||||
}
|
||||
|
||||
// GetC get
|
||||
func (e *ExStruct) GetC(a int) {
|
||||
e.ChildStruct.A = a
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := ExStruct{}
|
||||
b := MyStruct{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user