Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b1612ed
supports for treesitter main
ray-x Sep 20, 2025
ca144ec
add guihua to unit test
ray-x Sep 20, 2025
483f842
github pipeline
ray-x Sep 21, 2025
ce2cafe
nvim-treesitter.query
ray-x Sep 21, 2025
1a15930
Merge branch 'master' into treesitter-main
ray-x Sep 24, 2025
db79d7e
fix typo
ray-x Sep 24, 2025
3d863df
doc update
ray-x Sep 24, 2025
589b421
Merge branch 'master' into treesitter-main
ray-x Nov 7, 2025
dc8d70d
adding gopls cmds routing and update doc
ray-x Nov 7, 2025
05324d5
Merge branch 'master' into treesitter-main
ray-x Nov 9, 2025
ac3a441
trying to handle both master and main
ray-x Nov 9, 2025
4997a92
health for treesitter main branch
ray-x Nov 9, 2025
aaa85c7
ginkgo fix for treesitter-main
ray-x Nov 10, 2025
8026196
update sandbox init.lua
ray-x Nov 10, 2025
a20e447
format updates
ray-x Nov 22, 2025
4659981
remove neovim 0.10.4 in test
ray-x Nov 22, 2025
49e5c8f
fix diagnostic
ray-x Nov 22, 2025
a3d04d5
more treesitter fixs
ray-x Nov 22, 2025
64d3945
use minimal lua
ray-x Nov 22, 2025
0341ec3
move test and treesitter fix
ray-x Nov 22, 2025
7c1daaa
Change Makefile with lua config
ray-x Nov 22, 2025
9335420
update test lua config
ray-x Nov 22, 2025
a532ea8
update pipeline
ray-x Nov 22, 2025
a383fe6
update test pipeline
ray-x Nov 22, 2025
6becdf7
fix log path in tests
ray-x Nov 22, 2025
1d88a76
fix log_path warning in tests
ray-x Nov 22, 2025
6853bca
a few fix for treesitter
ray-x Nov 22, 2025
101907d
increase install parser waiting time
ray-x Nov 22, 2025
55f604f
Add install parser step
ray-x Nov 23, 2025
0424144
github pipeline update
ray-x Nov 23, 2025
e038c0d
update github pipeline
ray-x Nov 23, 2025
1477ad4
workflow updates
ray-x Nov 23, 2025
ddd5472
update workflows
ray-x Nov 23, 2025
08db52d
update nvim env vars
ray-x Nov 23, 2025
64c0f9b
update minimal.lua
ray-x Nov 23, 2025
d19b42e
Update minimal.lua
ray-x Nov 23, 2025
2936b1d
update env var
ray-x Nov 23, 2025
f379906
update setup script
ray-x Nov 23, 2025
68e4611
fix treesitter main
ray-x Nov 23, 2025
e0b2b09
update minimal.lua
ray-x Nov 23, 2025
e3d6bd6
add ts binary into runtime
ray-x Nov 23, 2025
fb596d4
add debug logs
ray-x Nov 23, 2025
edd3359
fix minimal
ray-x Nov 23, 2025
48481ad
add debug logs
ray-x Nov 23, 2025
00fe257
add logs
ray-x Nov 23, 2025
68e9bf4
fix install-parsers
ray-x Nov 23, 2025
c18b6a2
add fix for install-parsers
ray-x Nov 23, 2025
a794d32
copy parsers
ray-x Nov 23, 2025
4ed0028
fix install-parsers
ray-x Nov 23, 2025
1f388d5
download and compile
ray-x Nov 23, 2025
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
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ jobs:
url: https://github.com/neovim/neovim/releases/download/stable/nvim-linux-x86_64.tar.gz
manager: sudo snap
packages: go
- os: ubuntu-22.04
url: https://github.com/neovim/neovim/releases/download/v0.10.4/nvim-linux-x86_64.tar.gz
manager: sudo snap
packages: go
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand Down Expand Up @@ -51,10 +47,15 @@ jobs:
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
git clone --depth 1 https://github.com/neovim/nvim-lspconfig ~/.local/share/nvim/site/pack/vendor/start/nvim-lspconfig
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter
git clone --depth 1 -b main https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter
git clone --depth 1 https://github.com/ray-x/guihua.lua ~/.local/share/nvim/site/pack/vendor/start/guihua.lua
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
- name: Compile parsers
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
nvim -l lua/tests/install-parsers.lua --max-jobs=2
- name: Run tests
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
nvim --headless -u lua/tests/minimal.vim -i NONE -c "TSInstallSync go" -c "q"
nvim --headless -u lua/tests/minimal.lua -i NONE -c "TSInstall go" -c "q"
make test
29 changes: 20 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
PACKER_DIR = ~/.local/share/nvim/site/pack/vendor/start

test:
nvim --headless --noplugin -u lua/tests/minimal.vim -c "PlenaryBustedDirectory lua/tests/ {minimal_init = 'lua/tests/minimal.vim'}"
nvim --headless --noplugin -u lua/tests/minimal.lua -c "PlenaryBustedDirectory lua/tests/ {minimal_init = 'lua/tests/minimal.lua'}"
localfailed: localtestsetup
nvim --headless --noplugin -u lua/tests/init.vim -c "PlenaryBustedDirectory lua/tests/failed {minimal_init = 'lua/tests/init.vim'}"
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedDirectory lua/tests/failed {minimal_init = 'lua/tests/init.lua'}"
localtest: localtestsetup
nvim --headless --noplugin -u lua/tests/init.vim -c "PlenaryBustedDirectory lua/tests/ {minimal_init = 'lua/tests/init.vim'}"
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedDirectory lua/tests/ {minimal_init = 'lua/tests/init.lua'}"
localtestfile: localtestsetup
nvim --headless --noplugin -u lua/tests/init.vim -c "PlenaryBustedFile lua/tests/go_test_spec.lua"
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedFile lua/tests/go_test_spec.lua"
localtestts: localtestsetup
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedFile lua/tests/go_ts_node_spec.lua"
localtesttag: localtestsetup
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedFile lua/tests/go_tags_spec.lua"
localtestmod: localtestsetup
nvim --headless --noplugin -u lua/tests/init.vim -c "PlenaryBustedFile lua/tests/go_module_spec.lua"
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedFile lua/tests/go_module_spec.lua"
localtestfix: localtestsetup
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedFile lua/tests/go_fixplurals_spec.lua"

localtestgoplsfill: localtestsetup
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedFile lua/tests/go_fillstruct_spec.lua"
localtestgoplsimport: localtestsetup
nvim --headless --noplugin -u lua/tests/init.lua -c "PlenaryBustedFile lua/tests/go_gopls_imports_spec.lua"
lint:
luacheck lua/go
clean:
Expand All @@ -25,12 +36,12 @@ localtestsetup:
@test -d $(PACKER_DIR)/nvim-lspconfig ||\
git clone --depth 1 https://github.com/neovim/nvim-lspconfig $(PACKER_DIR)/nvim-lspconfig

@test -d $(PACKER_DIR)/guihua ||\
git clone --depth 1 https://github.com/ray-x/guihua.lua $(PACKER_DIR)/guihua
@test -d $(PACKER_DIR)/guihua.lua ||\
git clone --depth 1 https://github.com/ray-x/guihua.lua $(PACKER_DIR)/guihua.lua

@test -d $(PACKER_DIR)/nvim-treesitter ||\
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter $(PACKER_DIR)/nvim-treesitter
git clone --depth 1 -b main https://github.com/nvim-treesitter/nvim-treesitter $(PACKER_DIR)/nvim-treesitter

@test -d $(PACKER_DIR)/go.nvim || ln -s ${shell pwd} $(PACKER_DIR)

nvim --headless -u lua/tests/minimal.vim -i NONE -c "TSUpdateSync go" -c "q"
nvim --headless -u lua/tests/minimal.vim -i NONE -c "TSUpdate go" -c "q"
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The plugin covers most features required for a gopher.

## Installation

Use your favorite package manager to install. The dependency `treesitter` (and optionally, treesitter-objects) should be
Use your favorite package manager to install. The dependency `treesitter` **main** branch (and optionally, treesitter-objects) should be
installed the first time you use it. Also Run `TSInstall go` to install the go parser if not installed yet. `sed` is
recommended to run this plugin.

Expand All @@ -58,14 +58,14 @@ recommended to run this plugin.
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/go.nvim'
Plug 'ray-x/guihua.lua' ; recommended if need floating window support
Plug 'ray-x/guihua.lua' ; required if you using treesitter main branch
```

### [packer.nvim](https://github.com/wbthomason/packer.nvim)
### [packer.nvim/pckr.nvim](https://github.com/lewis6991/pckr.nvim)

```lua
use 'ray-x/go.nvim'
use 'ray-x/guihua.lua' -- recommended if need floating window support
use 'ray-x/guihua.lua' -- required if using treesitter main branch
use 'neovim/nvim-lspconfig'
use 'nvim-treesitter/nvim-treesitter'
```
Expand All @@ -80,11 +80,8 @@ use 'nvim-treesitter/nvim-treesitter'
"neovim/nvim-lspconfig",
"nvim-treesitter/nvim-treesitter",
},
opts = {
-- lsp_keymaps = false,
-- other options
},
config = function(lp, opts)
opts = function()

require("go").setup(opts)
local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {})
vim.api.nvim_create_autocmd("BufWritePre", {
Expand All @@ -94,6 +91,10 @@ use 'nvim-treesitter/nvim-treesitter'
end,
group = format_sync_grp,
})
return {
-- lsp_keymaps = false,
-- other options
}
end,
event = {"CmdlineEnter"},
ft = {"go", 'gomod'},
Expand Down Expand Up @@ -850,6 +851,8 @@ require('go').setup({
-- signs = {'', '', '', ''}, -- set to true to use default signs, an array of 4 to specify custom signs
-- update_in_insert = false,
-- },
-- set to false/nil: disable config gopls diagnostic

-- if you need to setup your ui for input and select, you can do it here
-- go_input = require('guihua.input').input -- set to vim.ui.input to disable guihua input
-- go_select = require('guihua.select').select -- vim.ui.select to disable guihua select
Expand Down
68 changes: 68 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
-- Define the plugin directory variable (s:plugin_dir in VimScript)
local plugin_dir = vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start')

-- set rtp+=.
vim.opt.rtp:append('.')

-- execute 'set rtp^=' . s:plugin_dir . '/plenary.nvim'
-- execute 'set rtp^=' . s:plugin_dir . '/nvim-treesitter'
-- execute 'set rtp^=' . s:plugin_dir . '/nvim-lspconfig'
vim.opt.rtp:prepend(plugin_dir .. '/plenary.nvim')
vim.opt.rtp:prepend(plugin_dir .. '/nvim-treesitter')
vim.opt.rtp:prepend(plugin_dir .. '/nvim-lspconfig')

-- runtime! plugin/plenary.vim
-- runtime! plugin/nvim-treesitter.vim
-- runtime! plugin/playground.vim
-- runtime! plugin/nvim-lspconfig.vim
vim.cmd('runtime! plugin/plenary.vim')
vim.cmd('runtime! plugin/nvim-treesitter.vim')
vim.cmd('runtime! plugin/playground.vim')
vim.cmd('runtime! plugin/nvim-lspconfig.vim')

-- Option settings (set noswapfile, set nobackup, etc.)
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.writebackup = false
vim.opt.autoindent = false
vim.opt.cindent = false
vim.opt.smartindent = false
vim.opt.indentexpr = ''
vim.opt.shada = 'NONE'

-- filetype indent off
vim.cmd('filetype indent off')

-- Lua configuration block
_G.test_rename = true
_G.test_close = true

-- require("plenary/busted")
require('plenary.busted')

-- require("go").setup({...})
require('go').setup({
gofmt = 'gofumpt',
goimports = 'goimports',
verbose = true,
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
lsp_cfg = true,
})

vim.lsp.enable('gopls')

require('nvim-treesitter').setup({
-- Directory to install parsers and queries to
install_dir = vim.fn.stdpath('data') .. '/site',
})

vim.api.nvim_create_autocmd('FileType', {
pattern = { 'go' },
callback = function()
local queries = require('nvim-treesitter.config').get_installed('queries')
if not vim.tbl_contains(queries, 'go') then
error('No queries for go found')
end
pcall(vim.treesitter.start)
end,
})
22 changes: 18 additions & 4 deletions lua/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local vfn = vim.fn
-- Keep this in sync with README.md
-- Keep this in sync with doc/go.txt
_GO_NVIM_CFG = {
treesitter_main = false,
disable_defaults = false, -- true|false when true disable all default settings, user need to set all settings
remap_commands = {}, -- Vim commands to remap or disable, e.g. `{ GoFmt = "GoFormat", GoDoc = false }`
go = 'go', -- set to go1.18beta1 if necessary
Expand Down Expand Up @@ -74,6 +75,8 @@ _GO_NVIM_CFG = {
severity = vim.diagnostic.severity.WARN, -- severity level of the diagnostics
},
},
diagnostic = false, -- set to false to disable diagnostic setup from go.nvim
--[[
diagnostic = { -- set diagnostic to false to disable diagnostic
hdlr = false, -- hook diagnostic handler and send error to quickfix
underline = true,
Expand All @@ -84,7 +87,7 @@ _GO_NVIM_CFG = {
-- signs = {
-- text = { '🚑', '🔧', '🪛', '🧹' },
-- },
},
}, --]]
go_input = function()
if require('go.utils').load_plugin('guihua.lua', 'guihua.gui') then
return require('guihua.input').input
Expand Down Expand Up @@ -210,6 +213,10 @@ function go.setup(cfg)
}
end

-- ts master branch use nvim-treesitter.configs
-- ts main branch use nvim-treesitter.config
local has_ts_main = pcall(require, 'nvim-treesitter.config')
_GO_NVIM_CFG.treesitter_main = has_ts_main
-- legacy options
if type(cfg.null_ls) == 'boolean' then
vim.notify('go.nvim config: null_ls=boolean deprecated, refer to README for more info', vim.log.levels.WARN)
Expand Down Expand Up @@ -274,11 +281,14 @@ function go.setup(cfg)
else
-- we do not setup diagnostic from go.nvim
-- use whatever user has setup
_GO_NVIM_CFG.diagnostic = {}
_GO_NVIM_CFG.diagnostic = nil
end
else
local dcfg = vim.tbl_extend('force', {}, _GO_NVIM_CFG.diagnostic)
vim.diagnostic.config(dcfg)
-- vim.notify('go.nvim diagnostic setup deprecated, use vim.diagnostic instead', vim.log.levels.DEBUG)
if next(_GO_NVIM_CFG.diagnostic or {}) then
local dcfg = vim.tbl_extend('force', {}, _GO_NVIM_CFG.diagnostic)
vim.diagnostic.config(dcfg)
end
end
vim.defer_fn(function()
require('go.coverage').setup()
Expand Down Expand Up @@ -334,4 +344,8 @@ go.set_test_runner = function(runner)
vim.notify('runner not supported ' .. runner, vim.log.levels.ERROR)
end

go.config = function()
return _GO_NVIM_CFG
end

return go
46 changes: 25 additions & 21 deletions lua/go/comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,53 @@
-- for func name(args) rets {}
-- add cmts // name : rets
local comment = {}
local placeholder = _GO_NVIM_CFG.comment_placeholder or ""
local ulog = require("go.utils").log
local api = vim.api
local placeholder = _GO_NVIM_CFG.comment_placeholder or ''
local ulog = require('go.utils').log
local api = vim.api

local ok, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
if not ok then
ts_utils = require('guihua.ts_obsolete.ts_utils')
end
local gen_comment = function()
local comments = nil

local ns = require("go.ts.go").get_package_node_at_pos()
local ns = require('go.ts.go').get_package_node_at_pos()
if ns ~= nil and ns ~= {} then
-- ulog("parnode" .. vim.inspect(ns))
comments = "// Package " .. ns.name .. " provides " .. ns.name
comments = '// Package ' .. ns.name .. ' provides ' .. ns.name
return comments, ns
end
ns = require("go.ts.go").get_func_method_node_at_pos()
ns = require('go.ts.go').get_func_method_node_at_pos()
if ns ~= nil and ns ~= {} then
-- ulog("parnode" .. vim.inspect(ns))
comments = "// " .. ns.name .. " " .. ns.type
comments = '// ' .. ns.name .. ' ' .. ns.type
return comments, ns
end
ns = require("go.ts.go").get_struct_node_at_pos()
ns = require('go.ts.go').get_struct_node_at_pos()
if ns ~= nil and ns ~= {} then
comments = "// " .. ns.name .. " " .. ns.type
comments = '// ' .. ns.name .. ' ' .. ns.type
return comments, ns
end
ns = require("go.ts.go").get_interface_node_at_pos()
ns = require('go.ts.go').get_interface_node_at_pos()
if ns ~= nil and ns ~= {} then
-- ulog("parnode" .. vim.inspect(ns))
comments = "// " .. ns.name .. " " .. ns.type
comments = '// ' .. ns.name .. ' ' .. ns.type
return comments, ns
end

ns = require("go.ts.go").get_type_node_at_pos()
ns = require('go.ts.go').get_type_node_at_pos()
if ns ~= nil and ns ~= {} then
-- ulog("parnode" .. vim.inspect(ns))
comments = "// " .. ns.name .. " " .. ns.type
comments = '// ' .. ns.name .. ' ' .. ns.type
return comments, ns
end
return ""
return ''
end

local wrap_comment = function(comment_line, ns)
if string.len(comment_line) > 0 and placeholder ~= nil and string.len(placeholder) > 0 then
return comment_line .. " " .. placeholder, ns
return comment_line .. ' ' .. placeholder, ns
end
return comment_line, ns
end
Expand All @@ -55,29 +60,28 @@ comment.gen = function()
local bufnr = api.nvim_get_current_buf()
if ns == nil then
-- nothing found
local ts_utils = require("nvim-treesitter.ts_utils")
ns = ts_utils.get_node_at_cursor()
local node_text = require("go.utils").get_node_text(ns, bufnr)
local node_text = require('go.utils').get_node_text(ns, bufnr)

local line = api.nvim_get_current_line()
local regex = "^(%s+)"
local regex = '^(%s+)'
local q = line:match(regex)
c = (q or "") .. "// " .. node_text
c = (q or '') .. '// ' .. node_text
c, _ = wrap_comment(c, {})
vim.fn.append(row - 1, c)
vim.fn.cursor(row, #c + 1)
return
end
ulog(vim.inspect(ns))
row, col = ns.dim.s.r, ns.dim.s.c
ulog("set cursor " .. tostring(row))
ulog('set cursor ' .. tostring(row))
api.nvim_win_set_cursor(0, { row, col })
-- insert doc
vim.fn.append(row - 1, c)
-- set curosr
vim.fn.cursor(row, #c + 1)
-- enter into insert mode
api.nvim_command("startinsert!")
api.nvim_command('startinsert!')
return c
end

Expand Down
Loading
Loading