Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoRun errors out with 'no packages loaded from /path/filename.go #3300

Closed
mfrw opened this issue Oct 5, 2021 · 5 comments
Closed

GoRun errors out with 'no packages loaded from /path/filename.go #3300

mfrw opened this issue Oct 5, 2021 · 5 comments

Comments

@mfrw
Copy link

mfrw commented Oct 5, 2021

What did you do? (required: The issue will be closed when not provided)

I ran :GoRun in a test hello world with main.

package main

import "fmt"

func main() {
        fmt.Println("vim-go")
}

I tried to run :GoRun on this program.

What did you expect to happen?

Print vim-go

What happened instead?

:!'go' 'run' '/home/mfrw/mariner-org/dashboard/cmd/test/main.go\\n'  2>&1| tee /tmp/nvim7Egq2g/6                                                                                                                                                                     
go run: no packages loaded from /home/mfrw/mariner-org/dashboard/cmd/test/main.go\n

Configuration (MUST fill this out):

vim-go version:

vimrc you used to reproduce:

vimrc
call plug#begin('~/.vim/bundle')
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()

au FileType go nmap <leader>r <Plug>(go-run)

Vim version (first three lines from :version):

NVIM v0.6.0-dev

Go version (go version):

go version go1.17.1 linux/amd64

Go environment

go env Output:
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mfrw/.cache/go-build"
GOENV="/home/mfrw/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mfrw/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mfrw/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.17"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.17/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mfrw/mariner-org/dashboard/go.mod"
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-build470378468=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.7.2
    golang.org/x/tools/gopls@v0.7.2 h1:kRKKdvA8GOzra8rhSFDClOR7hV/x8v0J0Vm4C/gWq8s=

Although with the same .vimrc i am able to run this everywhere else.
If anyone could please point me towards any steps to debug this. I am not really sure what happend.

The only change I did it is upgrade go from 1.15 to 1.17.1 and it stopped working.

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 5, 2021

Why is there a literal \n at the end of main.go's filename?

@mfrw
Copy link
Author

mfrw commented Oct 5, 2021

Why is there a literal \n at the end of main.go's filename?

:( I am not sure :(.
Let me try to find any specific reason for this :(
I am trying to find what in my config is causing this .. but Yes :(

Edit:

I changed my mapping to below and now it works as it does not add an additional new line.

au FileType go nmap <leader>r :GoRun % <CR>

What i am now wondering is

What went wrong with

au FileType go nmap <leader>r <Plug>(go-run)

I am not too well versed with vimscript.
The issue is mitigated. Should I close the issue or we dig more to find what caused this ?

[In anycase, thank you very much for the pointer, at least I am able to proceed. Appreciate the help]

@bhcleek
Copy link
Collaborator

bhcleek commented Oct 5, 2021

au FileType go nmap <leader>r <Plug>(go-run) in my vimrc works fine for me: when I \r in main.go, it runs fine.

@mfrw
Copy link
Author

mfrw commented Oct 5, 2021

au FileType go nmap <leader>r <Plug>(go-run) in my vimrc works fine for me: when I \r in main.go, it runs fine.

I am facing this issue only in one of my boxes. All other boxes that I have are running fine.
I am not sure what changed apart from me updating go-1.15 -> go-1.17. I touched nothing :(
Let me dig more though.
And probably this is just maybe something wrong with my env.

@sbatial
Copy link

sbatial commented Feb 16, 2022

I recently ran into the same error and I'm pretty sure I tracked it down!

Explanation:

The literal newline character appears to stem from the go#tool#Files() function.
Invoking :echo go#tool#Files() gives me ['<path-to-project>/main.go\n'].

So when one of the mappings

nnoremap <silent> <Plug>(go-run-vertical) :<C-u>call go#cmd#RunTerm(!g:go_jump_to_error, 'vsplit', [])<CR>
nnoremap <silent> <Plug>(go-run-split) :<C-u>call go#cmd#RunTerm(!g:go_jump_to_error, 'split', [])<CR>
nnoremap <silent> <Plug>(go-run-tab) :<C-u>call go#cmd#RunTerm(!g:go_jump_to_error, 'tabe', [])<CR>

calls go#cmd#RunTerm(!g:go_jump_to_error, 'split', []) which then invokes

vim-go/autoload/go/cmd.vim

Lines 123 to 125 in 00c5f2d

if empty(a:files)
call extend(cmd, go#tool#Files())
else

Probable reason

While poking around in the go#tool#Files() function I saw that go#tool#Deps() handled the format string for go list a bit different than Files() and Imports().
I tested the Imports() function and it failed as well!

So I suspect that using {{printf \"\n\"}} only works on Windows whereas \n should be used on Linux/MacOS.

Possible fix

So to fix it I just changed the go#tool#Files() and the go#tool#Imports() function to use \n instead of {{printf \"\n\"}}.

That brought the 'run' commands as well as the 'Imports' command back to life again on my side (linux, nvim).

I opened a pull-request which should fix this: #3358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants