Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

is there a way to "build and run package" ? #299

Closed
tubzby opened this issue Apr 18, 2016 · 8 comments
Closed

is there a way to "build and run package" ? #299

tubzby opened this issue Apr 18, 2016 · 8 comments
Assignees

Comments

@tubzby
Copy link

tubzby commented Apr 18, 2016

I'm new to vs code(from "IntelliJ IDEA"), in my practise, "build and run package" in IDEA is very usefull.
For me, the only way to accomplish this is to create a tasks.json like this:

{
    // See http://go.microsoft.com/fwlink/?LinkId=733558\n
    // for the documentation about the tasks.json format\n
    "version": "0.1.0",
    "echoCommand": true,
    "isShellCommand": true,
    "showOutput": "always",
    "suppressTaskName": true,
    "windows": {
        "command": "cmd",
        "args": [
            "/C"
        ]
    },
    "osx": {
        "command": "bash",
        "args": [
            "-c"
        ]
    },
    "tasks": [
        {
            "taskName": "build",
            "isBuildCommand": true,
            "args": [
                "go build $packagenames"
            ]
        },
        {
            "taskName": "run",          
            "isTestCommand": true,
            "args":[
                "./$packagename $args"
            ]
        }
    ]
}

then command + shift + B to build and command + shift + T to run a test.
unfortunately, the shell console doesn't accept input "ctrl-c", so i can't stop the program after startup.

Is there any quick way to "build and run package"?
I know debugging package is working, but not sure if it will cause performance issue or not.

@josefcs
Copy link

josefcs commented Sep 11, 2016

Is there any news on this, or have you been able to resolve this?

@ramya-rao-a
Copy link
Contributor

Assuming your launch config is set to point to the package, wouldn't just hitting F5 work ?

@ramya-rao-a
Copy link
Contributor

Looks like this should be doable as per microsoft/vscode#2780
Will try to get this in in the next update

@ramya-rao-a
Copy link
Contributor

In the latest update (0.6.56), you can
- Press Ctrl+F5 or run the command Debug: Start Without Debugging to run using the currently selected launch configuration.
- If you don't have a launch.json file, then the current file will be run.
- Supported only for launch configs with type as debug and program that points to a Go file and not package

@gosp
Copy link

gosp commented Aug 15, 2017

@ramya-rao-a it is a pity that GOPATH which is configured in settings.json isn't recognized by Debug: Start Without Debugging. I MUST reconfigure them in launch.json

the example of .vscode\settings.json

{
    "go.inferGopath": true,
    "go.toolsGopath": "D:\\SourceCode\\golang"
}

@ramya-rao-a
Copy link
Contributor

@gosp We do send GOPATH as configured in settings.json to the Debug: Start Without Debugging command.

I have similar setting as yours where go.inferGopath is true and I have set a toolsGopath and nothing else. GOPATH is not configured as env var outside of VS Code either. And Debug: Start Without Debugging uses the inferred Gopath in my case.

  • Run Go: Current GOPATH command and ensure what you see is what you expect your GOPATH to be
  • Clear out GOPATH from env property of your debug configurations in launch.json if you have any and try again?

@gosp
Copy link

gosp commented Aug 17, 2017

vscode golang extension is installed General GOPATH: "D:\\SourceCode\\golang"
So I MUST set "go.toolsGopath".
After Go: Current GOPATH:
Current gopath Current GOPATH is inferred from workspace root: d:\SourceCode\etc.project\server

Errors:

main.go:11:2: cannot find package "github.com/go-chi/chi" in any of:
	D:\Tools\go\src\github.com\go-chi\chi (from $GOROOT)
	D:\SourceCode\golang\src\github.com\go-chi\chi (from $GOPATH)

The error means it can't find package which is in vendor folder.

.vscode\launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${fileDirname}",
            "env": {},
            "args": [],
            "showLog": true
        }
    ]
}

@ramya-rao-a
Copy link
Contributor

@gosp I can repro now. This is because, the debug adapter cannot read the settings. This is being tracked in #840. I have a way to get around this in mind, please follow #840 for now.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants