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

Auto go fmt on save #5

Closed
fatih opened this issue Mar 24, 2014 · 11 comments
Closed

Auto go fmt on save #5

fatih opened this issue Mar 24, 2014 · 11 comments

Comments

@fatih
Copy link
Owner

fatih commented Mar 24, 2014

No description provided.

@fatih fatih closed this as completed in 4135bdb Mar 25, 2014
@Netherdrake
Copy link

Hi,

It is possible to pass options to the formatter like so:
gofmt -tabs=false -tabwidth=4 main.go

Via the go-vim setting:
let g:go_fmt_command = "gofmt -tabs=false -tabwidth=4"

However now I'm wondering how would it be possible to pass these settings when using goimports?

I'm trying to get my code formatted with spaces instead of tabs, 4 spaces in width.

@fatih
Copy link
Owner Author

fatih commented Mar 31, 2014

Well just pass it to goimports binary path!

let g:go_goimports_bin = "goimports -tabs=false -tabwidth=4"

can you try it?

@Netherdrake
Copy link

I have 2 issues with that approach.
1.) It doesn't work. I get this on save.
2.) It prompts me with goimports installation on every vim start, even though its already installed.

% vim main.go 
Installing code.google.com/p/go.tools/cmd/goimports
Press ENTER or type command to continue

@fatih
Copy link
Owner Author

fatih commented Apr 1, 2014

My suggestion was based on that you had a goimports installed somewhere else. We need to seperate binary path and the options. I've opened a new issue where we are gonna introduce a new parameter. Let us talk from there now. Thanks for reporting.

@Netherdrake
Copy link

I see the commit 13a71b0 adds new option, but I'm wondering how can that option be used to achieve go-vim usage of goimports combined with custom formatting settings (-tabs=false -tabwidth=4)?

@fatih
Copy link
Owner Author

fatih commented Apr 9, 2014

That's up to the go fmt command, if you use gofmt just specifiy in your vimrc:

let g:go_fmt_options = "-tabs=false -tabwidth=4"

@Netherdrake
Copy link

@fatih Well, naturally that's the first thing I tried before posting here, and it didn't work for me.
Is there any additional setting that I'm missing?

I went ahead, and deleted every occurrence of goimports from my system, and had the go-vim plugin re-install it.
sudo find / -name 'goimports'

The behavior is pretty much the same as with the one described 9 days ago. When I hit :w, I get some echo of code on bottom, while in buffer the code is nor formatted, nor do imports run. link

Here is my current vimrc

@fatih
Copy link
Owner Author

fatih commented Apr 9, 2014

goimports doesn't have those options. Only gofmt has it. You need to change it to g:go_fmt_command = 'gofmt'.

@Netherdrake
Copy link

Well than, that means if I want to do goimports there is no way for me to format my code with proper spacing (other than running :%retab on BufWritePost)?

@fatih
Copy link
Owner Author

fatih commented Apr 9, 2014

Yes, unfortunately this is a limitation of goimports rather than vim-go. You can just type goimports in the shell and see what it supports.

@Netherdrake
Copy link

I was aware of this limitation, I thought that you would do some magic with new update (eg. run goimports first, and than gofmt over it).

The goimports tool is really stupid in this sense, they should merge it with gofmt and provide it as a flag.

mingtaoy added a commit to mingtaoy/vim-go that referenced this issue Dec 26, 2018
vim's rename() function will output messages for non-fatal conditions,
such as setting SELinux context. This will cause vim-go to annoyingly
display a "Press ENTER to continue" message in conjunction with
go_fmt_autosave = 1.

For example, if the original Go source file is located on a FUSE
filesystem that does not support `setxattr()`, and vim is compiled with
SELINUX_ENABLED, `rename()` will attempt to call `setfilecon()`, which
will fail and output an annoying error message.

Call stack:

```
 #0  mch_copy_sec (from_file=0xc2e3d0 "/tmp/vRUr7yU/7.go", to_file=0xc59910 "/fuse/test.go") at os_unix.c:2866
 fatih#1  0x00000000004e7dcf in vim_rename (from=0xc2e3d0 "/tmp/vRUr7yU/7.go", to=0xc59910 "/fuse/test.go") at fileio.c:6731
 fatih#2  0x0000000000480ab7 in f_rename (argvars=0x7ffec6fddac0, rettv=0x7ffec6fddd08) at evalfunc.c:9646
 fatih#3  0x0000000000474011 in call_internal_func (name=0xc51b00 "rename", argcount=2, argvars=0x7ffec6fddac0, rettv=0x7ffec6fddd08) at evalfunc.c:1110
 fatih#4  0x0000000000660d8e in call_func (funcname=0xc62d20 "rename", len=6, rettv=0x7ffec6fddd08, argcount_in=2, argvars_in=0x7ffec6fddac0, argv_func=0x0, firstline=12, lastline=12, doesrange=0x7ffec6fddcfc,
     evaluate=1, partial=0x0, selfdict_in=0x0) at userfunc.c:1507
 fatih#5  0x0000000000660690 in get_func_tv (name=0xc62d20 "rename", len=6, rettv=0x7ffec6fddd08, arg=0x7ffec6fddd38, firstline=12, lastline=12, doesrange=0x7ffec6fddcfc, evaluate=1, partial=0x0, selfdict=0x0)
     at userfunc.c:455
 fatih#6  0x0000000000666961 in ex_call (eap=0x7ffec6fddf38) at userfunc.c:3171
 fatih#7  0x00000000004af3c2 in do_one_cmd (cmdlinep=0x7ffec6fde6c8, sourcing=1, cstack=0x7ffec6fde210, fgetline=0x666be0 <get_func_line>, cookie=0xc48fd0) at ex_docmd.c:2537
 fatih#8  0x00000000004ac3d8 in do_cmdline (cmdline=0x0, fgetline=0x666be0 <get_func_line>, cookie=0xc48fd0, flags=7) at ex_docmd.c:1038
 fatih#9  0x0000000000662123 in call_user_func (fp=0xbfe220, argcount=2, argvars=0x7ffec6fdf0e0, rettv=0x7ffec6fdf328, firstline=12, lastline=12, selfdict=0x0) at userfunc.c:954
 fatih#10 0x0000000000660d01 in call_func (funcname=0xc59fb0 "go#fmt#update_file", len=18, rettv=0x7ffec6fdf328, argcount_in=2, argvars_in=0x7ffec6fdf0e0, argv_func=0x0, firstline=12, lastline=12,
     doesrange=0x7ffec6fdf31c, evaluate=1, partial=0x0, selfdict_in=0x0) at userfunc.c:1488
 fatih#11 0x0000000000660690 in get_func_tv (name=0xc59fb0 "go#fmt#update_file", len=18, rettv=0x7ffec6fdf328, arg=0x7ffec6fdf358, firstline=12, lastline=12, doesrange=0x7ffec6fdf31c, evaluate=1, partial=0x0,
     selfdict=0x0) at userfunc.c:455
 fatih#12 0x0000000000666961 in ex_call (eap=0x7ffec6fdf558) at userfunc.c:3171
 fatih#13 0x00000000004af3c2 in do_one_cmd (cmdlinep=0x7ffec6fdfce8, sourcing=1, cstack=0x7ffec6fdf830, fgetline=0x666be0 <get_func_line>, cookie=0xc61900) at ex_docmd.c:2537
 fatih#14 0x00000000004ac3d8 in do_cmdline (cmdline=0x0, fgetline=0x666be0 <get_func_line>, cookie=0xc61900, flags=7) at ex_docmd.c:1038
 fatih#15 0x0000000000662123 in call_user_func (fp=0xc59340, argcount=1, argvars=0x7ffec6fe0700, rettv=0x7ffec6fe0948, firstline=12, lastline=12, selfdict=0x0) at userfunc.c:954
 fatih#16 0x0000000000660d01 in call_func (funcname=0xc64a40 "go#fmt#Format", len=13, rettv=0x7ffec6fe0948, argcount_in=1, argvars_in=0x7ffec6fe0700, argv_func=0x0, firstline=12, lastline=12, doesrange=0x7ffec6fe093c,
     evaluate=1, partial=0x0, selfdict_in=0x0) at userfunc.c:1488
 fatih#17 0x0000000000660690 in get_func_tv (name=0xc64a40 "go#fmt#Format", len=13, rettv=0x7ffec6fe0948, arg=0x7ffec6fe0978, firstline=12, lastline=12, doesrange=0x7ffec6fe093c, evaluate=1, partial=0x0, selfdict=0x0)
     at userfunc.c:455
 fatih#18 0x0000000000666961 in ex_call (eap=0x7ffec6fe0b78) at userfunc.c:3171
 fatih#19 0x00000000004af3c2 in do_one_cmd (cmdlinep=0x7ffec6fe1308, sourcing=1, cstack=0x7ffec6fe0e50, fgetline=0x4cc2a0 <getexline>, cookie=0x0) at ex_docmd.c:2537
 fatih#20 0x00000000004ac3d8 in do_cmdline (cmdline=0xc65380 "call go#fmt#Format(-1)", fgetline=0x4cc2a0 <getexline>, cookie=0x0, flags=11) at ex_docmd.c:1038
 fatih#21 0x00000000004ba24b in do_ucmd (eap=0x7ffec6fe15d8) at ex_docmd.c:7018
 fatih#22 0x00000000004af390 in do_one_cmd (cmdlinep=0x7ffec6fe1d68, sourcing=0, cstack=0x7ffec6fe18b0, fgetline=0x4cc2a0 <getexline>, cookie=0x0) at ex_docmd.c:2528
 fatih#23 0x00000000004ac3d8 in do_cmdline (cmdline=0x0, fgetline=0x4cc2a0 <getexline>, cookie=0x0, flags=0) at ex_docmd.c:1038
 fatih#24 0x0000000000558c59 in nv_colon (cap=0x7ffec6fe1eb8) at normal.c:5388
 fatih#25 0x000000000054ec81 in normal_cmd (oap=0x7ffec6fe1f58, toplevel=1) at normal.c:1121
 fatih#26 0x00000000006bf4b9 in main_loop (cmdwin=0, noexmode=0) at main.c:1374
 fatih#27 0x00000000006bdf2b in vim_main2 () at main.c:920
 fatih#28 0x00000000006bb637 in main (argc=2, argv=0x7ffec6fe2168) at main.c:444
```

Fixes fatih#1081
jrahme-cci added a commit to jrahme-cci/vim-go that referenced this issue Dec 10, 2022
# This is the 1st commit message:

Add in functionality to test single case in table

# This is the commit message fatih#2:

internm commit for implementing name discovery

# This is the commit message fatih#3:

Add ability to run single test case

# This is the commit message fatih#4:

move subtest name detection to a helper function

# This is the commit message fatih#5:

use line instead of detecting case
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

2 participants