Skip to content

Commit

Permalink
added vscode workspace support
Browse files Browse the repository at this point in the history
  • Loading branch information
janhalfar committed Feb 16, 2021
1 parent 08369c6 commit 2f2d2a1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package gograpple
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"path/filepath"
"strings"
"time"

"github.com/foomo/squadron/util"
Expand All @@ -23,15 +26,16 @@ type launchArgs struct {
ShowLog bool `json:"showLog,omitempty"`
}

func newLaunchArgs(pod, host string, port, iteration int) *launchArgs {
func newLaunchArgs(pod, host string, port, iteration int, workspaceFolder string) *launchArgs {
return &launchArgs{
Host: host,
Name: fmt.Sprintf("delve-%v-run-%v", pod, iteration),
Port: port,
Request: "attach",
Type: "go",
Mode: "remote",
RemotePath: "${workspaceFolder}",
RemotePath: workspaceFolder,

// Trace: "verbose",
// LogOutput: "rpc",
// ShowLog: true,
Expand All @@ -47,7 +51,22 @@ func (la *launchArgs) toJson() (string, error) {
}

func launchVscode(l *logrus.Entry, goModDir, pod, host string, port, tries, iteration int, sleep time.Duration) error {
util.NewCommand(l, "code").Args(goModDir).PostEnd(func() error {

openFile := goModDir
workspaceFolder := "${workspaceFolder}"
// is there a workspace in that dir
files, errReadDir := ioutil.ReadDir(goModDir)
if errReadDir == nil {
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".code-workspace") {
openFile = filepath.Join(goModDir, file.Name())
workspaceFolder = goModDir
break
}
}
}

util.NewCommand(l, "code").Args(openFile).PostEnd(func() error {
return tryCall(tries, time.Millisecond*200, func(i int) error {
l.Infof("waiting for vscode status (%v/%v)", i, tries)
_, err := util.NewCommand(l, "code").Args("-s").Run()
Expand All @@ -56,7 +75,7 @@ func launchVscode(l *logrus.Entry, goModDir, pod, host string, port, tries, iter
}).Run()

l.Infof("opening debug configuration")
la, err := newLaunchArgs(pod, host, port, iteration).toJson()
la, err := newLaunchArgs(pod, host, port, iteration, workspaceFolder).toJson()
if err != nil {
return err
}
Expand Down

0 comments on commit 2f2d2a1

Please sign in to comment.