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

Unable to build on vscode #2901

Closed
byteshiva opened this issue Nov 13, 2019 · 11 comments
Closed

Unable to build on vscode #2901

byteshiva opened this issue Nov 13, 2019 · 11 comments

Comments

@byteshiva
Copy link

byteshiva commented Nov 13, 2019

What did you do?
I'm trying to build go source file using vscode-go gopls on Microsoft vscode. Instead of executing go build on the specific file, it fails to execute the build command.
note:
I'm using go version manager to maintain its different go runtimes.

Here is the code.
https://play.golang.com/p/HhCLwAZhaBk

What did you expect to see?
It should build a specific file.

What did you see instead?
It's not building the specific file.

Build info

golang.org/x/tools/gopls 0.2.0
    golang.org/x/tools/gopls@v0.2.0 h1:ddCHfScTYOG6auAcEKXCFN5iSeKSAnYcPv+7zVJBd+U=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20191108194844-46f05828f2fe h1:FNzasIzfY1IIdyTs/+o3Qv1b7YdffPbBXyjZ5VJJdIA=
    golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
    honnef.co/go/tools@v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=

Go info
go version go1.13.4 linux/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xyz/.cache/go-build"
GOENV="/home/xyz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xyz/.asdf/installs/golang/1.13.4/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/xyz/.asdf/installs/golang/1.13.4/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/xyz/.asdf/installs/golang/1.13.4/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build321841077=/tmp/go-build -gno-record-gcc-switches"

settings on vscode

{
    "go.gopath": "/home/xyz/.asdf/installs/golang/1.13.4/packages",
    "go.goroot": "/home/xyz/.asdf/installs/golang/1.13.4/go",
    "terminal.integrated.shellArgs.linux": ["-l"],
    "terminal.integrated.automationShell.linux": "/bin/bash",
    "go.useLanguageServer": true,
    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        }
    },
    "go.languageServerExperimentalFeatures": {
        "format": true,
        "autoComplete": true,
        "rename": true,
        "goToDefinition": true,
        "hover": true,
        "signatureHelp": true,
        "goToTypeDefinition": true,
        "goToImplementation": true,
        "documentSymbols": true,
        "workspaceSymbols": true,
        "findReferences": true,
        "diagnostics": true,
    },
    "go.languageServerFlags": [
        "-rpc.trace", // for more detailed debug logging
        "serve",
        "--debug=localhost:6060", // to investigate memory usage, see profiles 
    ],
    "gopls": {
        "usePlaceholders": true, // add parameter placeholders when completing a function

        // Experimental settings
        "completeUnimported": true, // autocomplete unimported packages
        "watchFileChanges": true,  // watch file changes outside of the editor
        "deepCompletion": true,     // enable deep completion
    },
    "files.eol": "\n", // formatting only supports LF line endings
}```
@ramya-rao-a
Copy link
Contributor

Thanks for reporting @byteshiva

cc @stamblerre

@ramya-rao-a ramya-rao-a added the upstream-gopls Issue for gopls label Nov 15, 2019
@stamblerre
Copy link
Contributor

@ramya-rao-a: To my understanding, this is not a gopls issue, as gopls does not execute builds within VS Code. The description of the issue is a bit misleading, because while @byteshiva is using gopls, they are not using gopls functionality here.

@byteshiva: Can you share a bit more information about the failure that you are seeing? What logs does VS Code show? Does go build on the command line work?

@byteshiva
Copy link
Author

byteshiva commented Nov 16, 2019

@ramya-rao-a: To my understanding, this is not a gopls issue, as gopls does not execute builds within VS Code. The description of the issue is a bit misleading, because while @byteshiva is using gopls, they are not using gopls functionality here.

@byteshiva: Can you share a bit more information about the failure that you are seeing? What logs does VS Code show?

I'll get the log details.

Does go build on the command line work?

Yes it works on vscode command prompt after making the below changes but it does not seems to execute within vscode command
palette.

"terminal.integrated.automationShell.linux": "/bin/bash",

Since I'm using go version manager which kicks up during bashrc.

  1. https://asdf-vm.com/#/ -- Manage multiple runtime versions with a single CLI tool
    1.1 Plugin for Golang - golang plugin for asdf version manager https://github.com/kennyp/asdf-golang

@byteshiva
Copy link
Author

byteshiva commented Nov 16, 2019

Here are the logs

Starting building the current package at /home/xyz/golang-workspace/wscp
Not able to determine import path of current package by using cwd: /home/xyz/golang-workspace/wscp and Go workspace: 
/home/xyz/golang-workspace/wscp>Finished running tool: /home/xyz/.asdf/installs/golang/1.13.4/go/bin/go build -i -o /tmp/vscode-goMa3odF/go-code-check .

Not able to determine import path of current package by using cwd:

Thanks, --My mistake, Added source code folder in $GOPATH/src/. Now I'm able to build current workspace using command palette using vscode-go extension.

@byteshiva
Copy link
Author

Does "go.buildOnSave": "workspace", work as expected? I don't see this working, maybe I'm missing something here.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Nov 16, 2019

@byteshiva The setting go.buildOnSave is ignored when you are using the language server as the language server is then responsible to provide the diagnostics.

In the issue description you mention that the extension fails to execute the build command. Can you provide more details on how you attempted to build the file?
Are you trying to build using commands like Go: Build Package, Go: Build Workspace or are you expecting build to be triggered when you save a file?

@ramya-rao-a ramya-rao-a added needs more info and removed upstream-gopls Issue for gopls labels Nov 16, 2019
@byteshiva
Copy link
Author

byteshiva commented Nov 17, 2019

@byteshiva The setting go.buildOnSave is ignored when you are using the language server as the language server is then responsible to provide the diagnostics.

In one development profile, the gopls runs on the remote machine and I'd like to explore the language protocol and buildOnSave

In the issue description you mention that the extension fails to execute the build command. Can you provide more details on how you attempted to build the file?
Are you trying to build using commands like Go: Build Package, Go: Build Workspace or are you expecting build to be triggered when you save a file?

The Go:Build Package works as expected but Go: Build Package executes
Go:Build Package Output

Starting building the current package at /home/xyz/.asdf/instjalls/golang/1.13.4/packages/src/swcp
/home/xyz/.asdf/installs/golang/1.13.4/packages/src/swcp>Finished running tool: /home/xyz/.asdf/installs/golang/1.13.4/go/bin/go build -i -o /tmp/vscode-gohkt7n1/go-code-check swcp

but I don't see the output(Maybe I might be missing something here). Also, as you mentioned above I need to disable "go.useLanguageServer": false, to make buildOnSave work.

  1. Are you trying to build using commands like Go: Build Package, Go: Build Workspace

Yes,

  1. or are you expecting build to be triggered when you save a file?

Yes

If possible I'd like to build using the above mentioned steps depending on the dev profile.

@ramya-rao-a
Copy link
Contributor

A few clarifications

  • Go: Build Package and Go: Build Workspace commands will work even if language server is enabled
  • The build process that gets triggered when you save a file will not get triggered if language server is enabled
  • The output pane does not show the output of the build process. If the build process succeeds, it prints out "Finished running tool:". If the build process fails, it prints out the failures. What are you expecting to see in the output pane?

@byteshiva
Copy link
Author

byteshiva commented Nov 19, 2019

A few clarifications

  • Go: Build Package and Go: Build Workspace commands will work even if language server is enabled

Go: Build Package is not working for me. Maybe I'm missing something here.

  • The build process that gets triggered when you save a file will not get triggered if language server is enabled
  • so in this case, when can we expect buildOnSave on language server.
  • The output pane does not show the output of the build process. If the build process succeeds, it prints out "Finished running tool:". If the build process fails, it prints out the failures. What are you expecting to see in the output pane?
  • The go build packages doesn't seems to be working when it's it's via Go: Build Package. Am I missing something here .

@stamblerre
Copy link
Contributor

@byteshiva: What is failing when you run Go: Build Package? I'm not seeing any error messages in the output posted above.

@vscodebot
Copy link

vscodebot bot commented Feb 25, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. Thank you for your contributions.

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

No branches or pull requests

3 participants