Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

goimports-reviser with -rm-unused removes the module that not in go.mod #1617

Open
5 tasks done
Pagliacii opened this issue Jul 6, 2023 · 0 comments
Open
5 tasks done
Labels
bug Something isn't working

Comments

@Pagliacii
Copy link

Pagliacii commented Jul 6, 2023

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Issues

  • I have checked existing issues and there are no issues with the same problem.

Neovim Version

NVIM v0.9.1 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3

Dev Version?

  • I am using a stable Neovim release version, or if I am using a dev version of Neovim I have confirmed that my issue is reproducible on a stable version.

Operating System

Windows 11 10.0.25393

Minimal Config

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
    local path_sep = on_windows and "\\" or "/"
    local result = table.concat({ ... }, path_sep)
    return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local null_ls_config = function()
    local null_ls = require("null-ls")
    -- add only what you need to reproduce your issue
    null_ls.setup({
        sources = {
            require("null-ls").builtins.formatting.goimports_reviser.with({
              args = { "-rm-unused", "$FILENAME" }, -- this
            }),
        },
        debug = true,
    })
end

local function load_plugins()
    -- only add other plugins if they are necessary to reproduce the issue
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            {
                "jose-elias-alvarez/null-ls.nvim",
                requires = { "nvim-lua/plenary.nvim" },
                config = null_ls_config,
            },
        },
        config = {
            package_root = package_root,
            compile_path = compile_path,
        },
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
    load_plugins()
    require("packer").sync()
else
    load_plugins()
    require("packer").sync()
end

Steps to Reproduce

Test go file:

// main.go
package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello")
}
  1. nvim --clean -u minimal_init.lua main.go
  2. add this line glog.Info("World") into main function
  3. add the module import statement "github.com/golang/glog" after "fmt"
  4. execute lua vim.lsp.buf.format(), the "github.com/golang/glog" disappeared.

Reproducibility Check

  • I confirm that my minimal config is based on the minimal_init.lua template and that my issue is reproducible by running nvim --clean -u minimal_init.lua and following the steps above.

Expected Behavior

Keep the import statement at its place.

Actual Behavior

The import statement disappeared

Debug Log

[TRACE 2023/7/6 23:47:55] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didSave
[TRACE 2023/7/6 23:47:55] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_SAVE
[DEBUG 2023/7/6 23:47:55] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:47:55] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:106: received LSP request for method shutdown
[TRACE 2023/7/6 23:47:55] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method exit
[TRACE 2023/7/6 23:47:57] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/client.lua:97: starting null-ls client
[TRACE 2023/7/6 23:47:57] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:106: received LSP request for method initialize
[DEBUG 2023/7/6 23:47:57] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/client.lua:152: unable to notify client for method textDocument/didOpen (client not active): {
textDocument = {
uri = "file:///R:/code/go/hello-world/main.go"
}
}
[TRACE 2023/7/6 23:47:57] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method initialized
[TRACE 2023/7/6 23:47:57] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didOpen
[TRACE 2023/7/6 23:47:57] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_OPEN
[DEBUG 2023/7/6 23:47:57] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:11] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didChange
[TRACE 2023/7/6 23:48:11] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS
[DEBUG 2023/7/6 23:48:11] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:12] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didSave
[TRACE 2023/7/6 23:48:12] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_SAVE
[DEBUG 2023/7/6 23:48:12] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:16] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didChange
[TRACE 2023/7/6 23:48:16] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS
[DEBUG 2023/7/6 23:48:16] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:17] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didChange
[TRACE 2023/7/6 23:48:17] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS
[DEBUG 2023/7/6 23:48:17] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:19] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didSave
[TRACE 2023/7/6 23:48:19] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_SAVE
[DEBUG 2023/7/6 23:48:19] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:19] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:106: received LSP request for method shutdown
[TRACE 2023/7/6 23:48:19] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method exit
[TRACE 2023/7/6 23:48:20] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/client.lua:97: starting null-ls client
[TRACE 2023/7/6 23:48:20] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:106: received LSP request for method initialize
[DEBUG 2023/7/6 23:48:20] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/client.lua:152: unable to notify client for method textDocument/didOpen (client not active): {
textDocument = {
uri = "file:///R:/code/go/hello-world/main.go"
}
}
[TRACE 2023/7/6 23:48:20] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method initialized
[TRACE 2023/7/6 23:48:20] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didOpen
[TRACE 2023/7/6 23:48:20] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_OPEN
[DEBUG 2023/7/6 23:48:20] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:35] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didChange
[TRACE 2023/7/6 23:48:35] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS
[DEBUG 2023/7/6 23:48:35] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:43] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:106: received LSP request for method textDocument/formatting
[TRACE 2023/7/6 23:48:43] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_FORMATTING
[DEBUG 2023/7/6 23:48:43] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:321: spawning command "goimports-reviser" at R:\code\go\hello-world with args { "-rm-unused", "R:\code\go\hello-world\.null-ls_814785_main.go" }
[TRACE 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:205: error output: nil
[TRACE 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:206: output: nil
[DEBUG 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/formatting.lua:89: received edits from generators
[TRACE 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/formatting.lua:90: {
newText = ')\r\n\r\nfunc main() {\r\n\ts := ""\r\n\tfmt.Println(s)\r\n\tfmt.Printf("test: %s", "hello")\r\n\tglog.Info("Hello")\r\n}\r\n',
range = {
["end"] = {
character = 0,
line = 14
},
start = {
character = 0,
line = 4
}
},
rangeLength = 124
}
[TRACE 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didChange
[TRACE 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS
[DEBUG 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didChange
[TRACE 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS
[DEBUG 2023/7/6 23:48:44] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE 2023/7/6 23:48:47] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/rpc.lua:131: received LSP notification for method textDocument/didSave
[TRACE 2023/7/6 23:48:47] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_SAVE
[DEBUG 2023/7/6 23:48:47] C:\Users\Jason\AppData\Local\Temp\nvim\site\pack\packer\start\null-ls.nvim/lua/null-ls/generators.lua:24: no generators available

Help

Yes, but I don't know how to start. I would need guidance

Implementation Help

Execute the command in terminal will report a failure message, but doesn't touch the file.

Failure message:

λ goimports-reviser -rm-unused main.go
main.go:6:2: no required module provides package github.com/golang/glog; to add it:
        go get github.com/golang/glog
2023/07/06 23:53:17 Failed to fix file: package has an errors

File contents:

// main.go
package main

import (
	"fmt"

	"github.com/golang/glog"
)

func main() {
	fmt.Println("Hello")
	glog.Info("World")
}

Requirements

  • I have read and followed the instructions above and understand that my issue will be closed if I did not provide the required information.
@Pagliacii Pagliacii added the bug Something isn't working label Jul 6, 2023
@Pagliacii Pagliacii changed the title goimports-reviser removes the module that not in go.mod goimports-reviser with -rm-unused removes the module that not in go.mod Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant