Skip to content

Commit 44981e6

Browse files
author
cheikhshift
committed
Update autocomplete, fix line highlighting on vet errors. Add directory upload as means to import project
1 parent 29bab83 commit 44981e6

File tree

7 files changed

+147
-71
lines changed

7 files changed

+147
-71
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[![Maintainability](https://api.codeclimate.com/v1/badges/d46b0bfb51e827632710/maintainability)](https://codeclimate.com/github/thestrukture/IDE/maintainability)
66
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fthestrukture%2FIDE.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fthestrukture%2FIDE?ref=badge_shield)
77

8+
9+
810
## About IDE
911
Just a Go IDE. It features :
1012
- Autocomplete.
@@ -17,9 +19,9 @@ Just a Go IDE. It features :
1719
- Breakpoints and debugging with Delve.
1820
- Regex directory search.
1921
- Automatically lints your code in the background, and suggests code fixes.
22+
2023
## Requirements
21-
- Go v1.15+.
22-
- Git. Git present as a command on your system.
24+
- Go v1.18+.
2325

2426
## First Launch
2527

api/assets/bindata.go

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

api/handlers/rest_POSTApiAct.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ func POSTApiAct(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
2626
apps := methods.GetApps()
2727
app := types.App{Type: "webapp", Name: r.FormValue("name")}
2828
useGos := r.FormValue("usegos")
29+
fullDir := filepath.Join(os.ExpandEnv("$GOPATH"), "src", app.Name)
2930

3031
var err error
3132

3233
dir := os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("name")
3334

3435
if _, err := os.Stat(dir); os.IsNotExist(err) {
35-
if strings.Contains(useGos, "Scratch") {
36+
if strings.Contains(useGos, "Scratch") || strings.Contains(useGos, "Select") {
3637
app.Type = "app"
3738

38-
fullDir := filepath.Join(os.ExpandEnv("$GOPATH"), "src", app.Name)
39+
3940
err = os.MkdirAll(fullDir, 0700)
4041

4142
if err != nil {
@@ -63,13 +64,22 @@ func POSTApiAct(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
6364
}
6465
} else {
6566
app.Type = "app"
67+
6668
}
6769

6870
if err == nil {
6971
apps = append(apps, app)
70-
//Users.Update(bson.M{"uid": me.UID}, me)
72+
7173
methods.SaveApps(apps)
7274
response = templates.Alert(types.Alertbs{Type: "warning", Text: "Success package " + r.FormValue("name") + " was created!", Redirect: "javascript:updateTree()"})
75+
76+
if strings.Contains(useGos, "Select") {
77+
response += fmt.Sprintf(`<h3>Action Required:</h3><br/><button
78+
onclick="uploadDirectory('%s')"
79+
class="btn btn-block btn-primary"
80+
>Upload files</button><br/>`, app.Name)
81+
}
82+
7383
}
7484
} else if r.FormValue("type") == "100" {
7585
plugins := methods.GetPlugins()
@@ -153,9 +163,7 @@ func POSTApiAct(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
153163

154164
if r.FormValue("fmode") == "touch" {
155165
addstr := ""
156-
if !strings.Contains(r.FormValue("path"), ".go") {
157-
addstr = ".go"
158-
}
166+
159167
_, err := os.Create(filepath.Join(os.ExpandEnv("$GOPATH"), "/src/", r.FormValue("pkg"), r.FormValue("prefix"), r.FormValue("path")+addstr))
160168

161169
if err != nil {

api/handlers/rest_POSTApiNew.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func POSTApiNew(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
2020
inputs := []types.Inputs{}
2121
inputs = append(inputs, types.Inputs{Type: "text", Name: "name", Misc: "required", Text: "Package Name"})
2222
inputs = append(inputs, types.Inputs{Type: "hidden", Name: "type", Value: "0"})
23-
inputs = append(inputs, types.Inputs{Type: "select", Misc: "Project type", Name: "usegos", Value: "Scratch", Options: []string{"Scratch", "Existing package"}})
23+
inputs = append(inputs, types.Inputs{Type: "select", Misc: "Project type", Name: "usegos", Value: "Scratch", Options: []string{"Scratch", "Existing package", "Select from folder"}})
2424

2525
response = templates.Modal(types.SModal{Body: "", Title: "Add Package", Color: "#ededed", Form: types.Forms{Link: "/api/act", CTA: "Add Package", Class: "warning btn-block", Buttons: []types.SButton{}, Inputs: inputs}})
2626

api/handlers/rest_POSTApiPut.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func POSTApiPut(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
4747

4848
response = templates.Alert(types.Alertbs{Type: "warning", Text: r.FormValue("target") + " saved!"})
4949
} else if r.FormValue("type") == "30" {
50-
ioutil.WriteFile(os.ExpandEnv("$GOPATH")+"/src/"+filepath.Join(r.FormValue("pkg"), r.FormValue("target")), []byte(r.FormValue("data")), 0777)
50+
ioutil.WriteFile(filepath.Join(os.ExpandEnv("$GOPATH"), "src" ,r.FormValue("pkg"), r.FormValue("target")), []byte(r.FormValue("data")), 0777)
5151

5252
response = templates.Alert(types.Alertbs{Type: "warning", Text: r.FormValue("target") + " saved!"})
5353
} else if r.FormValue("type") == "4" {

gos.gxml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,10 +1732,12 @@ for _, v := range apps {
17321732
response = net_bModal(sModal{Body: "",Title: "Add Package",Color: "#ededed",Form:Forms{Link:"/api/act",CTA:"Add Package",Class:"warning btn-block",Buttons:[]SButton{}, Inputs:inputs }})
17331733

17341734
} else if r.FormValue("type") == "100" {
1735+
17351736
inputs := []Inputs{}
17361737
inputs = append(inputs, Inputs{Type:"text",Name:"name",Misc: "required",Text:"Plugin install path"})
17371738
inputs = append(inputs, Inputs{Type:"hidden", Name: "type" ,Value: "100"})
17381739
response = net_bModal(sModal{Body: "",Title: "PLUGINS",Color: "#ededed",Form:Forms{Link:"/api/act",CTA:"ADD",Class:"warning btn-block",Buttons:[]SButton{}, Inputs:inputs }})
1740+
17391741
} else if r.FormValue("type") == "101" {
17401742

17411743
response = bPluginList(gosweb.NoStruct{})
@@ -1795,6 +1797,9 @@ for _, v := range apps {
17951797
//Users.Update(bson.M{"uid": me.UID}, me)
17961798
methods.SaveApps(apps)
17971799
response = net_bAlert(Alertbs{Type:"warning",Text:"Success package " + r.FormValue("name") + " was created!",Redirect: "javascript:updateTree()"})
1800+
1801+
if strings.Contains(useGos, "Scratch") {
1802+
17981803
}
17991804
} else if r.FormValue("type") == "100" {
18001805
plugins := methods.GetPlugins()

tmpl/js.tmpl

Lines changed: 112 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,93 @@
4848

4949
var termsize = 0;
5050

51+
var dirHandle;
5152

53+
async function uploadDirectory(project){
54+
55+
dirHandle = await window.showDirectoryPicker();
56+
57+
iterateOver(dirHandle, project)
58+
}
59+
60+
const headers = {
61+
"accept": "*/*",
62+
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
63+
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
64+
"sec-fetch-dest": "empty",
65+
"sec-fetch-mode": "cors",
66+
"sec-fetch-site": "same-origin",
67+
"x-requested-with": "XMLHttpRequest"
68+
}
69+
70+
async function iterateOver(dirHandle, project, path = "/"){
71+
72+
var it = dirHandle.entries()
73+
var next = await it.next()
74+
75+
while(!next.done){
76+
77+
const [name, handler] = next.value
78+
79+
if (handler.kind === 'directory') {
80+
// run directory code
81+
let newPath = path == "/" ? path + name : path + "/" + name
82+
//mkdir
83+
await fetch("http://localhost:8884/api/act", {
84+
headers,
85+
"referrer": "http://localhost:8884/",
86+
"referrerPolicy": "strict-origin-when-cross-origin",
87+
"body": `type=60&pkg=${project}&prefix=${path}&path=${name}&basesix=&fmode=dir`,
88+
"method": "POST",
89+
"mode": "cors",
90+
"credentials": "include"
91+
});
92+
93+
await iterateOver(handler, project, newPath)
94+
95+
} else {
96+
97+
// write file
98+
99+
100+
await fetch("http://localhost:8884/api/act", {
101+
headers,
102+
"referrer": "http://localhost:8884/",
103+
"referrerPolicy": "strict-origin-when-cross-origin",
104+
"body": `type=60&pkg=${project}&prefix=${path}&path=${name}&basesix=&fmode=touch`,
105+
"method": "POST",
106+
"mode": "cors",
107+
"credentials": "include"
108+
});
109+
110+
fileData = await handler.getFile();
111+
let text = await fileData.text()
112+
113+
114+
await fetch("http://localhost:8884/api/put", {
115+
headers,
116+
"referrer": "http://localhost:8884/",
117+
"referrerPolicy": "strict-origin-when-cross-origin",
118+
"body": `type=30&target=${path}/${name}&pkg=${project}&data=${encodeURIComponent(text)}`,
119+
"method": "POST",
120+
"mode": "cors",
121+
"credentials": "include"
122+
});
123+
124+
125+
126+
127+
128+
129+
}
130+
131+
132+
next = await it.next()
133+
}
134+
135+
$(".modal .close").click()
136+
updateTree()
137+
}
52138

53139
window.debugFn = (cmd) => {
54140
socketTerminal.send(cmd + " \n");
@@ -351,6 +437,8 @@
351437

352438
return ret
353439
}));
440+
} else {
441+
callback(null, [])
354442
}
355443
}
356444
}
@@ -365,12 +453,14 @@
365453
function vetAndLint(id,pkg, path){
366454
resetVetter(id)
367455
let file = path
368-
let lineArr = {}
456+
457+
let errors = []
369458
$.ajax({type : "POST", data : {
370459
pkg
371460
} ,url: "/api/govet", success:function(html){
372461

373462
let cText = html.Text.split("\n")
463+
374464

375465
for(var i = 1; i < cText.length;i++){
376466

@@ -380,31 +470,22 @@
380470
let lineParts = line.split(":")
381471
if( lineParts[2] ){
382472
let lastBit = lineParts[ lineParts.length - 1]
383-
console.log(lineParts[2], lastBit)
384-
if(!lineArr[lineParts[2]]){
385-
lineArr[ lineParts[2] ] = []
386-
}
387-
388-
lineArr[ lineParts[2] ].push(lastBit)
473+
474+
errors.push({
475+
row: parseInt(lineParts[1]) - 1,
476+
column: 0,
477+
text: lastBit,
478+
type: "warning" //This would give a red x on the gutter
479+
})
480+
389481

390482
}
391483
}
392484
}
485+
486+
editors[id].getSession().setAnnotations(errors)
487+
393488

394-
$(".ace_gutter-cell", "#" + id).each(function(e,i){
395-
let key = $(this).text().trim()
396-
397-
if (lineArr[key] && !$("i", this).length ){
398-
$(this).attr("style", "height:12px;background:yellow;")
399-
400-
$(this).unbind()
401-
$(this).popover({
402-
content : lineArr[key].join("<br />"),
403-
placement : "right"
404-
});
405-
406-
}
407-
})
408489

409490
} });
410491

@@ -416,6 +497,7 @@
416497

417498
let cText = html.Text.split("\n")
418499

500+
419501
for(var i = 0; i < cText.length;i++){
420502

421503
let line = cText[i]
@@ -424,47 +506,26 @@
424506
let lineParts = line.split(":")
425507
if( lineParts[1] ){
426508
let lastBit = lineParts[ lineParts.length - 1]
427-
console.log(lineParts[1], lastBit)
428-
if(!lineArr[lineParts[1]]){
429-
lineArr[ lineParts[1] ] = []
430-
}
509+
510+
errors.push({
511+
row: parseInt(lineParts[1]) - 1,
512+
column: 0,
513+
text: lastBit,
514+
type: "warning" //This would give a red x on the gutter
515+
})
431516

432-
lineArr[ lineParts[1] ].push(lastBit)
433517

434518
}
435519
}
436520
}
437-
console.log(lineArr)
438-
$(".ace_gutter-cell", "#" + id).each(function(e,i){
439-
let key = $(this).text().trim()
440-
441-
if (lineArr[key] && !$("i", this).length ){
442-
$(this).attr("style", "height:12px;background:yellow;")
443-
444-
$(this).unbind()
445-
$(this).popover({
446-
content : lineArr[key].join("<br />"),
447-
placement : "right"
448-
});
449521

450-
}
451-
})
522+
editors[id].getSession().setAnnotations(errors)
452523

453524
} });
454525
}
455526

456527
function resetVetter(id){
457-
$(".ace_gutter-cell", "#" + id).each(function(e,i){
458-
459-
if ( $("i", this).length )
460-
return
461-
462-
463-
464-
let el = $(this)
465-
el.attr("style", "height:12px")
466-
el.unbind()
467-
})
528+
editors[id].getSession().clearAnnotations()
468529
}
469530

470531

0 commit comments

Comments
 (0)