gopls test case

pull/25/head
ray-x 3 years ago
parent 21ee2891ef
commit 8db7f9af39

@ -0,0 +1,5 @@
package main
func foo() {
fmt.Println("vim-go")
}

@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("vim-go")
}

@ -2,6 +2,6 @@ package main
import "fmt" import "fmt"
func main() { func foo() {
fmt.Println("vim-go") fmt.Println("vim-go")
} }

@ -93,29 +93,30 @@ describe("should run gofmt", function()
vim.cmd(cmd) vim.cmd(cmd)
end) end)
it("should run import from file with gopls", function() it("should run import from file with gopls", function()
local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports.go" -- %:p:h ? %:p local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports2.go" -- %:p:h ? %:p
local expected = vim.fn.join(vim.fn.readfile(cur_dir local expected = vim.fn.join(vim.fn.readfile(cur_dir
.. "/lua/tests/fixtures/fmt/goimports_golden.go"), .. "/lua/tests/fixtures/fmt/goimports2_golden.go"),
"\n") "\n")
require("go").setup({goimport = "gopls", lsp_cfg = true}) require("go").setup({goimport = "gopls", lsp_cfg = true})
_GO_NVIM_CFG.goimport = 'gopls' _GO_NVIM_CFG.goimport = 'gopls'
local name = vim.fn.tempname() .. ".go"
print(name)
local lines = vim.fn.readfile(path) local lines = vim.fn.readfile(path)
vim.fn.writefile(lines, name) local cmd = " silent exe 'e " .. path .. "'"
local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd) vim.cmd(cmd)
vim.wait(1000, function()
end)
vim.cmd([[cd %:p:h]]) vim.cmd([[cd %:p:h]])
require("go.format").goimport() require("go.format").goimport()
print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders())) print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders()))
vim.wait(100, function() vim.wait(200, function()
end) end)
local fmt = vim.fn.join(vim.fn.readfile(name), "\n") local fmt = vim.fn.join(vim.fn.readfile(path), "\n")
-- eq(expected, fmt) eq(expected, fmt)
eq(1, 1) -- still not working eq(1, 1) -- still not working
cmd = "bd! " .. name cmd = "bd! " .. path
vim.cmd(cmd) vim.cmd(cmd)
end) end)
it("should run import from file buffer with gofumpts", function() it("should run import from file buffer with gofumpts", function()

Loading…
Cancel
Save