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

Cannot navigate to next error #247

Closed
pengux opened this issue Nov 27, 2014 · 22 comments
Closed

Cannot navigate to next error #247

pengux opened this issue Nov 27, 2014 · 22 comments
Labels

Comments

@pengux
Copy link

pengux commented Nov 27, 2014

Errors in Go files seems to be different and cannot be navigated to by using :cn or :lne. Is there any other way to cycle through all errors in a buffer?

@fatih
Copy link
Owner

fatih commented Nov 27, 2014

Are you sure it's not working? Which command are you using? I'll use it all the time without any single problem. This is what I have in my .vimrc

map <C-n> :cn<CR>
map <C-m> :cp<CR>

So you can use :cn and :cp. vim-go uses the quickfix window and any quickfix related mappings should work.

@fatih fatih added the bug label Nov 27, 2014
@pengux
Copy link
Author

pengux commented Nov 27, 2014

Yes, I run the command :cn<CR> and it only prints "E42: No Errors" even though there is a type error in the buffer. If I move the cursor to that line then the error message appear in vim status bar

@fatih
Copy link
Owner

fatih commented Nov 27, 2014

Could you please paste the executed command and an example code? I would like to debug it in more detail.

@pengux
Copy link
Author

pengux commented Nov 27, 2014

Here is a sample code that I just open up in a new buffer:

package main

func main() {
    var foo Bar
}

the line var foo Bar generates the error, but executing :cn<CR> prints E42: No Errors. Moving the cursor to that line prints undefined: Bar

@fatih
Copy link
Owner

fatih commented Nov 27, 2014

@pengux what command are you executing ? (this is the third time I'm asking you :)) It works perfectlly for me. If there is only one single error, you need to call :cc, not :cn

@pengux
Copy link
Author

pengux commented Nov 27, 2014

@fatih Sorry, I thought you meant the :cn commands. I just save the buffer and in my vim settings, it should run the goimports command

@pengux
Copy link
Author

pengux commented Nov 27, 2014

:cc didn't work either btw. I first thought that some other plugins were eating the key mappings. But as I'm executing the command in the vim command line, it should not be interfered by other plugins, correct?

@fatih
Copy link
Owner

fatih commented Nov 27, 2014

Ok just to be sure we are on the same page:

  1. You just saving the file to autoformat it
  2. You use goimports as the fmt command ?
  3. There is error (produced by goimports) and you can't jump to it.

If that's the case then we need to look at fmt.vim. Btw can you execute :GoBuild and check if :cn works ?

@pengux
Copy link
Author

pengux commented Nov 27, 2014

@fatih That's correct. Using :GoBuild works as the quickfix window open up and the cursor is moved to the error automatically. Using :cn in the sample code does not work as you pointed out as there's only one error, but :cc works.

@fatih
Copy link
Owner

fatih commented Nov 27, 2014

Alright, now at least I know where to look now :) Thanks for the report. Probably the quickfix window is not being correctly produced via fmt.vim, or goimports has a different output than gofmt. Anyway I need more time to look it up. In meanwhile you can disable showing errors when you save your file by adding the line:

let g:go_fmt_fail_silently = 1

to your .vimrc.

@pengux
Copy link
Author

pengux commented Nov 27, 2014

Great!

No, I rather see the errors and moving to it manually though :-)

@pengux
Copy link
Author

pengux commented Nov 27, 2014

I was curious and tried to debug the problem in fmt.go, and I don't think it is because of GoImports/GoFmt. Because if I change the error to be something like an syntax error, such as:

package main

import "fmt"

func main() {
        var Foo Bar

By leaving out the closing bracket, GoImports reports the error correctly, the quickfix window is opened and I can navigate to the error.

So it must be some kind of compiler checking that don't populate the quickfix window correctly. What is run on save automatically with vim-go?

@pengux
Copy link
Author

pengux commented Nov 27, 2014

Found the cause and it's because of Syntastic syntax checking, so closing this...

@pengux pengux closed this as completed Nov 27, 2014
@elithrar
Copy link

@pengux What was the actual issue with syntastic? How did you correct it?

@pengux
Copy link
Author

pengux commented Apr 23, 2015

@elithrar I don't remember exactly, but I have these two lines in my .vimrc so maybe you can try it

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1

@vorstack-jeff
Copy link

Something else is going on... I don't have syntastic and have this same issue. Open to trying things to debug it.

@hongzhouchen-oceanwing
Copy link

@pengux Thanks for your comment. It solved my problem.

@blacksails
Copy link

blacksails commented Jul 25, 2016

@vorstack-jeff did you get it working? I dont have syntastic and i have the issue aswell.

UPDATE. I am not that used to using the lists in vim. It turns out that there are two types of lists location lists and quickfix lists. cnext will not find the next error if your use a location list. Instead you will need to run lnext.

@modood
Copy link

modood commented Feb 5, 2018

my .vimrc:

It works, so maybe you can try it:

let g:go_metalinter_autosave = 1
let g:go_list_type = 'locationlist'

" turn to next or previous errors, after open location list
nmap <leader>j :lnext<CR>
nmap <leader>k :lprevious<CR>

I hope that helps 😄

@andradei
Copy link

andradei commented Aug 8, 2018

@modood Worked for me. Thank you.

@bxsx
Copy link

bxsx commented Aug 15, 2023

Hi @fatih

Let me know if I should open a new issue for this but..

I have exactly the same problem. :cc, :cn, :lnext etc. says No errors. However it's working fine when first calling :GoBuild, but since the lines were highlighted on the fly (without former building or saving file), it would be nice to jump to the next error.. How can I do that?

PS. I don't use GoMetaLinter or Syntastic, my VIm configuration for Go is very simple:

let g:go_def_mode='gopls'
let g:go_info_mode='gopls'

@bxsx
Copy link

bxsx commented Aug 16, 2023

PS. I don't use GoMetaLinter or Syntastic, my VIm configuration for Go is very simple:

Turned out that these errors have been identified by YouCompleteMe. Fixed now :)

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

No branches or pull requests

9 participants