-
Notifications
You must be signed in to change notification settings - Fork 761
goimports-reviser with -rm-unused removes the module that not in go.mod #1617
Description
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()
endSteps to Reproduce
Test go file:
// main.go
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello")
}- nvim --clean -u minimal_init.lua main.go
- add this line
glog.Info("World")into main function - add the module import statement
"github.com/golang/glog"after"fmt" - 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.luatemplate and that my issue is reproducible by runningnvim --clean -u minimal_init.luaand 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 errorsFile 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.