<p>I would like to check my go files for syntax errors. Usually it's about incorrect pointer usage or wrong type. Please see example here: <a href="https://play.golang.org/p/14jE31C1383" rel="nofollow">https://play.golang.org/p/14jE31C1383</a></p>
<p>I'm using vim, vim-go and ALE plugin for running linters.</p>
<p>In the IntelliJ IDEA with Golang plugin, the IDE instantly shows all syntax errors without necessity to compile program. Can I achieve the same in vim?</p>
<p>Thank you.</p>
<hr/>**评论:**<br/><br/>gbrlsnchs: <pre><p>I use the same plugins you do and could not yet achieve what you want. For the checking you desire, I have to save the file first for the linter to run.</p></pre>_grundic_: <pre><p>I've found this <a href="https://stackoverflow.com/questions/37769882/vim-go-synstastic-errors-not-automatically-displaying-on-save" rel="nofollow">question</a> on SO, which is for vim-go + syntastic. So, running :GoErrCheck will show errors in quickfix window, but without gutter signs :-/</p>
<p>But for me it doesn't work even after saving the file.</p></pre>jarmojobbo: <pre><p>I get the gutter signs with vimgo and syntactic (plus the quickfix stuff). I'm on the toilet on mobile right now, but I'll pm you my vimrc two hours from now. (If I forget, feel free to bug me and I'll get it to you)</p></pre>tv64738: <pre><blockquote>
<p>I'm on the toilet on mobile right now, but I'll [...] two hours from now.</p>
</blockquote>
<p>You may have overdone the whole Christmas eating thing a bit.</p></pre>jarmojobbo: <pre><blockquote>
<p>It's not about what you eat between Christmas and New Years, but what you eat between New Years and Christmas. </p>
</blockquote>
<p>That's what "all" just taught me, I'm still in the acceptable threshold!</p></pre>_grundic_: <pre><p>I didn't want to interrupt you sorry ^_^</p>
<p>So I managed it to work after adding </p>
<pre><code>let g:ale_linters = {
\ 'go': ['gometalinter', 'gofmt'],
\}
</code></pre>
<p>The problem was that it was defined in other vim file and being overwritten.
Thank you for your willing to help, appreciate that!</p></pre>new_frame: <pre><p>Run gotype on the file. I'm using Emacs, don't know how to do this with vim, but I know that's possible.</p>
<pre><code>gotype a_tmp_01.go
tmp_01.go:11:7: cannot use s (variable of type string) as *string value in argument to echo
tmp_01.go:15:7: cannot use &i (value of type *int) as *string value in argument to echo
</code></pre></pre>Jelterminator: <pre><p>I've been working on a PR to ale that does what you ask: <a href="https://github.com/w0rp/ale/pull/1099" rel="nofollow">https://github.com/w0rp/ale/pull/1099</a></p>
<p>It works pretty decently, but test files are not supported yet</p></pre>_grundic_: <pre><p>Looks good, but unfortunately my setup is non-standard and gotype not always works for me. I've managed to configure my workflow with <code>gometalinter</code>.
Thank you.</p></pre>Jelterminator: <pre><p>If you don't mind saving the file it is indeed fine to use gometalinter. The main reason I tried this to work is to get type checking to work while I type. </p></pre>arp242: <pre><p>gometalinter supports <code>gotype</code>; not sure why an extra linter is needed?</p></pre>Jelterminator: <pre><p>See my other comment, ALE only does gometalinter on save, not while typing. </p></pre>arp242: <pre><p>Isn't that something that can be fixed? I normally disable the check-while-typing stuff (as I find it annoying as hell) so I hadn't noticed that.</p></pre>Jelterminator: <pre><p>It could probably be fixed for <code>gometalinter</code> as well in a similar way I'm doing it for <code>gotype</code>. But wanted to try it out with <code>gotype</code> first to keep it easy.</p></pre>_grundic_: <pre><p>I believe you're wrong: ALE by default runs all linters after small delay , but this behavior can be changed. Please see <a href="https://github.com/w0rp/ale/blob/e43e7065da17f45e4cce127a319ceee0a0311883/plugin/ale.vim#L87-L90" rel="nofollow">comment</a> in the code. Probably I'm wrong, feel free to correct me :)</p>
<p>In this <a href="https://dmerej.info/blog/post/lets-have-a-pint-of-vim-ale/" rel="nofollow">article</a> the guy describes his ALE setup for python and he changes settings to be executed only on save:</p>
<pre><code>let g:ale_lint_on_text_changed = 'never'
</code></pre></pre>Jelterminator: <pre><p>You're half right. Most ALE linters work like that indeed. However if you look at the list of supported linters you can see that the ones with <code>!!</code> behind them only work on save: <a href="https://github.com/w0rp/ale#1-supported-languages-and-tools" rel="nofollow">https://github.com/w0rp/ale#1-supported-languages-and-tools</a>
<code>gometalinter</code> is one of those (as well as most other go linters).</p></pre>_grundic_: <pre><blockquote>
<p>re half right. Most ALE linters work like that indeed. However if you look at the list of supported linters you can see </p>
</blockquote>
<p>Ah, you're right. I was confused that it works after the file is opened. But when it changed it's not updated, only after saving. Thank you :)</p></pre>0xjnml: <pre><blockquote>
<p>I would like to check my go files for syntax errors.</p>
</blockquote>
<p>Try the Go compiler, it's really good at spotting syntax errors.</p>
<blockquote>
<p>Usually it's about incorrect pointer usage or wrong type.</p>
</blockquote>
<p>That cannot be usually done just over an isolated file as those are not syntax errors. The type checker needs to access a complete package(s) for that. Once again, the Go compiler is quite probably the most complete and best performing type checking tool available.</p>
<p>PS: I have mapped <enter> in normal mode to do exactly this - use the compiler to check the package I'm editing. So my "hotkey" for the check is <esc><enter>.</p></pre>_grundic_: <pre><p>Interesting, probably I'll give it a try. Thank you!</p></pre>kidovate: <pre><p>If you like Vim I would recommend trying <a href="http://spacemacs.org" rel="nofollow">Spacemacs</a> as a "full IDE" because the emacs Go plugins (flycheck, company) are capable of doing what you say out of the box. </p>
<p>Edit: what none of you realize is the variant I am recommending is designed to support Vim users with the Vim style. I used vim alone for years, and still do when necessary. But I've moved completely to using Spacemacs for my daily work. It supports the same workflow as vim with a lot more functionality. </p>
<p>Grow up a bit guys. </p></pre>kd7nyq: <pre><p>If you like Christianity, I would recommend trying Islam... </p></pre>joncrlsn: <pre><p>Tough crowd you have here, @kidovate. :-) I know you were thinking of the lightweight command-line nature of the two tools even if they have fanatical adherents.</p></pre>EmmEff: <pre><p>OP likes vim so you recommend an Emacs variant... got it.</p></pre>kidovate: <pre><p>This is a Go sub not a Vim sub and the variant I recommended is explicitly designed to support people who like vim. </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传