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

Fixtures Updates #392

Merged
merged 31 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions .luacheckcache

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.diagnostics.globals": [
"vim",
"describe",
"it",
"before_each",
"after_each",
"teardown",
"pending",
"lfs"
],
"Lua.workspace.checkThirdParty": false,
"Lua.workspace.library": [
"${3rd}/lfs/library"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ require('go').setup({
-- settings with {}
go='go', -- go command, can be go[default] or go1.18beta1
goimport='gopls', -- goimport command, can be gopls[default] or goimport
fillstruct = 'gopls', -- can be nil (use fillstruct, slower) and gopls
fillstruct = 'gopls', -- default, can also use fillstruct
gofmt = 'gofumpt', --gofmt cmd,
max_line_len = 128, -- max line length in golines format, Target maximum line length for golines
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options
Expand Down
4 changes: 2 additions & 2 deletions lua/go/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ M.gofmt = function(...)
end

M.org_imports = function()
local r = require('go.lsp').codeaction('', 'source.organizeImports', function()
require('go.lsp').codeaction('', 'source.organizeImports', function()
vim.lsp.buf.format({
async = _GO_NVIM_CFG.lsp_fmt_async,
bufnr = vim.api.nvim_get_current_buf(),
Expand All @@ -172,7 +172,7 @@ M.org_imports = function()
end

M.goimport = function(...)
local goimport = _GO_NVIM_CFG.goimport or 'goimports'
local goimport = _GO_NVIM_CFG.goimport or 'gopls'
local args = { ... }
log(args, goimport)
if goimport == 'gopls' then
Expand Down
9 changes: 5 additions & 4 deletions lua/go/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local on_attach = function(client, bufnr)
end
local keymaps
if _GO_NVIM_CFG.lsp_keymaps == true then
log('go.nvim lsp_keymaps', client, bufnr)
log('go.nvim lsp_keymaps', bufnr)
keymaps = {
{ key = 'gd', func = vim.lsp.buf.definition, desc = 'goto definition' },
{ key = 'K', func = vim.lsp.buf.hover, desc = 'hover' },
Expand Down Expand Up @@ -232,8 +232,8 @@ function M.setup()

local vim_version = vim.version().major * 100 + vim.version().minor * 10 + vim.version().patch

if vim_version < 61 then
vim.notify('LSP: go.nvim requires neovim 0.6.1 or later', vim.log.levels.WARN)
if vim_version < 81 then
vim.notify('LSP: go.nvim requires neovim 0.8.1 or later', vim.log.levels.WARN)
end
log(goplscfg)
lspconfig.gopls.setup(goplscfg)
Expand All @@ -253,11 +253,12 @@ write", "source", "source.organizeImports" }
-- only this action 'refactor.rewrite' source.organizeImports
M.codeaction = function(action, only, hdlr)
local params = vim.lsp.util.make_range_params()
log(action, only)
if only then
params.context = { only = { only } }
end
local bufnr = vim.api.nvim_get_current_buf()

log(action, only, bufnr)
vim.lsp.buf_request_all(bufnr, 'textDocument/codeAction', params, function(result)
if not result or next(result) == nil then
log('nil result')
Expand Down
2 changes: 1 addition & 1 deletion lua/tests/fixtures/coverage/branch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package coverage

// import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion lua/tests/fixtures/coverage/branch_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package coverage

import "testing"

Expand Down
3 changes: 0 additions & 3 deletions lua/tests/fixtures/coverage/go.mod

This file was deleted.

2 changes: 1 addition & 1 deletion lua/tests/fixtures/coverage/tag_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+build integration,unit

package main
package coverage

func TestTag(t *testing.T) {
t.Log("TestTag")
Expand Down
3 changes: 0 additions & 3 deletions lua/tests/fixtures/fill/go.mod

This file was deleted.

3 changes: 0 additions & 3 deletions lua/tests/fixtures/fixplurals/go.mod

This file was deleted.

3 changes: 0 additions & 3 deletions lua/tests/fixtures/fmt/go.mod

This file was deleted.

3 changes: 3 additions & 0 deletions lua/tests/fixtures/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module fixtures

go 1.21.1
3 changes: 0 additions & 3 deletions lua/tests/fixtures/ts/go.mod

This file was deleted.

21 changes: 12 additions & 9 deletions lua/tests/go_commands_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,26 @@ describe('should run Go commands', function()
vim.fn.writefile(lines, name)
local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
local bufn = vim.fn.bufnr('')
-- local bufn = vim.fn.bufnr('')
--
vim.cmd('GoFmt')

vim.cmd('GoRun')
vim.cmd('GoBuild')
path = cur_dir .. '/lua/tests/fixtures/'
local fname = 'coverage/branch_test.go' -- %:p:h ? %:p

path = cur_dir .. '/lua/tests/fixtures/coverage/branch_test.go' -- %:p:h ? %:p
-- local lines = vim.fn.readfile(path)
vim.cmd('cd ' .. path)

lines = vim.fn.readfile(path)
-- name = vim.fn.tempname() .. '.go'
-- vim.fn.writefile(lines, name)
local cmd = " silent exe 'e " .. fname .. "'"

name = vim.fn.tempname() .. '.go'
vim.fn.writefile(lines, name)
cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
bufn = vim.fn.bufnr('')
vim.cmd('GoRun')
vim.cmd('GoBuild')

vim.cmd('GoTest')
vim.cmd('GoTest -c')
vim.cmd('GoFmt')
end)
end)
42 changes: 21 additions & 21 deletions lua/tests/go_fillstruct_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@ local _ = require('plenary/busted')

local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h')
-- local status = require("plenary.reload").reload_module("go.nvim")
-- status = require("plenary.reload").reload_module("nvim-treesitter")
-- local ulog = require('go.utils').log
describe('should run fillstruct', function()
vim.cmd([[packadd go.nvim]])

-- _GO_NVIM_CFG.fillstruct = "fillstruct"
it('should run fillstruct', function()
--

local name = vim.fn.tempname() .. '.go'
local path = cur_dir .. '/lua/tests/fixtures/fill/fill_struct_input.go' -- %:p:h ? %:p
local lines = vim.fn.readfile(path)
vim.fn.writefile(lines, name)
vim.o.ft = 'go'
local expected = vim.fn.join(
vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fill/fill_struct_golden.txt'),
'\n'
)
local cmd = " silent exe 'e " .. path .. "'"

local path = cur_dir .. '/lua/tests/fixtures/' -- %:p:h ? %:p
vim.cmd('cd ' .. path)
local fname = 'fill/fill_struct_input.go'

local cmd = " silent exe 'e " .. fname .. "'"
vim.cmd(cmd)
-- _GO_NVIM_CFG.log_path = '' -- log to console in github actions
vim.bo.filetype = 'go'
require('plenary.reload').reload_module('go.nvim')
require('go').setup({ verbose = true, lsp_cfg = true })

vim.cmd('sleep 1000m') -- allow gopls startup
vim.cmd('sleep 1500m') -- allow gopls startup
vim.fn.setpos('.', { 0, 20, 14, 0 })

vim.bo.filetype = 'go'

require('go.reftool').fillstruct()

vim.cmd('sleep 500m') -- allow cleanup
vim.wait(100, function()
local filled = vim.api.nvim_buf_get_lines(0, 0, 40, false)

-- local path = cur_dir .. "/lua/tests/fixtures/fill/fill_struct_input.go2" -- %:p:h ? %:p
-- vim.fn.writefile(filled, path)
local filled
for _ = 1, 6 do
require('go.utils').log('waiting for fill')
vim.wait(1000, function() return false end)

filled = vim.api.nvim_buf_get_lines(0, 0, 40, false)
filled = vim.fn.join(filled, '\n')
eq(expected, filled)
end)
require('go.utils').log(vim.inspect(filled))
if expected == filled then
break
end
end

eq(expected, filled)
end)
end)
53 changes: 37 additions & 16 deletions lua/tests/go_gopls_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@ local eq = assert.are.same
local cur_dir = vim.fn.expand('%:p:h')
local busted = require('plenary/busted')

local godir = cur_dir .. '/lua/tests/fixtures'
describe('should run gopls releated functions', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
require('plenary.reload').reload_module('go.nvim')
local cmd = " silent exe 'e temp.go'"
vim.cmd(cmd)
require('go').setup({ goimport = 'gopls', lsp_cfg = true })

vim.cmd([[packadd go.nvim]])
it('should run import from file with gopls', function()
local path = cur_dir .. '/lua/tests/fixtures/fmt/goimports2.go' -- %:p:h ? %:p
require('plenary.reload').reload_module('go.nvim')
local cmd = " silent exe 'e temp.go'"
vim.cmd(cmd)
require('go').setup({ goimport = 'gopls', lsp_cfg = true })
local path = './fmt/goimports2.go' -- %:p:h ? %:p
local expected =
vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fmt/goimports2_golden.go'), '\n')

vim.cmd('%bdelete!')
local cmd = " silent exe 'e " .. path .. "'"
vim.cmd('cd ' .. godir)
cmd = " silent exe 'e " .. path .. "'"
vim.cmd(cmd)

vim.cmd([[cd %:p:h]])
_GO_NVIM_CFG.goimport = 'gopls'
vim.wait(2000, function()
return false
end)
local c = vim.lsp.get_active_clients()
eq(#c > 0, true)
require('go.format').goimport()
vim.wait(100, function()
return false
Expand All @@ -39,23 +44,39 @@ describe('should run gopls releated functions', function()
vim.cmd(cmd)
end)
it('should run import from file with gopls', function()
vim.cmd('%bdelete!')
local path = cur_dir .. '/lua/tests/fixtures/fmt/goimports3.go' -- %:p:h ? %:p
require('plenary.reload').reload_module('go.nvim')

require('go').setup({ goimport = 'gopls', verbose = true, log_path = '', lsp_cfg = true })
local cmd = " silent exe 'e temp.go'"
vim.cmd(cmd)
_GO_NVIM_CFG.log_path = '' -- enable log to console
local expected =
vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fmt/goimports3_golden.go'), '\n')
local cmd = " silent exe 'e " .. path .. "'"

vim.cmd('cd ' .. godir)
local path = './fmt/goimports3.go' -- %:p:h ? %:p
cmd = " silent exe 'e " .. path .. "'"
vim.cmd(cmd)

vim.cmd([[cd %:p:h]])
vim.wait(500, function()
vim.wait(2000, function()
return false
end)

_GO_NVIM_CFG.log_path = '' -- enable log to console
require('go.format').goimport()
vim.wait(200, function() end)
vim.cmd([[wa]])

print('workspaces:', vim.inspect(vim.lsp.buf.list_workspace_folders()))
local fmt = vim.fn.join(vim.fn.readfile(path), '\n')
print(vim.inspect(fmt))
local fmt
for _ = 1, 6 do
require('go.utils').log('waiting for import')
vim.wait(1000, function() return false end)
vim.cmd([[wa]])
fmt = vim.fn.join(vim.fn.readfile(path), '\n')
require('go.utils').log(vim.inspect(fmt))
if expected == fmt then
break
end
end
eq(expected, fmt)
-- eq(1, 1) -- still not working
cmd = 'bd! ' .. path
Expand Down
45 changes: 25 additions & 20 deletions lua/tests/go_make_spec.lua
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
local eq = assert.are.same
local cur_dir = vim.fn.expand("%:p:h")
local busted = require("plenary/busted")
local cur_dir = vim.fn.expand('%:p:h')
local busted = require('plenary/busted')

describe("should run func make", function()
describe('should run func make', function()
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
require("plenary.reload").reload_module("go.nvim")
it("should make function", function()
require('plenary.reload').reload_module('go.nvim')
it('should make function', function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])

local path = cur_dir .. "/lua/tests/fixtures/coverage/branch_test.go" -- %:p:h ? %:p
require("go").setup({
local path = cur_dir .. '/lua/tests/fixtures/'
local fname = 'coverage/branch_test.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos(".", { 0, 5, 11, 0 })
local cmd = require("go.asyncmake").make('go', 'vet', '.')
vim.cmd("silent cd " .. path)
vim.cmd("silent exe 'e " .. fname .. "'")
vim.fn.setpos('.', { 0, 5, 11, 0 })
local cmd = require('go.asyncmake').make('go', 'vet', './coverage')
print(vim.inspect(cmd))

eq({ "go", "vet", "."}, cmd)
eq({ 'go', 'vet', './coverage' }, cmd)
end)
it("should make function inside a source code", function()
it('should make function inside a source code', function()
--
-- go.nvim may not auto loaded
vim.cmd([[packadd go.nvim]])

local path = cur_dir .. "/lua/tests/fixtures/coverage/branch.go" -- %:p:h ? %:p
require("go").setup({
local path = cur_dir .. '/lua/tests/fixtures/'
local fname = './coverage/branch.go' -- %:p:h ? %:p
require('go').setup({
trace = true,
lsp_cfg = true,
log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
})
vim.cmd("silent exe 'e " .. path .. "'")
vim.fn.setpos(".", { 0, 6, 11, 0 })
local cmd = require("go.asyncmake").make('go', 'test', './...')

eq({ "go", "test", "./..."}, cmd)
vim.cmd("silent cd " .. path)
vim.cmd("silent exe 'e " .. fname .. "'")
vim.fn.setpos('.', { 0, 6, 11, 0 })
local cmd = require('go.asyncmake').make('go', 'test', './coverage')

eq({ 'go', 'test', './coverage' }, cmd)
end)
end)
Loading
Loading