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

adjust imports on save #2800

Merged
merged 1 commit into from
Apr 8, 2020
Merged

adjust imports on save #2800

merged 1 commit into from
Apr 8, 2020

Conversation

bhcleek
Copy link
Collaborator

@bhcleek bhcleek commented Apr 1, 2020

Introduce a new option, g:go_imports_autosave, to allow imports to be
adjusted even when g:go_fmt_command is not set to goimports.

Closes #2795

@bhcleek bhcleek added the wip label Apr 1, 2020
@bhcleek bhcleek force-pushed the fmt/imports-on-save branch 2 times, most recently from 567e3df to f77d1aa Compare April 2, 2020 02:47
@bhcleek
Copy link
Collaborator Author

bhcleek commented Apr 2, 2020

@orlangure I think the recent changes on master have taken care of the issues that you saw on #2797. Feel free to give this a run through if you want.

@orlangure
Copy link
Contributor

Found two issues (and one probably related to gopls):

  1. When creating a new file and using both fmt and imports on save (enabled by default), the first save causes error since the file does not exist, and the next save works.
  2. When using the same options, every save leads to Press ENTER or type command to continue.

The last issue is inconsistency, I think it should be reported to gopls, but I'll post here anyway:

package main

import (
	"time"
	"github.com/orlangure/gnomock"
)

func meh() {
	_ = 0
	_ = gnomock.DefaultPort
	_ = time.Now()
}

Saving this file changes the order of imports to

import (
	"github.com/orlangure/gnomock"
	"time"
)

And saving this file changes it to

import (
	"time"

	"github.com/orlangure/gnomock"
)

@bhcleek
Copy link
Collaborator Author

bhcleek commented Apr 2, 2020

The first item, the error on the first save, is an issue on master that I'll address in a separate PR.

I can't duplicate the second item.

I can duplicate the third item; based on the debug output (let g:go_debug=["lsp"]), it looks like a gopls issue.

Introduce a new option, g:go_imports_autosave, to allow imports to be
adjusted even when g:go_fmt_command is not set to goimports.

Closes fatih#2795
@bhcleek bhcleek removed the wip label Apr 4, 2020
@bhcleek bhcleek added this to the vim-go 1.23 milestone Apr 5, 2020
@bhcleek bhcleek merged commit 785f585 into fatih:master Apr 8, 2020
@bhcleek bhcleek deleted the fmt/imports-on-save branch April 8, 2020 15:46
bhcleek added a commit that referenced this pull request Apr 8, 2020
jonaustin added a commit to jonaustin/dotfiles that referenced this pull request Mar 5, 2022
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

Successfully merging this pull request may close these issues.

Organizing imports on save with gopls
2 participants