Skip to content

Commit

Permalink
Add support for Delve
Browse files Browse the repository at this point in the history
  • Loading branch information
cheikhshift committed Dec 12, 2020
1 parent 8772c93 commit f55c66e
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Test Coverage](https://api.codeclimate.com/v1/badges/d46b0bfb51e827632710/test_coverage)](https://codeclimate.com/github/thestrukture/IDE/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/d46b0bfb51e827632710/maintainability)](https://codeclimate.com/github/thestrukture/IDE/maintainability)

Go lang IDE server. Built with [GopherSauce](http://gophersauce.com)
Go lang IDE. Built with [GopherSauce](http://gophersauce.com)

## About project
The strukture is an open source IDE. It is designed to build web applications, with the organizational help of [GopherSauce](http://gophersauce.com). The IDE runs as a server and is accessed via web browser. Being a web server, the IDE is accessible from any device on your network.Compared to Microsoft VS Code and Eclipse CHE, this IDE is very minimalistic. It features :
Expand All @@ -19,8 +19,8 @@ The strukture is an open source IDE. It is designed to build web applications, w
- Build docker images (Must have docker running on host) .

## Requirements
- Go v1.10+.
- [GopherSauce](http://gophersauce.com) if using `makefile`.
- Go v1.13+.


## Install

Expand Down
8 changes: 4 additions & 4 deletions api/assets/bindata.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions api/handlers/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func ApiAttempt(w http.ResponseWriter, r *http.Request) (callmet bool) {

response, callmet = POSTApiAct(w, r, session)

} else if isURL := (r.URL.Path == "/api/breakpoints" && r.Method == strings.ToUpper("POST")); !callmet && isURL {

response, callmet = POSTApiBreakpoints(w, r, session)

This comment has been minimized.

Copy link
@iamwavecut

iamwavecut Dec 29, 2020

@cheikhshift it seems, that you forgot to commit POSTApiBreakpoints handler file.

#6

This comment has been minimized.

Copy link
@cheikhshift

cheikhshift Jan 2, 2021

Author Member

Sorry for the delay, thank you again for the alert.


} else if isURL := (r.URL.Path == "/api/put" && r.Method == strings.ToUpper("POST")); !callmet && isURL {

response, callmet = POSTApiPut(w, r, session)
Expand Down
5 changes: 5 additions & 0 deletions api/handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,8 @@ func TestPOSTApiConsole(t *testing.T) {
func TestApiTerminal_realtime(t *testing.T) {

}

func TestPOSTApiBreakpoints(t *testing.T) {

t.Error("Test for handler POSTApiBreakpoints not implemented!!")
}
50 changes: 49 additions & 1 deletion gos.gxml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@
core.RunCmdSmart("go get github.com/golang/dep/cmd/dep")
}

if _, err := os.Stat(os.ExpandEnv("$GOPATH") + "/src/github.com/go-delve/delve/cmd/dlv"); os.IsNotExist(err) {
fmt.Println("Delve not present, installing from github.com/go-delve/delve/cmd/dlv")
core.RunCmdSmart("go get github.com/go-delve/delve/cmd/dlv")
}



autocompletePath = filepath.Join(os.ExpandEnv("$GOPATH"), "strukture-autocomplete")

if _, err := os.Stat(autocompletePath); os.IsNotExist(err) {
Expand Down Expand Up @@ -1776,7 +1783,48 @@ for _, v := range apps {
}
}
</end>


<end path="/api/breakpoints" type="POST">

id := r.FormValue("id")
m := make(map[string]string)

var pkgpath = core.TrimSuffix(os.ExpandEnv("$GOPATH"), "/")+"/src/"+ id +"/"

if Windows {
pkgpath = strings.Replace(pkgpath,"/", "\\", -1)
}

_ = filepath.Walk(pkgpath, func(path string, file os.FileInfo, _ error) error {
//fmt.Println(path)
if file.IsDir() {

files, _ := ioutil.ReadDir(path)

for _, f := range files {
if !f.IsDir() && strings.Contains(f.Name(), "go-breakpoints") {
var mjk string

mjk = strings.Replace(path, pkgpath, "",-1) + "/" + f.Name()
if Windows {
mjk = strings.Replace(mjk, "/", "\\", -1)
}

data,_ := ioutil.ReadFile(filepath.Join(path, f.Name()))

m[mjk] = string(data)

}
}
}

return nil
})

response = mResponse(m)

</end>

<end path="/api/put" method="mPut" type="POST" >
me := SoftUser{Email:"Strukture user", Username:"Strukture user"}

Expand Down
5 changes: 5 additions & 0 deletions launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func LaunchServer() {
core.RunCmdSmart("go get github.com/golang/dep/cmd/dep")
}

if _, err := os.Stat(os.ExpandEnv("$GOPATH") + "/src/github.com/go-delve/delve/cmd/dlv"); os.IsNotExist(err) {
fmt.Println("Delve not present, installing from github.com/go-delve/delve/cmd/dlv")
core.RunCmdSmart("go get github.com/go-delve/delve/cmd/dlv")
}

globals.AutocompletePath = filepath.Join(os.ExpandEnv("$GOPATH"), "strukture-autocomplete")

if _, err := os.Stat(globals.AutocompletePath); os.IsNotExist(err) {
Expand Down
89 changes: 88 additions & 1 deletion tmpl/js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,25 @@

if(working)
term.set_prompt('>')

if(event.data.includes("(dlv)")){
window.$startMap = true;
term.set_prompt('>')
}


if(window.$awaitDelve && window.$startMap){
var br = window.$breakpoints[ window.$arrayIndex ];
if(!br)
delete window.$awaitDelve
else {

socketTerminal.send(br + "\n");
window.$arrayIndex++;
}


}
});

jQuery(function($, undefined) {
Expand Down Expand Up @@ -678,12 +697,35 @@
StartServer($node.original.appid);
}
};
menu["Stop"] = {

menu["Stop"] = {
"label": "Stop",
"action": function (obj) {
StopServer($node.original.appid);
}
};

menu["Debug"] = {
"label": "Launch Delve",
"action": function (obj) {

socketTerminal.send('cd $GOPATH/src/' + $node.original.appid + "\n");


setTimeout(() => {

$.ajax({url:"/api/breakpoints", data: { id : $node.original.appid } ,type:"POST",success:function(html){
completeDelvLaunch(html, $node.original.appid);
},error:function(e){
completeDelvLaunch(e.responseText, $node.original.appid);
}
});



}, 2000)
}
};
}

if ($node.original.mtype){
Expand Down Expand Up @@ -724,6 +766,51 @@
});
});


function completeDelvLaunch(data, appid){
var keys = Object.keys(data);
var breakpoints = [];

for (var i = keys.length - 1; i >= 0; i--) {
var k = keys[i];
var brs = JSON.parse(data[k]);
if(k[0] == "/"){

k = k.substr(1, k.length);
}


for(var v = 0; v < brs.length;v++){

var ent = brs[v];

if(ent){
breakpoints.push(`break ${k.replace("-breakpoints", "")}:${v + 1}`);
}


}

}

window.$awaitDelve = true;
window.$breakpoints = breakpoints;
window.$arrayIndex = 0;
window.$startMap = false;

setTimeout(() => {
socketTerminal.send('dlv debug --allow-non-terminal-interactive ' + appid + " \n");
}, 3500)


if(!$(".terminal-side").hasClass('active')){
$(".terminal-side").addClass('active');
$(".terminal-side").css('display','block');
}


}

function makeid()
{
var text = "";
Expand Down

0 comments on commit f55c66e

Please sign in to comment.