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

goimports-reviser not importing and undoing on save #112

Closed
kcaashish opened this issue Mar 23, 2023 · 6 comments
Closed

goimports-reviser not importing and undoing on save #112

kcaashish opened this issue Mar 23, 2023 · 6 comments

Comments

@kcaashish
Copy link

My config for goimports-reviser is:

return {
  {
    "jose-elias-alvarez/null-ls.nvim",
    opts = function(_, opts)
      local nls = require("null-ls")
      local nls_sources = {
        -- go
        nls.builtins.formatting.goimports_reviser.with({
          generator_opts = {
            command = "goimports-reviser",
            args = { "-output", "stdout", "$FILENAME" },
            to_stdin = true,
          },
        }),
      }
      vim.list_extend(opts.sources, nls_sources, 1, #nls_sources)
    end,
  },
}

In a very simple go project with go.mod:

module minimal

go 1.19

main.go:

package main

func main() {
	fmt.Println("Hello, World!")
}

Notice the absence of imports statment as well. So there should be a undeclared name: fmt error. If I format the code, the imports are not auto imported.

If I delete the line fmt.Println() dd then hit :w, the line pops back up.

@kcaashish
Copy link
Author

Screencast.from.2023-03-24.14-10-39.webm

@nanomoeamezao
Copy link

You should try reaching out to null-ls devs about this, as it likely needs some edits in the builtin itself (related to reading the old saved file, but not the new unsaved version).

@incu6us
Copy link
Owner

incu6us commented Apr 6, 2023

hi @kcaashish
I'm not familiar with null-ls, but I guess the problem is in your configuration to the plugin. Try to find out correct example for null-ls which will cover your case

@incu6us incu6us closed this as completed Apr 6, 2023
@kcaashish
Copy link
Author

Hey @incu6us, we did solve it by writing into a temp file. I think the issue here is taking input from stdin. Possibly this #94! We had a discussion over at null-ls and chose to use temp file for now until this gets fixed in goimports-reviser. The discussion: jose-elias-alvarez/null-ls.nvim#1472 (reply in thread) Anything on this?

@kcaashish
Copy link
Author

So instead of :

args = { "-output", "stdout", "$FILENAME" },
to_stdin = true,

we are using:

args = {"$FILENAME"},
to_temp_file = true,

Anyway to fix this?

@incu6us incu6us reopened this Apr 7, 2023
@incu6us
Copy link
Owner

incu6us commented Oct 16, 2023

fixed stdin feature in v3.5.6

@incu6us incu6us closed this as completed Oct 16, 2023
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