vscode-go | Go extension for Visual Studio Code
kandi X-RAY | vscode-go Summary
kandi X-RAY | vscode-go Summary
Go extension for Visual Studio Code
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of vscode-go
vscode-go Key Features
vscode-go Examples and Code Snippets
Community Discussions
Trending Discussions on vscode-go
QUESTION
I am using VSCode and vscode-go
to develop the Go application,but, sometime, I got this error, and can't jump to the code definination
How can I get past this error message and get back all gopls features?
...ANSWER
Answered 2021-Jun-02 at 07:45As explained in golang/vscode-go
issue 1229:
The error message indicates the go.mod file is incomplete and needs update.
Check the "
PROBLEMS
" view (Ctrl+Shift+P> "Problems: Focus On Problems View
" ), find the error-level problem (probably in thego.mod
file), and either choose the Quick Fix or check the light bulb.Or, simply open the
go.mod
file and run 'go mod tidy
' using the code lens at the top of the file.
Obviously, make sure you are using the latest versions (of Go, VSCode and vscode-go, as well as gopls)
QUESTION
I am downloading Go on my Ubuntu 16.04 computer. I am following this tutorial and I can't progress from this part on youtube https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1810s:
When I created that Main.go an error on VSC console shows up:
...ANSWER
Answered 2021-Feb-26 at 03:44I am guessing the error message comes from https://github.com/golang/go/blob/release-branch.go1.16/src/cmd/go/internal/modload/init.go#L207-L210
In the last line of your ~/.bashrc, you meant export GOPATH=$GOPATH:...
, not export GOPATH=$gopath:...
. Since $gopath is not set, your GOPATH would end up being :/home/santiagoquinteros/code
. The above code doesn't like it.
As others said, you don't need to set GOROOT
. With go1.16, the module mode is the default, so you probably don't need to set GOPATH
but live with the default GOPATH
which is $HOME/go
.
Many things have changed recently. I recommend newer sets of materials like https://golang.org/doc/#getting-started, https://learn.go.dev, https://play-with-go.dev/ , ...
QUESTION
It is my first time coding in Go. I am following an example and I succesfully can run the small applcation bellow. But I can't find a reason for not been ran in Visual Studio Code. So far I can see, I follow the suggestion found in this answer saying: "... Since your package is outside of $GOPATH, you may need to create a module file. You'll need to init your go module using".
go.mod
...ANSWER
Answered 2020-Aug-25 at 12:14Thanks to discussion in Go Slack (GOPHERS), someone guided me to this solution. Hopefully it can help future readers.
1 - add program and cwd as bellow to launch
QUESTION
When I type console.lo
in a .js
file in Visual Studio Code, I can hit Enter
, and autocomplete will change my line to console.log
. However, I would also like autocomplete to add parentheses. This question was already asked using the Go programming language. I tried adding js.useCodeSnippetsOnFunctionSuggest
as well as javascript.useCodeSnippetsOnFunctionSuggest
. Neither of these work. I also tried useCodeSnippetsOnMethodSuggest
as suggested here, but that didn't work either. What am I doing wrong?
ANSWER
Answered 2020-Jul-22 at 17:57I fixed this by searching for "Complete Function Calls" in VS Code's settings, and checking JavaScript > Suggest: Complete Function Calls
. Thanks Mark for the suggestion.
QUESTION
I have a Visual Studio Code environment with the Linux Subsystem for windows running and it's compiling and running a Go project just fine.
Now I'm trying to get the delve debugger running following this link:
https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code
But I can't get it running, neither remote nor local.
Tried all kind of configurations in launch.json but breakpoints just arent hit and no error message is printed.
Has anyone got go debugging running on VSCode using the WSL?
...ANSWER
Answered 2019-Nov-08 at 07:12Old post, but its not possible to get delve to work on WSL
https://github.com/go-delve/delve/issues/1235
There was a better resource that explains fully why it doesnt work, cant find it now
Apparently it has something to do with WSL not implementing Linux fully...but it will in WSL2!
QUESTION
From here: https://github.com/Microsoft/vscode-go/wiki/GOPATH-in-the-VS-Code-Go-extension
At any point in time, you can run the command Go: Current GOPATH to see the GOPATH being used by the extension.
But... WHERE do I type that command?
Is there a specific command pane I need to open or something?
(I'm on the Mac client, if that's relevant.)
...ANSWER
Answered 2020-Apr-03 at 06:01Press Shift Command P, that is the command palette.
From there, type that command.
But, GOPATH is a lot less important with recent Go versions that support Go modules.
QUESTION
I create a sample project in Golang:
...ANSWER
Answered 2020-Mar-25 at 04:13I could reproduce your issue initially but after I upgrade to VSCode Version 1.35.1 (I am on MacOSX), the issue is gone. I can see the variable values during debug with "Launch exec"
I think the compiler optimisation made it problematic. Should works fine for executable built with
go build -gcflags=all="-N -l"
-N: disable optimization
-l: disable inlining
Golang officially suggested it as well: https://golang.org/doc/gdb
QUESTION
I am developing a Go (1.12.0) api-server using vscode (1.34.0 insider and stable builds) for Windows 10. The source code is located on the Windows machine in the defined %GOPATH%. Delve (dlv.exe - version 1.2.0) is also installed in %GOPATH%\bin and %GOPATH%\bin is also in the Windows %PATH%.
The go app is then built in a Docker (Docker Desktop Version 2.0.0.3 (31259)) container with docker-compose (as some other services such as Database and web-server are running in other containers). The final go app binary is then copied to an Alpine-Linux container together with the delve executable and the delve server is started in headless mode. No source code is copied over to the Alpine-Linux container, just the binaries.
I have not managed to get remote debugging set up properly in vscode with this set-up. The debugger does start my app but any breakpoints immediately turn grey and become "unverified". They are also not hit when the app (api server) runs.
Debugging with this set-up works perfectly (debugger starts, breakpoints can be set and are hit) when using the Goland IDE from Jetbrains for remote debugging.
I have tried to find a solution over the last couple of days, finding forum posts with similar problems for Chrome debugging, Node.js debugging etc. and this post on Go, specifically:
Remote debugging - Unverified breakpoint
I also found this sample config:
https://github.com/lukehoban/webapp-go/blob/debugging/.vscode/launch.json
I think the main problem I had is that nowhere could I find any examples of how to properly set the path of the program in launch.json for the remote debug config on a Windows machine (nor could I find any documentation referring to this). The source code is only on the Windows machine in GOPATH, not in the final container the app and delve run in (and this, again, works fine with Goland debugger)
My project path/directory structure (simplified):
...ANSWER
Answered 2019-May-09 at 11:09I have finally found a bug report on this, so it appears to be an open bug for now. Leaving this here for anybody searching as this bug was not easy to find (for me at least).
QUESTION
In order to discover Linux namespaces under certain conditions my open source Golang package lxkns needs to re-execute the application it is used in as a new child process in order to be able to switch mount namespaces before the Golang runtime spins up. The way Linux mount namespaces work makes it impossible to switch them from Golang applications after the runtime has spun up OS threads.
This means that the original process "P" re-runs a copy of itself as a child "C" (reexec package), passing a special indication via the child's environment which signals to the child to only run a specific "action" function belonging to the included "lxkns" package (see below for details), instead of running the whole application normally (avoiding endless recursively spawning children).
...ANSWER
Answered 2020-Mar-07 at 23:34After @Volker's comment on my Q I knew I had to take the challenge and went straight for the source code of Go's testing
package. While @marco.m's suggestion is helpful in many cases, it cannot handle my admittedly slightly bizare usecase. testing
's mechanics relevant to my original question are as follows, heavily simplified:
- cover.go: implements
coverReport()
which writes a coverage data file (in ASCII text format); if the file already exists (stale version from a previous run), then it will be truncated first. Please note thatcoverReport()
has the annoying habit of printing some “statistics” information to os.Stdout. - testing.go:
- gets the CLI arguments
-test.coverprofile=
and-test.outputdir=
fromos.Args
(via the flags package). If also implementstoOutputDir(path)
which places cover profile files inside-test.outputdir
if specified. - But when does
coverReport()
get called? Simply spoken, at the end oftesting.M.Run()
.
- gets the CLI arguments
Now with this knowledge under the belt, a crazy solutions starts to emerge, kind of "Go-ing Bad" ;)
- Wrap
testing.M
in a special re-execution enabled versionreexec.testing.M
: it detects whether it is running with coverage enabled:- if it is the "parent" process P, then it runs the tests as normal, and then it collects coverage profile data files from re-executed child processes C and merges them into P's coverage profile data file.
- while in P and when just about to re-execute a new child C, a new dedicated coverage profile data filename is allocated for the child C. C then gets the filename via its "personal"
-test.coverprofile=
CLI arg. - when in C, we run the desired action function. Next, we need to run an empty test set in order to trigger writing the coverage profile data for C. For this, the re-execution function in P adds a
test.run=
with a very special "Bielefeld test pattern" that will most likely result in an empty result. Remember, P will -- after it has run all its tests -- pick up the individual C coverage profile data files and merge them into P's.
- when coverage profiling isn't enabled, then no special actions need to be taken.
The downside of this solution is that it depends on some un-guaranteed behavior of Go's testing
with respect to how and when it writes code coverage reports. But since a Linux-kernel namespace discovery package already pushes Go probably even harder than Docker's libnetwork, that's just a quantum further over the edge.
To a test developer, the whole enchilada is hidden inside an "enhanced" rxtst.M
wrapper.
QUESTION
I've installed Microsoft VS Code in another partition (Drive D) on my Windows 10 system. I prefer to keep Microsoft VS Code in another partition away from Windows.
My goal is to install the GO extension from Microsoft. The link to the extension is here.
Click here to visit the source of the repository to the go extension.
The following error occurs when I attempt to install the GO extension through the Extension dialog in the Microsoft VS Code application.
The Error:
Failed to run "go env" to find GOPATH as the "go" binary cannot be found in either GOROOT(undefined) or PATH (
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\System32\OpenSSH\;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;
C:\Users\ My username left out \AppData\Local\Microsoft\WindowsApps;
)
I suspect that the cause is the fact that I installed Microsoft VS Code in another partition. I've also mentioned this at the beginning of my question. I've explained the steps that I took to find the solution below:
First I examined the location of the go resource. It seems that my resource is placed in the right folder (the folder of my installation.
D:\Program Files\Microsoft VS Code\resources\app\extensions\go
Than I tried a simple command through the commands by pressing ctrl+shift+p
and then typing go:Current GOPATH. the error message
command go.goroot not found
Then I thought of testing out if I can run a basic go file. I searched for a simple example and came across this site.. So, I've created a project folder and added the file Hello.go in the folder D:\VS_Projects\GO_Helloworld Then I placed the hello world program in it. The program is shown below
...ANSWER
Answered 2020-Jan-17 at 15:21The answer can be found on superuser. Also, I like to clearify why my post was originally closed according to the guidelines of stackoverflow. I Quote:
Questions about general computing hardware and software are off-topic for Stack Overflow unless they directly involve tools used primarily for programming.
I'm not sure to why the user who spotted the mistake removed his comment.
He said: What do you mean by 'Microsoft'?
It was helpful though. Anyway, I'll close this post now.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install vscode-go
Step 1. If you haven't done so already, install Go and the VS Code Go extension. Go installation guide. This extension works best with Go 1.14+. Managing extensions in VS Code.
Step 2. To activate the extension, open any directory or workspace containing Go code. Once activated, the Go status bar will appear in the bottom left corner of the window and show the recognized Go version.
Step 3. The extension depends on a set of extra command-line tools. If they are missing, the extension will show the "⚠️ Analysis Tools Missing" warning. Click the notification to complete the installation.
Go modules are how Go manages dependencies in recent versions of Go. Modules replace the GOPATH-based approach to specifying which source files are used in a given build, and they are the default build mode in go1.16+. While this extension continues to support both Go modules and GOPATH modes, we highly recommend Go development in module mode. If you are working on existing projects, please consider migrating to modules. Unlike the traditional GOPATH mode, module mode does not require the workspace to be located under GOPATH nor to use a specific structure. A module is defined by a directory tree of Go source files with a go.mod file in the tree's root directory. Your project may involve one or more modules. If you are working with multiple modules or uncommon project layouts, you will need to configure your workspace by using Workspace Folders. Please see this documentation about supported workspace layouts.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page