Skip to content

Commit

Permalink
Update autocomplete, fix line highlighting on vet errors. Add directo…
Browse files Browse the repository at this point in the history
…ry upload as means to import project
  • Loading branch information
cheikhshift committed Aug 23, 2022
1 parent 29bab83 commit 44981e6
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 71 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/d46b0bfb51e827632710/maintainability)](https://codeclimate.com/github/thestrukture/IDE/maintainability)
[![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)



## About IDE
Just a Go IDE. It features :
- Autocomplete.
Expand All @@ -17,9 +19,9 @@ Just a Go IDE. It features :
- Breakpoints and debugging with Delve.
- Regex directory search.
- Automatically lints your code in the background, and suggests code fixes.

## Requirements
- Go v1.15+.
- Git. Git present as a command on your system.
- Go v1.18+.

## First Launch

Expand Down
20 changes: 10 additions & 10 deletions api/assets/bindata.go

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions api/handlers/rest_POSTApiAct.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ func POSTApiAct(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
apps := methods.GetApps()
app := types.App{Type: "webapp", Name: r.FormValue("name")}
useGos := r.FormValue("usegos")
fullDir := filepath.Join(os.ExpandEnv("$GOPATH"), "src", app.Name)

var err error

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

if _, err := os.Stat(dir); os.IsNotExist(err) {
if strings.Contains(useGos, "Scratch") {
if strings.Contains(useGos, "Scratch") || strings.Contains(useGos, "Select") {
app.Type = "app"

fullDir := filepath.Join(os.ExpandEnv("$GOPATH"), "src", app.Name)

err = os.MkdirAll(fullDir, 0700)

if err != nil {
Expand Down Expand Up @@ -63,13 +64,22 @@ func POSTApiAct(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
}
} else {
app.Type = "app"

}

if err == nil {
apps = append(apps, app)
//Users.Update(bson.M{"uid": me.UID}, me)

methods.SaveApps(apps)
response = templates.Alert(types.Alertbs{Type: "warning", Text: "Success package " + r.FormValue("name") + " was created!", Redirect: "javascript:updateTree()"})

if strings.Contains(useGos, "Select") {
response += fmt.Sprintf(`<h3>Action Required:</h3><br/><button
onclick="uploadDirectory('%s')"
class="btn btn-block btn-primary"
>Upload files</button><br/>`, app.Name)
}

}
} else if r.FormValue("type") == "100" {
plugins := methods.GetPlugins()
Expand Down Expand Up @@ -153,9 +163,7 @@ func POSTApiAct(w http.ResponseWriter, r *http.Request, session *sessions.Sessio

if r.FormValue("fmode") == "touch" {
addstr := ""
if !strings.Contains(r.FormValue("path"), ".go") {
addstr = ".go"
}

_, err := os.Create(filepath.Join(os.ExpandEnv("$GOPATH"), "/src/", r.FormValue("pkg"), r.FormValue("prefix"), r.FormValue("path")+addstr))

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/handlers/rest_POSTApiNew.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func POSTApiNew(w http.ResponseWriter, r *http.Request, session *sessions.Sessio
inputs := []types.Inputs{}
inputs = append(inputs, types.Inputs{Type: "text", Name: "name", Misc: "required", Text: "Package Name"})
inputs = append(inputs, types.Inputs{Type: "hidden", Name: "type", Value: "0"})
inputs = append(inputs, types.Inputs{Type: "select", Misc: "Project type", Name: "usegos", Value: "Scratch", Options: []string{"Scratch", "Existing package"}})
inputs = append(inputs, types.Inputs{Type: "select", Misc: "Project type", Name: "usegos", Value: "Scratch", Options: []string{"Scratch", "Existing package", "Select from folder"}})

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}})

Expand Down
2 changes: 1 addition & 1 deletion api/handlers/rest_POSTApiPut.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func POSTApiPut(w http.ResponseWriter, r *http.Request, session *sessions.Sessio

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

response = templates.Alert(types.Alertbs{Type: "warning", Text: r.FormValue("target") + " saved!"})
} else if r.FormValue("type") == "4" {
Expand Down
5 changes: 5 additions & 0 deletions gos.gxml
Original file line number Diff line number Diff line change
Expand Up @@ -1732,10 +1732,12 @@ for _, v := range apps {
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 }})

} else if r.FormValue("type") == "100" {

inputs := []Inputs{}
inputs = append(inputs, Inputs{Type:"text",Name:"name",Misc: "required",Text:"Plugin install path"})
inputs = append(inputs, Inputs{Type:"hidden", Name: "type" ,Value: "100"})
response = net_bModal(sModal{Body: "",Title: "PLUGINS",Color: "#ededed",Form:Forms{Link:"/api/act",CTA:"ADD",Class:"warning btn-block",Buttons:[]SButton{}, Inputs:inputs }})

} else if r.FormValue("type") == "101" {

response = bPluginList(gosweb.NoStruct{})
Expand Down Expand Up @@ -1795,6 +1797,9 @@ for _, v := range apps {
//Users.Update(bson.M{"uid": me.UID}, me)
methods.SaveApps(apps)
response = net_bAlert(Alertbs{Type:"warning",Text:"Success package " + r.FormValue("name") + " was created!",Redirect: "javascript:updateTree()"})

if strings.Contains(useGos, "Scratch") {

}
} else if r.FormValue("type") == "100" {
plugins := methods.GetPlugins()
Expand Down
163 changes: 112 additions & 51 deletions tmpl/js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,93 @@

var termsize = 0;

var dirHandle;

async function uploadDirectory(project){

dirHandle = await window.showDirectoryPicker();

iterateOver(dirHandle, project)
}

const headers = {
"accept": "*/*",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
}

async function iterateOver(dirHandle, project, path = "/"){

var it = dirHandle.entries()
var next = await it.next()

while(!next.done){

const [name, handler] = next.value

if (handler.kind === 'directory') {
// run directory code
let newPath = path == "/" ? path + name : path + "/" + name
//mkdir
await fetch("http://localhost:8884/api/act", {
headers,
"referrer": "http://localhost:8884/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `type=60&pkg=${project}&prefix=${path}&path=${name}&basesix=&fmode=dir`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});

await iterateOver(handler, project, newPath)

} else {

// write file


await fetch("http://localhost:8884/api/act", {
headers,
"referrer": "http://localhost:8884/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `type=60&pkg=${project}&prefix=${path}&path=${name}&basesix=&fmode=touch`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});

fileData = await handler.getFile();
let text = await fileData.text()


await fetch("http://localhost:8884/api/put", {
headers,
"referrer": "http://localhost:8884/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `type=30&target=${path}/${name}&pkg=${project}&data=${encodeURIComponent(text)}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});






}


next = await it.next()
}

$(".modal .close").click()
updateTree()
}

window.debugFn = (cmd) => {
socketTerminal.send(cmd + " \n");
Expand Down Expand Up @@ -351,6 +437,8 @@

return ret
}));
} else {
callback(null, [])
}
}
}
Expand All @@ -365,12 +453,14 @@
function vetAndLint(id,pkg, path){
resetVetter(id)
let file = path
let lineArr = {}

let errors = []
$.ajax({type : "POST", data : {
pkg
} ,url: "/api/govet", success:function(html){

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


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

Expand All @@ -380,31 +470,22 @@
let lineParts = line.split(":")
if( lineParts[2] ){
let lastBit = lineParts[ lineParts.length - 1]
console.log(lineParts[2], lastBit)
if(!lineArr[lineParts[2]]){
lineArr[ lineParts[2] ] = []
}

lineArr[ lineParts[2] ].push(lastBit)

errors.push({
row: parseInt(lineParts[1]) - 1,
column: 0,
text: lastBit,
type: "warning" //This would give a red x on the gutter
})


}
}
}

editors[id].getSession().setAnnotations(errors)


$(".ace_gutter-cell", "#" + id).each(function(e,i){
let key = $(this).text().trim()

if (lineArr[key] && !$("i", this).length ){
$(this).attr("style", "height:12px;background:yellow;")

$(this).unbind()
$(this).popover({
content : lineArr[key].join("<br />"),
placement : "right"
});

}
})

} });

Expand All @@ -416,6 +497,7 @@

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


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

let line = cText[i]
Expand All @@ -424,47 +506,26 @@
let lineParts = line.split(":")
if( lineParts[1] ){
let lastBit = lineParts[ lineParts.length - 1]
console.log(lineParts[1], lastBit)
if(!lineArr[lineParts[1]]){
lineArr[ lineParts[1] ] = []
}

errors.push({
row: parseInt(lineParts[1]) - 1,
column: 0,
text: lastBit,
type: "warning" //This would give a red x on the gutter
})

lineArr[ lineParts[1] ].push(lastBit)

}
}
}
console.log(lineArr)
$(".ace_gutter-cell", "#" + id).each(function(e,i){
let key = $(this).text().trim()

if (lineArr[key] && !$("i", this).length ){
$(this).attr("style", "height:12px;background:yellow;")

$(this).unbind()
$(this).popover({
content : lineArr[key].join("<br />"),
placement : "right"
});

}
})
editors[id].getSession().setAnnotations(errors)

} });
}

function resetVetter(id){
$(".ace_gutter-cell", "#" + id).each(function(e,i){

if ( $("i", this).length )
return



let el = $(this)
el.attr("style", "height:12px")
el.unbind()
})
editors[id].getSession().clearAnnotations()
}


Expand Down

0 comments on commit 44981e6

Please sign in to comment.