|
|
@ -3,7 +3,6 @@ try { |
|
|
|
|
|
|
|
const vscode = require("vscode") |
|
|
|
const fs = require("fs") |
|
|
|
const axios = require("axios") |
|
|
|
|
|
|
|
let start = vscode.window.activeTextEditor.selection.start.line |
|
|
|
let fileName = vscode.window.activeTextEditor.document.fileName |
|
|
@ -25,14 +24,67 @@ try { |
|
|
|
a = a.replace(" ", " ") |
|
|
|
} |
|
|
|
let b = a.split(" ") |
|
|
|
|
|
|
|
|
|
|
|
if (b[0] != "type" || b[2] != "struct" || b[3] != "{") { |
|
|
|
vscode.window.showErrorMessage("找不到结构") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let struct = b[1] |
|
|
|
|
|
|
|
axios.get("") |
|
|
|
console.log(struct) |
|
|
|
|
|
|
|
var stack = ['{'] |
|
|
|
var endLine = 0 |
|
|
|
var endChar = 0 |
|
|
|
for (var i = start + 1; i < context_arr.length; i++) { |
|
|
|
|
|
|
|
for (let k = 0; k < context_arr[i].length; k++) { |
|
|
|
const element = context_arr[i][k]; |
|
|
|
if (element == '{') { |
|
|
|
stack.push('{') |
|
|
|
} |
|
|
|
if (element == '}') { |
|
|
|
stack.pop() |
|
|
|
} |
|
|
|
if (stack.length == 0) { |
|
|
|
endLine = i |
|
|
|
endChar = k |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (endLine < start) { |
|
|
|
vscode.window.showErrorMessage("结构异常") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let endPosition = vscode.Position(endLine, endChar) |
|
|
|
axios({ |
|
|
|
method: 'get', |
|
|
|
url: 'http://git.ouxuan.net/3136352472/vscode-helper-js/raw/branch/master/hasaki-gen-crud/template.go', |
|
|
|
responseType: 'text' |
|
|
|
}).then(res => { |
|
|
|
console.log("123") |
|
|
|
let text = "" + res['data'] |
|
|
|
let tmp = text.split("// ----------------------------temp------------------------------------") |
|
|
|
|
|
|
|
text = tmp[1] |
|
|
|
text = text.replace(/Temp3A60/g, struct) |
|
|
|
console.log(text) |
|
|
|
|
|
|
|
vscode.window.activeTextEditor.edit(function (textEditorEdit: vscode.TextEditorEdit) { |
|
|
|
|
|
|
|
textEditorEdit.insert( |
|
|
|
endPosition, |
|
|
|
text, |
|
|
|
) |
|
|
|
}) |
|
|
|
// vscode.window.showErrorMessage(res)
|
|
|
|
}).catch(error => { |
|
|
|
vscode.window.showErrorMessage(`err:${error.message}`) |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|