From b1612ed69404ea972b53137727b955c47ff8a90b Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 20 Sep 2025 17:25:55 +1000 Subject: [PATCH 01/47] supports for treesitter main --- .github/workflows/ci.yml | 2 +- lua/go/ts/go.lua | 32 +++++++++++++++++--------------- lua/go/ts/nodes.lua | 25 +++++++++---------------- lua/go/ts/utils.lua | 5 +++-- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a31d32c7..5d94f4970 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ 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 ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start - name: Run tests run: | diff --git a/lua/go/ts/go.lua b/lua/go/ts/go.lua index 33bef1450..8cdde3601 100644 --- a/lua/go/ts/go.lua +++ b/lua/go/ts/go.lua @@ -1,6 +1,6 @@ local nodes = require('go.ts.nodes') -local tsutil = require('nvim-treesitter.ts_utils') +local tsutil = require('guihua.ts_obsolete.ts_utils') local log = require('go.utils').log local warn = require('go.utils').warn local info = require('go.utils').info @@ -17,19 +17,23 @@ local M = { query_package = '(package_clause (package_identifier)@package.name)@package.clause', query_struct_id = '(type_spec name:(type_identifier) @definition.struct (struct_type))', query_em_struct_id = '(field_declaration name:(field_identifier) @definition.struct (struct_type))', - query_struct_block = [[((type_declaration (type_spec name:(type_identifier) @struct.name type: (struct_type)))@struct.declaration)]], - query_struct_block_type = [[((type_spec name:(type_identifier) @struct.name type: (struct_type))@struct.declaration)]], -- type(struct1, struct2) + query_struct_block = + [[((type_declaration (type_spec name:(type_identifier) @struct.name type: (struct_type)))@struct.declaration)]], + query_struct_block_type = [[((type_spec name:(type_identifier) @struct.name type: (struct_type))@struct.declaration)]], -- type(struct1, struct2) -- query_type_declaration = [[((type_declaration (type_spec name:(type_identifier)@type_decl.name type:(type_identifier)@type_decl.type))@type_decl.declaration)]], -- rename to gotype so not confuse with type query_type_declaration = [[((type_declaration (type_spec name:(type_identifier)@type_decl.name)))]], - query_em_struct_block = [[(field_declaration name:(field_identifier)@struct.name type: (struct_type)) @struct.declaration]], + query_em_struct_block = + [[(field_declaration name:(field_identifier)@struct.name type: (struct_type)) @struct.declaration]], query_struct_block_from_id = [[(((type_spec name:(type_identifier) type: (struct_type)))@block.struct_from_id)]], -- query_em_struct = "(field_declaration name:(field_identifier) @definition.struct type: (struct_type))", - query_interface_id = [[((type_declaration (type_spec name:(type_identifier) @interface.name type:(interface_type)))@interface.declaration)]], + query_interface_id = + [[((type_declaration (type_spec name:(type_identifier) @interface.name type:(interface_type)))@interface.declaration)]], -- query_interface_method = [[((method_spec name: (field_identifier)@method.name)@interface.method.declaration)]], query_interface_method = [[((method_elem name: (field_identifier)@method.name)@interface.method.declaration)]], -- -- this is a breaking change require TS parser update query_func = '((function_declaration name: (identifier)@function.name) @function.declaration)', - query_method = '(method_declaration receiver: (parameter_list (parameter_declaration name:(identifier)@method.receiver.name type:(type_identifier)@method.receiver.type)) name:(field_identifier)@method.name)@method.declaration', + query_method = + '(method_declaration receiver: (parameter_list (parameter_declaration name:(identifier)@method.receiver.name type:(type_identifier)@method.receiver.type)) name:(field_identifier)@method.name)@method.declaration', query_method_name = [[((method_declaration receiver: (parameter_list)@method.receiver name: (field_identifier)@method.name @@ -258,11 +262,10 @@ M.get_tbl_testcase_node_name = function(bufnr) end end for _, node in pairs(nodes) do - local n = get_tc_block(node, function(start_row, end_row, curr_row) if (start_row <= curr_row and curr_row <= end_row) then -- curr_row starts from 1 - trace('valid node:', node) -- the nvim manual is out of sync for release version - return true -- cursor is in the same line, this is a strong match + trace('valid node:', node) -- the nvim manual is out of sync for release version + return true -- cursor is in the same line, this is a strong match end end) if n then @@ -272,15 +275,15 @@ M.get_tbl_testcase_node_name = function(bufnr) local start_row, _, end_row, _ = node:range() local result = {} -- find kv nodes inside test case struct - for pattern2, match2, _ in tbl_case_kv_query:iter_matches(tree:root(), bufn, start_row, end_row+1) do + for pattern2, match2, _ in tbl_case_kv_query:iter_matches(tree:root(), bufn, start_row, end_row + 1) do local id for i2, nodes2 in pairs(match2) do local name2 = tbl_case_kv_query.captures[i2] -- or tbl_case_kv_query.captures[pattern2] - for i, n2 in pairs(nodes2) do -- the order is abit random + for i, n2 in pairs(nodes2) do -- the order is abit random -- if name2 == 'test.name' then local start_row2, _, end_row2, _ = n2:range() if name2 == 'test.nameid' then - id = vim.treesitter.get_node_text(n2, bufn) + id = vim.treesitter.get_node_text(n2, bufn) if id == 'name' then result[name2] = id end @@ -296,7 +299,7 @@ M.get_tbl_testcase_node_name = function(bufnr) trace('found node', name2, n2:range()) end - trace('node type name',i2, i, name2, id, start_row2, end_row2, curr_row, tc_name, guess) + trace('node type name', i2, i, name2, id, start_row2, end_row2, curr_row, tc_name, guess) end end end @@ -332,7 +335,7 @@ M.get_sub_testcase_name = function(bufnr) -- tc_run is the first capture of a match, so we can use it to check if we are inside a test if name == 'tc.run' then local start_row, _, end_row, _ = node:range() - if (start_row < curr_row and curr_row <= end_row + 1) then + if (start_row < curr_row and curr_row <= end_row + 1) then is_inside_test = true else is_inside_test = false @@ -340,7 +343,6 @@ M.get_sub_testcase_name = function(bufnr) goto continue end if name == 'tc.name' and is_inside_test then - return string.gsub(vim.treesitter.get_node_text(node, bufn), '"', '') end ::continue:: diff --git a/lua/go/ts/nodes.lua b/lua/go/ts/nodes.lua index 642d02163..1295031b3 100644 --- a/lua/go/ts/nodes.lua +++ b/lua/go/ts/nodes.lua @@ -1,8 +1,9 @@ -- part of the code from polarmutex/contextprint.nvim -local ts_utils = require('nvim-treesitter.ts_utils') + +local ts_utils = require('guihua.ts_obsolete.ts_utils') local ts_query = require('nvim-treesitter.query') local parsers = require('nvim-treesitter.parsers') -local locals = require('nvim-treesitter.locals') +local locals = require('guihua.ts_obsolete.locals') local utils = require('go.ts.utils') local goutil = require('go.utils') local ulog = require('go.utils').log @@ -185,8 +186,8 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype -- stylua: ignore ulog( "node ", vim.inspect(node), "\n path: " .. path .. " op: " .. op - .. " type: " .. type .. "\n txt: " .. dbg_txt .. "\n range: " .. tostring(a1 or 0) - .. ":" .. tostring(b1 or 0) .. " TO " .. tostring(c1 or 0) .. ":" .. tostring(d1 or 0) + .. " type: " .. type .. "\n txt: " .. dbg_txt .. "\n range: " .. tostring(a1 or 0) + .. ":" .. tostring(b1 or 0) .. " TO " .. tostring(c1 or 0) .. ":" .. tostring(d1 or 0) ) -- stylua: ignore end -- @@ -197,8 +198,7 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype type_node = node elseif op == 'declaration' or op == 'clause' then declaration_node = node - sRow, sCol, eRow, eCol = - ts_utils.get_vim_range({ vim.treesitter.get_node_range(node) }, bufnr) + sRow, sCol, eRow, eCol = ts_utils.get_vim_range({ vim.treesitter.get_node_range(node) }, bufnr) else ulog('unknown op: ' .. op) end @@ -219,8 +219,7 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype end if type_node ~= nil and ntype then ulog('type_only') - sRow, sCol, eRow, eCol = - ts_utils.get_vim_range({ vim.treesitter.get_node_range(type_node) }, bufnr) + sRow, sCol, eRow, eCol = ts_utils.get_vim_range({ vim.treesitter.get_node_range(type_node) }, bufnr) table.insert(results, { type_node = type_node, dim = { s = { r = sRow, c = sCol }, e = { r = eRow, c = eCol } }, @@ -263,10 +262,7 @@ M.nodes_at_cursor = function(query, default, bufnr, ntype) end local ns = M.get_all_nodes(query, ft, default, bufnr, row, col, ntype) if ns == nil then - vim.notify( - 'Unable to find any nodes. place your cursor on a go symbol and try again', - vim.log.levels.DEBUG - ) + vim.notify('Unable to find any nodes. place your cursor on a go symbol and try again', vim.log.levels.DEBUG) ulog('Unable to find any nodes. place your cursor on a go symbol and try again') return nil end @@ -282,10 +278,7 @@ M.nodes_at_cursor = function(query, default, bufnr, ntype) ulog(row, col, vim.inspect(nodes_at_cursor):sub(1, 100)) if nodes_at_cursor == nil or #nodes_at_cursor == 0 then if _GO_NVIM_CFG.verbose then - vim.notify( - 'Unable to find any nodes at pos. ' .. tostring(row) .. ':' .. tostring(col), - vim.log.levels.DEBUG - ) + vim.notify('Unable to find any nodes at pos. ' .. tostring(row) .. ':' .. tostring(col), vim.log.levels.DEBUG) end ulog('Unable to find any nodes at pos. ' .. tostring(row) .. ':' .. tostring(col)) return nil diff --git a/lua/go/ts/utils.lua b/lua/go/ts/utils.lua index 9628f4e0d..caf394cd2 100644 --- a/lua/go/ts/utils.lua +++ b/lua/go/ts/utils.lua @@ -1,7 +1,9 @@ local api = vim.api local get_node_text = vim.treesitter.get_node_text -local ts_utils = require('nvim-treesitter.ts_utils') +local ts_utils = require('guihua.ts_obsolete.ts_utils') +local locals = require('guihua.ts_obsolete..locals') + local util = require('go.utils') local log = util.log local trace = util.trace @@ -26,7 +28,6 @@ M.intersects = function(row, col, sRow, sCol, eRow, eCol) return true end -local locals = require('nvim-treesitter.locals') -- from navigator/treesitter.lua -- modified from nvim-treesitter/treesitter-refactor plugin -- Get definitions of bufnr (unique and sorted by order of appearance). From ca144ecc85aaee7cf6b6e0d2feb82634657dc514 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 20 Sep 2025 17:39:09 +1000 Subject: [PATCH 02/47] add guihua to unit test --- .github/workflows/ci.yml | 1 + lua/tests/minimal.vim | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d94f4970..d7febbb73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,7 @@ jobs: 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 -b main https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter + git clone https://github.com/ray-x/guihua.lua.git ~/.local/share/nvim/site/pack/vendor/start/guihua.lua ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start - name: Run tests run: | diff --git a/lua/tests/minimal.vim b/lua/tests/minimal.vim index 8fc2246c9..ea951181d 100644 --- a/lua/tests/minimal.vim +++ b/lua/tests/minimal.vim @@ -7,6 +7,7 @@ runtime! plugin/plenary.vim runtime! plugin/nvim-treesitter.vim runtime! plugin/playground.vim runtime! plugin/nvim-lspconfig.vim +runtime! plugin/guihua.lua set noswapfile set nobackup From 483f84292edd559e9bbadbb373ab90136e15d6cd Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 21 Sep 2025 23:26:49 +1000 Subject: [PATCH 03/47] github pipeline --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7febbb73..aff2d1d0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: 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 -b main https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter - git clone https://github.com/ray-x/guihua.lua.git ~/.local/share/nvim/site/pack/vendor/start/guihua.lua + 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: Run tests run: | From ce2cafe3337aab5bd8630d4af4ddb763187a0981 Mon Sep 17 00:00:00 2001 From: ray-x Date: Mon, 22 Sep 2025 00:13:12 +1000 Subject: [PATCH 04/47] nvim-treesitter.query --- lua/go/ts/nodes.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/go/ts/nodes.lua b/lua/go/ts/nodes.lua index 1295031b3..c4e87659a 100644 --- a/lua/go/ts/nodes.lua +++ b/lua/go/ts/nodes.lua @@ -1,7 +1,7 @@ -- part of the code from polarmutex/contextprint.nvim local ts_utils = require('guihua.ts_obsolete.ts_utils') -local ts_query = require('nvim-treesitter.query') +local ts_query = require('guihua.ts_obsolete.query') local parsers = require('nvim-treesitter.parsers') local locals = require('guihua.ts_obsolete.locals') local utils = require('go.ts.utils') @@ -177,7 +177,7 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype if #dbg_txt > 100 then dbg_txt = string.sub(dbg_txt, 1, 100) .. '...' end - type = string.sub(path, 1, idx - 1) -- e.g. struct.name, type is struct + type = string.sub(path, 1, idx - 1) -- e.g. struct.name, type is struct if type:find('type') and op == 'type' then -- type_declaration.type node_type = get_node_text(node, bufnr) ulog('type: ' .. type) From db79d7e3fefbd5ad1ac42d3d6f32612eb5897961 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 25 Sep 2025 09:50:45 +1000 Subject: [PATCH 05/47] fix typo --- lua/go/ts/utils.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lua/go/ts/utils.lua b/lua/go/ts/utils.lua index caf394cd2..72bc2efd4 100644 --- a/lua/go/ts/utils.lua +++ b/lua/go/ts/utils.lua @@ -2,7 +2,7 @@ local api = vim.api local get_node_text = vim.treesitter.get_node_text local ts_utils = require('guihua.ts_obsolete.ts_utils') -local locals = require('guihua.ts_obsolete..locals') +local locals = require('guihua.ts_obsolete.locals') local util = require('go.utils') local log = util.log @@ -45,9 +45,9 @@ local function get_definitions(bufnr) local _, _, start = node:start() -- variadic_parameter_declaration if - node - and node:parent() - and string.find(node:parent():type(), 'parameter_declaration') + node + and node:parent() + and string.find(node:parent():type(), 'parameter_declaration') then trace('parameter_declaration skip') return @@ -68,7 +68,7 @@ local function get_definitions(bufnr) locals.recurse_local_nodes(loc.interface, function(def, node, full_match, match) local k, l, start = node:start() -- stylua: ignore start - trace( k, l, start, def, node, full_match, match, node:parent(), node:parent():start(), node:parent():type()) + trace(k, l, start, def, node, full_match, match, node:parent(), node:parent():start(), node:parent():type()) -- stylua: ignore end if nodes_set[start] == nil then nodes_set[start] = { node = node, type = match or '' } @@ -80,7 +80,7 @@ local function get_definitions(bufnr) local k, l, start = node:start() -- stylua: ignore start - trace( k, l, start, def, node, full_match, match, node:parent(), node:parent():start(), node:parent():type()) + trace(k, l, start, def, node, full_match, match, node:parent(), node:parent():start(), node:parent():type()) -- stylua: ignore end if nodes_set[start] == nil then -- if node:parent() and node:parent():type() == "field_declaration" then @@ -88,11 +88,11 @@ local function get_definitions(bufnr) -- return -- end -- qualified_type : e.g. io.Reader inside interface if - node:parent() - and node:parent():parent() - and node:type() == 'type_identifier' - and node:parent():type() == 'qualified_type' - and string.find(node:parent():parent():type(), 'interface') + node:parent() + and node:parent():parent() + and node:type() == 'type_identifier' + and node:parent():type() == 'qualified_type' + and string.find(node:parent():parent():type(), 'interface') then nodes_set[start] = { node = node, type = 'interface' } end @@ -147,8 +147,8 @@ function M.list_definitions_toc(bufnr) local index = n + 1 - i local parent_def = parents[index] if - ts_utils.is_parent(parent_def.node, def.node) - or (containers[parent_def.type] and ts_utils.is_parent(parent_def.node:parent(), def.node)) + ts_utils.is_parent(parent_def.node, def.node) + or (containers[parent_def.type] and ts_utils.is_parent(parent_def.node:parent(), def.node)) then break else From 3d863dfb5771796a3ca0edf4e8f7ba6d162f0426 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 25 Sep 2025 09:58:08 +1000 Subject: [PATCH 06/47] doc update --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1454b81f1..a5f67e1df 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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' ``` @@ -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", { @@ -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'}, From dc8d70dc6a1e27b0ce5ac2eb3832ac2fd961a639 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 7 Nov 2025 15:43:49 +1100 Subject: [PATCH 07/47] adding gopls cmds routing and update doc --- README.md | 2 ++ lua/go.lua | 7 +++++-- lua/go/gopls.lua | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dd24042ca..fe927f8af 100644 --- a/README.md +++ b/README.md @@ -850,6 +850,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 diff --git a/lua/go.lua b/lua/go.lua index e71db61d7..07cd8de2c 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -74,6 +74,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, @@ -84,7 +86,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 @@ -274,9 +276,10 @@ 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 + -- vim.notify('go.nvim diagnostic setup deprecated, use vim.diagnostic instead', vim.log.levels.DEBUG) local dcfg = vim.tbl_extend('force', {}, _GO_NVIM_CFG.diagnostic) vim.diagnostic.config(dcfg) end diff --git a/lua/go/gopls.lua b/lua/go/gopls.lua index beca2bec9..d6c7ddaa1 100644 --- a/lua/go/gopls.lua +++ b/lua/go/gopls.lua @@ -27,10 +27,12 @@ local gopls_cmds = { 'gopls.gc_details', 'gopls.generate', 'gopls.go_get_package', + 'gopls.lsp', 'gopls.list_imports', 'gopls.list_known_packages', 'gopls.maybe_prompt_for_telemetry', 'gopls.mem_stats', + 'gopls.modify_tags', 'gopls.modules', 'gopls.package_symbols', 'gopls.packages', @@ -41,6 +43,7 @@ local gopls_cmds = { 'gopls.run_govulncheck', 'gopls.run_tests', 'gopls.scan_imports', + 'gopls.split_package', 'gopls.start_debugging', 'gopls.start_profile', 'gopls.stop_profile', From ac3a441f71ba634fcc390d81f3a5ea0ae967e111 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 9 Nov 2025 13:07:28 +1100 Subject: [PATCH 08/47] trying to handle both master and main --- lua/go/ts/go.lua | 11 ++++++----- lua/go/ts/nodes.lua | 18 +++++++++++++----- lua/go/ts/textobjects.lua | 25 +++++++++++++------------ lua/go/ts/utils.lua | 9 +++++++-- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/lua/go/ts/go.lua b/lua/go/ts/go.lua index 8cdde3601..0c7119070 100644 --- a/lua/go/ts/go.lua +++ b/lua/go/ts/go.lua @@ -1,17 +1,18 @@ local nodes = require('go.ts.nodes') -local tsutil = require('guihua.ts_obsolete.ts_utils') +if _GO_NVIM_CFG.treesitter_main then + local tsutil = require('guihua.ts_obsolete.ts_utils') +else + local tsutil = require('nvim-treesitter.ts_utils') +end + local log = require('go.utils').log local warn = require('go.utils').warn local info = require('go.utils').info local debug = require('go.utils').debug local trace = require('go.utils').trace -local api = vim.api -local parsers = require "nvim-treesitter.parsers" -local utils = require "nvim-treesitter.utils" -local ts = vim.treesitter local M = { query_struct = '(type_spec name:(type_identifier) @definition.struct type: (struct_type))', query_package = '(package_clause (package_identifier)@package.name)@package.clause', diff --git a/lua/go/ts/nodes.lua b/lua/go/ts/nodes.lua index c4e87659a..13c17e8ad 100644 --- a/lua/go/ts/nodes.lua +++ b/lua/go/ts/nodes.lua @@ -1,9 +1,17 @@ -- part of the code from polarmutex/contextprint.nvim -local ts_utils = require('guihua.ts_obsolete.ts_utils') -local ts_query = require('guihua.ts_obsolete.query') -local parsers = require('nvim-treesitter.parsers') -local locals = require('guihua.ts_obsolete.locals') +local ts_utils, ts_query, locals, parsers +if _GO_NVIM_CFG.treesitter_main then + ts_utils = require('guihua.ts_obsolete.ts_utils') + ts_query = require('guihua.ts_obsolete.query') + locals = require('guihua.ts_obsolete.locals') + parsers = require('guihua.ts_obsolete.parsers') +else + ts_utils = require('nvim-treesitter.ts_utils') + ts_query = require('nvim-treesitter.query') + locals = require('nvim-treesitter.locals') + parsers = require('nvim-treesitter.parsers') +end local utils = require('go.ts.utils') local goutil = require('go.utils') local ulog = require('go.utils').log @@ -177,7 +185,7 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype if #dbg_txt > 100 then dbg_txt = string.sub(dbg_txt, 1, 100) .. '...' end - type = string.sub(path, 1, idx - 1) -- e.g. struct.name, type is struct + type = string.sub(path, 1, idx - 1) -- e.g. struct.name, type is struct if type:find('type') and op == 'type' then -- type_declaration.type node_type = get_node_text(node, bufnr) ulog('type: ' .. type) diff --git a/lua/go/ts/textobjects.lua b/lua/go/ts/textobjects.lua index 2a840cf9b..c833914a2 100644 --- a/lua/go/ts/textobjects.lua +++ b/lua/go/ts/textobjects.lua @@ -1,17 +1,18 @@ -local util = require("go.utils") +local util = require('go.utils') local plugins = util.load_plugin local M = {} function M.setup() - if not plugins("nvim-treesitter") then - util.log("treesitter not avalible") + if not plugins('nvim-treesitter') then + util.log('treesitter not avalible') return end local ok, configs = pcall(require, 'nvim-treesitter.configs') if not ok then - configs = require('nvim-treesitter') + -- treesitter main no longer provides textobjects by default + return end configs.setup({ @@ -21,26 +22,26 @@ function M.setup() lookahead = true, keymaps = { -- You can use the capture groups defined in textobjects.scm - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', }, }, move = { enable = true, set_jumps = true, -- whether to set jumps in the jumplist goto_next_start = { - ["]]"] = "@function.outer", + [']]'] = '@function.outer', }, goto_next_end = { - ["]["] = "@function.outer", + [']['] = '@function.outer', }, goto_previous_start = { - ["[["] = "@function.outer", + ['[['] = '@function.outer', }, goto_previous_end = { - ["[]"] = "@function.outer", + ['[]'] = '@function.outer', }, }, }, diff --git a/lua/go/ts/utils.lua b/lua/go/ts/utils.lua index 72bc2efd4..20f83c75b 100644 --- a/lua/go/ts/utils.lua +++ b/lua/go/ts/utils.lua @@ -1,9 +1,14 @@ local api = vim.api local get_node_text = vim.treesitter.get_node_text -local ts_utils = require('guihua.ts_obsolete.ts_utils') -local locals = require('guihua.ts_obsolete.locals') +if _GO_NVIM_CFG.treesitter_main then + local ts_utils = require('guihua.ts_obsolete.ts_utils') + local locals = require('guihua.ts_obsolete.locals') +else + local ts_utils = require('nvim-treesitter.ts_utils') + local locals = require('nvim-treesitter.locals') +end local util = require('go.utils') local log = util.log local trace = util.trace From 4997a920f81be1aa29dbac79f87178c5d7f1c478 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 9 Nov 2025 13:18:56 +1100 Subject: [PATCH 09/47] health for treesitter main branch --- lua/go/health.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lua/go/health.lua b/lua/go/health.lua index a26653c9f..634658e14 100644 --- a/lua/go/health.lua +++ b/lua/go/health.lua @@ -148,12 +148,18 @@ local function plugin_check() end end if ts_installed then - local _info = require('nvim-treesitter.info').installed_parsers() - if vim.tbl_contains(_info, 'go') then - ok('nvim-treesitter-go is installed') + local has_ts_main = pcall(require, 'nvim-treesitter.config') + if has_ts_main then + any_warn = false + warn('nvim-treesitter main module loaded, WIP') else - warn('nvim-treesitter-go is not installed, Please run TSInstall go to install') - any_warn = true + local _info = require('nvim-treesitter.info').installed_parsers() + if vim.tbl_contains(_info, 'go') then + ok('nvim-treesitter-go is installed') + else + warn('nvim-treesitter-go is not installed, Please run TSInstall go to install') + any_warn = true + end end end plugins = { From aaa85c72cb0f4652e5075438e7a041c639ca62cd Mon Sep 17 00:00:00 2001 From: ray-x Date: Mon, 10 Nov 2025 11:01:28 +1100 Subject: [PATCH 10/47] ginkgo fix for treesitter-main --- lua/go.lua | 5 +++++ lua/go/ginkgo.lua | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/go.lua b/lua/go.lua index 07cd8de2c..32c52e26a 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -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 @@ -212,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) diff --git a/lua/go/ginkgo.lua b/lua/go/ginkgo.lua index 413457086..6a44bb3a2 100644 --- a/lua/go/ginkgo.lua +++ b/lua/go/ginkgo.lua @@ -12,7 +12,13 @@ local long_opts = { floaterm = 'F', } local ts = vim.treesitter -local parsers = require('nvim-treesitter.parsers') + +local parsers +if _GO_NVIM_CFG.treesitter_main then + parsers = require('guihua.ts_obsolete.parsers') +else + parsers = require('nvim-treesitter.parsers') +end local getopt = require('go.alt_getopt') local short_opts = 'vct:bsF' From 802619603a499a0289f73f67b266f2325303d1f6 Mon Sep 17 00:00:00 2001 From: ray-x Date: Mon, 10 Nov 2025 21:11:13 +1100 Subject: [PATCH 11/47] update sandbox init.lua --- playground/init_lazy.lua | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/playground/init_lazy.lua b/playground/init_lazy.lua index a9cf1b0a8..267359d09 100644 --- a/playground/init_lazy.lua +++ b/playground/init_lazy.lua @@ -2,7 +2,7 @@ -- change the slash to backslash in PATH for Windows vim.cmd([[set runtimepath=$VIMRUNTIME]]) local tmpdir = vim.loop.os_tmpdir() .. '/nvim' -packpath = tmpdir .. '/lazy' +local packpath = tmpdir .. '/lazy' vim.cmd([[set packpath=]] .. packpath) -- print(packpath) @@ -32,35 +32,36 @@ local function load_plugins() return { { 'nvim-treesitter/nvim-treesitter', + lazy = false, + branch = 'main', + build = ':TSUpdate', config = function() - require('nvim-treesitter.configs').setup({ - ensure_installed = { 'go' }, - highlight = { enable = true }, + require('nvim-treesitter').setup({ + -- Directory to install parsers and queries to + install_dir = vim.fn.stdpath('data') .. '/site', }) + require('nvim-treesitter').install({ 'go' }):wait(3000) end, - build = ':TSUpdate', }, { 'neovim/nvim-lspconfig' }, { 'ray-x/go.nvim', dev = (plugin_folder() ~= ''), - -- dev = true, ft = { 'go', 'gomod', 'gosum', 'gotmpl', 'gohtmltmpl', 'gotexttmpl' }, dependencies = { 'mfussenegger/nvim-dap', -- Debug Adapter Protocol 'rcarriga/nvim-dap-ui', - 'nvim-neotest/nvim-nio', 'theHamsta/nvim-dap-virtual-text', 'ray-x/guihua.lua', }, config = true, opts = { verbose = true, - -- log_path = '~/tmp/go.log', + -- log_path = '~/tmp/gonvim.log', lsp_cfg = true, goimports = 'gopls', gofmt = 'gopls', - max_line_len = 80, + max_line_len = 120, }, }, } @@ -76,3 +77,10 @@ local opts = { } require('lazy').setup(load_plugins(), opts) + +vim.api.nvim_create_autocmd('FileType', { + pattern = { 'go' }, + callback = function() + vim.treesitter.start() + end, +}) From a20e4477fc50fe3e4a97a62215d3f56f6554e2bb Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 12:29:19 +1100 Subject: [PATCH 12/47] format updates --- lua/go/runner.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lua/go/runner.lua b/lua/go/runner.lua index 7978e2c41..c86f3e103 100644 --- a/lua/go/runner.lua +++ b/lua/go/runner.lua @@ -61,11 +61,11 @@ local run = function(cmd, opts, uvopts) end log(locopts) if opts.setloclist ~= false then - vim.schedule(function() - vim.fn.setloclist(0, {}, 'a', locopts) - vim.notify('run lopen to see output', vim.log.levels.INFO) - end) - end + vim.schedule(function() + vim.fn.setloclist(0, {}, 'a', locopts) + vim.notify('run lopen to see output', vim.log.levels.INFO) + end) + end end return lines end @@ -135,11 +135,7 @@ local run = function(cmd, opts, uvopts) log('failed to run', code, output_buf, output_stderr) vim.schedule(function() util.info( - cmd_str - .. ' exit with code: ' - .. tostring(code or 0) - .. (output_buf or '') - .. (output_stderr or '') + cmd_str .. ' exit with code: ' .. tostring(code or 0) .. (output_buf or '') .. (output_stderr or '') ) end) end From 465998188add457c04b290904442fb7f876228ad Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 12:32:47 +1100 Subject: [PATCH 13/47] remove neovim 0.10.4 in test --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aff2d1d0d..53c71ef36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 From 49e5c8f33e68e2c381d00b0e4a741c134b928e7b Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 12:37:24 +1100 Subject: [PATCH 14/47] fix diagnostic --- lua/go.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/go.lua b/lua/go.lua index 32c52e26a..00eec955d 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -285,8 +285,10 @@ function go.setup(cfg) end else -- vim.notify('go.nvim diagnostic setup deprecated, use vim.diagnostic instead', vim.log.levels.DEBUG) - local dcfg = vim.tbl_extend('force', {}, _GO_NVIM_CFG.diagnostic) - vim.diagnostic.config(dcfg) + 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() From a3d04d5f69509f2cb37b724470db9d90ae9485af Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 13:26:30 +1100 Subject: [PATCH 15/47] more treesitter fixs --- lua/go/comment.lua | 46 +++++++++++++++++++++++-------------------- lua/go/fixplurals.lua | 26 +++++++++++++----------- lua/go/impl.lua | 5 +---- lua/go/mockgen.lua | 1 - lua/go/snips.lua | 29 +++++++++++---------------- lua/go/ts/go.lua | 12 +++++------ lua/go/ts/utils.lua | 10 +++++----- 7 files changed, 61 insertions(+), 68 deletions(-) diff --git a/lua/go/comment.lua b/lua/go/comment.lua index 831e87828..36f93f184 100644 --- a/lua/go/comment.lua +++ b/lua/go/comment.lua @@ -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 @@ -55,14 +60,13 @@ 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) @@ -70,14 +74,14 @@ comment.gen = function() 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 diff --git a/lua/go/fixplurals.lua b/lua/go/fixplurals.lua index b959a41e5..f06da2d0d 100644 --- a/lua/go/fixplurals.lua +++ b/lua/go/fixplurals.lua @@ -1,33 +1,35 @@ -- lua implementation of the fixplurals -local ts_utils = require("nvim-treesitter.ts_utils") - -local info = require("go.utils").info +local ok, ts_utils = pcall(require, 'nvim-treesitter.ts_utils') +if not ok then + ts_utils = require('guihua.ts_obsolete.ts_utils') +end +local info = require('go.utils').info local get_node_text = vim.treesitter.get_node_text local function fixplurals() local n = ts_utils.get_node_at_cursor() if not n then - return info("no node found") + return info('no node found') end local p = n:parent() - if p:type() ~= "parameter_declaration" then - return info("not in parameter declaration") + if p:type() ~= 'parameter_declaration' then + return info('not in parameter declaration') end if p:named_child_count() ~= 2 then - return info("no plural parameter") + return info('no plural parameter') end local type_node = p:named_child(1) local type = get_node_text(type_node, 0) local edits = {} while ts_utils.get_next_node(p) ~= nil do local next_node = ts_utils.get_next_node(p) - if next_node:type() == "parameter_declaration" then + if next_node:type() == 'parameter_declaration' then local type_node2 = next_node:named_child(1) local type_next = get_node_text(type_node2, 0) if type == type_next then local range1 = ts_utils.node_to_lsp_range(p:named_child(1)) - range1["start"]["character"] = range1["start"]["character"] - 1 - local edit1 = { range = range1, newText = "" } + range1['start']['character'] = range1['start']['character'] - 1 + local edit1 = { range = range1, newText = '' } table.insert(edits, 1, edit1) end @@ -38,9 +40,9 @@ local function fixplurals() end if #edits == 0 then - return info("no plural parameter") + return info('no plural parameter') end local bufnr = vim.api.nvim_get_current_buf() - vim.lsp.util.apply_text_edits(edits, bufnr, "utf-8") + vim.lsp.util.apply_text_edits(edits, bufnr, 'utf-8') end return { fixplurals = fixplurals } diff --git a/lua/go/impl.lua b/lua/go/impl.lua index cf3ef4e12..7761e7c17 100644 --- a/lua/go/impl.lua +++ b/lua/go/impl.lua @@ -1,4 +1,3 @@ --- local ts_utils = require 'nvim-treesitter.ts_utils' local utils = require('go.utils') local log = utils.log local vfn = vim.fn @@ -61,9 +60,7 @@ local run = function(...) end vim.cmd('redraw!') if iface == '' then - utils.notify( - 'Impl: please input interface name e.g. io.Reader or receiver name e.g. GoImpl MyType' - ) + utils.notify('Impl: please input interface name e.g. io.Reader or receiver name e.g. GoImpl MyType') -- print("Usage: GoImpl f *File io.Reader") end elseif #arg == 1 then -- at least interface or type are specified diff --git a/lua/go/mockgen.lua b/lua/go/mockgen.lua index b4d806551..686a362e2 100644 --- a/lua/go/mockgen.lua +++ b/lua/go/mockgen.lua @@ -1,4 +1,3 @@ --- local ts_utils = require 'nvim-treesitter.ts_utils' local utils = require('go.utils') local log = utils.log local vfn = vim.fn diff --git a/lua/go/snips.lua b/lua/go/snips.lua index 42becb0c9..b592e051f 100644 --- a/lua/go/snips.lua +++ b/lua/go/snips.lua @@ -1,22 +1,14 @@ -- first version: from https://github.com/arsham/shark local ls = require('luasnip') local fmt = require('luasnip.extras.fmt').fmt +local ts_locals local ok, ts_utils = pcall(require, 'nvim-treesitter.ts_utils') if not ok then - local ok, packer = pcall(require, 'packer') - if ok then - require('packer').loader('nvim-treesitter') - else - local ok, lazy = pcall(require, 'lazy') - if lazy then - lazy.load({ plugins = { 'nvim-treesitter' } }) - else - error('Please install nvim-treesitter') - end - end - ts_utils = require('nvim-treesitter.ts_utils') + ts_utils = require('guihua.ts_obsolete.ts_utils') + ts_locals = require('guihua.ts_obsolete.locals') +else + ts_locals = require('nvim-treesitter.locals') end -local ts_locals = require('nvim-treesitter.locals') local rep = require('luasnip.extras').rep local ai = require('luasnip.nodes.absolute_indexer') @@ -25,7 +17,7 @@ local M = {} M.go_err_snippet = function(args, _, _, spec) local err_name = args[1][1] local index = spec and spec.index or nil - local msg = spec and spec[1] or "" + local msg = spec and spec[1] or '' if spec and spec[2] then err_name = err_name .. spec[2] end @@ -158,10 +150,11 @@ local function return_value_nodes(info) local function_node for _, scope in ipairs(scope_tree) do - if scope:type() == 'function_declaration' - or scope:type() == 'method_declaration' - or scope:type() == 'method_declaration' - or scope:type() == 'func_literal' + if + scope:type() == 'function_declaration' + or scope:type() == 'method_declaration' + or scope:type() == 'method_declaration' + or scope:type() == 'func_literal' then function_node = scope break diff --git a/lua/go/ts/go.lua b/lua/go/ts/go.lua index 0c7119070..0dc9c6591 100644 --- a/lua/go/ts/go.lua +++ b/lua/go/ts/go.lua @@ -1,11 +1,5 @@ local nodes = require('go.ts.nodes') -if _GO_NVIM_CFG.treesitter_main then - local tsutil = require('guihua.ts_obsolete.ts_utils') -else - local tsutil = require('nvim-treesitter.ts_utils') -end - local log = require('go.utils').log local warn = require('go.utils').warn local info = require('go.utils').info @@ -423,7 +417,11 @@ end function M.in_func() local ok, ts_utils = pcall(require, 'nvim-treesitter.ts_utils') if not ok then - return false + ok, ts_utils = pcall(require, 'guihua.ts_obsolete.ts_utils') + if not ok then + warn('ts_utils not found') + return false + end end local current_node = ts_utils.get_node_at_cursor() if not current_node then diff --git a/lua/go/ts/utils.lua b/lua/go/ts/utils.lua index 20f83c75b..5ded4cacd 100644 --- a/lua/go/ts/utils.lua +++ b/lua/go/ts/utils.lua @@ -1,13 +1,13 @@ local api = vim.api local get_node_text = vim.treesitter.get_node_text - +local ts_utils, locals if _GO_NVIM_CFG.treesitter_main then - local ts_utils = require('guihua.ts_obsolete.ts_utils') - local locals = require('guihua.ts_obsolete.locals') + ts_utils = require('guihua.ts_obsolete.ts_utils') + locals = require('guihua.ts_obsolete.locals') else - local ts_utils = require('nvim-treesitter.ts_utils') - local locals = require('nvim-treesitter.locals') + ts_utils = require('nvim-treesitter.ts_utils') + locals = require('nvim-treesitter.locals') end local util = require('go.utils') local log = util.log From 64d394522c88ce3522e11c8c0a5f60c1e38a62da Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 13:55:42 +1100 Subject: [PATCH 16/47] use minimal lua --- .github/workflows/ci.yml | 2 +- lua/tests/minimal.lua | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 lua/tests/minimal.lua diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53c71ef36..5f3a2d11e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,5 +53,5 @@ jobs: - 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 "TSInstallSync go" -c "q" make test diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua new file mode 100644 index 000000000..a4ab55342 --- /dev/null +++ b/lua/tests/minimal.lua @@ -0,0 +1,48 @@ +vim.opt.rtp:append('.') +vim.opt.rtp:append('../plenary.nvim/') +vim.opt.rtp:append('../nvim-treesitter') +vim.opt.rtp:append('../nvim-lspconfig/') +vim.opt.rtp:append('../guihua.lua/') + +vim.cmd([[ + runtime! plugin/plenary.vim + runtime! plugin/nvim-treesitter.vim + runtime! plugin/playground.vim + runtime! plugin/nvim-lspconfig.vim + runtime! plugin/guihua.lua +]]) + +vim.opt.swapfile = false -- no swapfile +vim.opt.backup = false -- no backup +vim.opt.writebackup = false -- no writebackup + +vim.cmd('filetype indent off') +vim.opt.autoindent = false +vim.opt.cindent = false +vim.opt.smartindent = false +vim.opt.indentexpr = '' -- clear any indentexpr + +require('plenary.busted') + +require('go').setup({ + debug = true, + verbose = true, + gofmt = 'gofumpt', + goimports = 'goimports', + log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', + lsp_cfg = true, +}) +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() + vim.treesitter.start() + end, +}) + +vim.cmd([[set completeopt+=menuone,noselect,popup]]) +vim.lsp.enable('gopls') From 0341ec3fac42b857b0ee069e3643c323b7f4e230 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 14:29:53 +1100 Subject: [PATCH 17/47] move test and treesitter fix --- lua/go/ginkgo.lua | 2 +- lua/go/ts/go.lua | 8 ++++++++ lua/go/ts/nodes.lua | 11 ++++++----- lua/go/ts/utils.lua | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lua/go/ginkgo.lua b/lua/go/ginkgo.lua index 6a44bb3a2..2fad60321 100644 --- a/lua/go/ginkgo.lua +++ b/lua/go/ginkgo.lua @@ -50,7 +50,7 @@ local function find_nearest_test_case() local query = require('go.ts.go').ginkgo_query local bufnr = vim.api.nvim_get_current_buf() - local parser = parsers.get_parser(bufnr, 'go') + local parser = vim.treesitter.get_parser(bufnr, 'go') if not parser then log('no parser found') return diff --git a/lua/go/ts/go.lua b/lua/go/ts/go.lua index 0dc9c6591..e6c0da8af 100644 --- a/lua/go/ts/go.lua +++ b/lua/go/ts/go.lua @@ -360,6 +360,14 @@ end M.get_import_node_at_pos = function(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf() + local ok, tsutil = pcall(require, 'nvim-treesitter.ts_utils') + if not ok then + ok, tsutil = pcall(require, 'guihua.ts_obsolete.ts_utils') + if not ok then + warn('ts_utils not found') + return + end + end local cur_node = tsutil.get_node_at_cursor(0, true) if not cur_node then vim.notify('cursor not in a node or TS parser not init correctly', vim.log.levels.INFO) diff --git a/lua/go/ts/nodes.lua b/lua/go/ts/nodes.lua index 13c17e8ad..5b1188fe6 100644 --- a/lua/go/ts/nodes.lua +++ b/lua/go/ts/nodes.lua @@ -1,7 +1,8 @@ -- part of the code from polarmutex/contextprint.nvim +local has_ts_main = pcall(require, 'nvim-treesitter.config') local ts_utils, ts_query, locals, parsers -if _GO_NVIM_CFG.treesitter_main then +if has_ts_main then ts_utils = require('guihua.ts_obsolete.ts_utils') ts_query = require('guihua.ts_obsolete.query') locals = require('guihua.ts_obsolete.locals') @@ -26,7 +27,7 @@ if parse == nil then parse = vim.treesitter.query.parse_query end -if not _GO_NVIM_CFG.verbose_ts then +if _GO_NVIM_CFG and not _GO_NVIM_CFG.verbose_ts then ulog = function() end end @@ -88,7 +89,7 @@ M.get_nodes = function(query, lang, defaults, bufnr) return nil end - local parser = parsers.get_parser(bufnr, lang) + local parser = vim.treesitter.get_parser(bufnr, lang) local root = parser:parse()[1]:root() local start_row, _, end_row, _ = root:range() local results = {} @@ -158,7 +159,7 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype return nil end - local parser = parsers.get_parser(bufnr, lang) + local parser = vim.treesitter.get_parser(bufnr, lang) local root = parser:parse()[1]:root() local start_row, _, end_row, _ = root:range() local results = {} @@ -185,7 +186,7 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype if #dbg_txt > 100 then dbg_txt = string.sub(dbg_txt, 1, 100) .. '...' end - type = string.sub(path, 1, idx - 1) -- e.g. struct.name, type is struct + type = string.sub(path, 1, idx - 1) -- e.g. struct.name, type is struct if type:find('type') and op == 'type' then -- type_declaration.type node_type = get_node_text(node, bufnr) ulog('type: ' .. type) diff --git a/lua/go/ts/utils.lua b/lua/go/ts/utils.lua index 5ded4cacd..21fcb242e 100644 --- a/lua/go/ts/utils.lua +++ b/lua/go/ts/utils.lua @@ -2,7 +2,8 @@ local api = vim.api local get_node_text = vim.treesitter.get_node_text local ts_utils, locals -if _GO_NVIM_CFG.treesitter_main then +local has_ts_main = pcall(require, 'nvim-treesitter.config') +if has_ts_main then ts_utils = require('guihua.ts_obsolete.ts_utils') locals = require('guihua.ts_obsolete.locals') else From 7c1daaa40ac11da7fb158095b60ff6c9451108fd Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 14:33:01 +1100 Subject: [PATCH 18/47] Change Makefile with lua config --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ed9730441..d433104c5 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ 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" 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" lint: luacheck lua/go clean: From 93354202900dff16111adcaa9a81bda9cd30ad2f Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 14:43:15 +1100 Subject: [PATCH 19/47] update test lua config --- lua/tests/init.lua | 59 +++++++++++++++++++++++++++++++++++++++++++ lua/tests/minimal.lua | 5 ++-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 lua/tests/init.lua diff --git a/lua/tests/init.lua b/lua/tests/init.lua new file mode 100644 index 000000000..3123f16a6 --- /dev/null +++ b/lua/tests/init.lua @@ -0,0 +1,59 @@ +-- 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('.') + +vim.opt.rtp:prepend(plugin_dir .. '/plenary.nvim') +vim.opt.rtp:prepend(plugin_dir .. '/nvim-treesitter') +vim.opt.rtp:prepend(plugin_dir .. '/nvim-lspconfig') + +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', +}) + +require('nvim-treesitter').install({ 'go' }):wait(10000) -- wait max. 5 minutes + +vim.api.nvim_create_autocmd('FileType', { + pattern = { 'go' }, + callback = function() + vim.treesitter.start() + end, +}) diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index a4ab55342..97e079560 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -12,8 +12,8 @@ vim.cmd([[ runtime! plugin/guihua.lua ]]) -vim.opt.swapfile = false -- no swapfile -vim.opt.backup = false -- no backup +vim.opt.swapfile = false -- no swapfile +vim.opt.backup = false -- no backup vim.opt.writebackup = false -- no writebackup vim.cmd('filetype indent off') @@ -37,6 +37,7 @@ require('nvim-treesitter').setup({ install_dir = vim.fn.stdpath('data') .. '/site', }) +require('nvim-treesitter').install({ 'go' }):wait(20000) vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() From a532ea875b9ba847797c119455a2308e1425caac Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 14:52:38 +1100 Subject: [PATCH 20/47] update pipeline --- .github/workflows/ci.yml | 2 +- lua/tests/go_fixplurals_spec.lua | 6 ++---- lua/tests/go_ts_node_spec.lua | 14 ++++++-------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f3a2d11e..8bfb88282 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,5 +53,5 @@ jobs: - name: Run tests run: | export PATH="${PWD}/_neovim/bin:${PATH}" - nvim --headless -u lua/tests/minimal.lua -i NONE -c "TSInstallSync go" -c "q" + nvim --headless -u lua/tests/minimal.lua -i NONE -c "TSInstall go" -c "q" make test diff --git a/lua/tests/go_fixplurals_spec.lua b/lua/tests/go_fixplurals_spec.lua index b839356da..a8ca726c8 100644 --- a/lua/tests/go_fixplurals_spec.lua +++ b/lua/tests/go_fixplurals_spec.lua @@ -16,16 +16,14 @@ describe('should run fixplurals', function() local path = cur_dir .. '/lua/tests/fixtures/fixplurals/fixp_input.go' -- %:p:h ? %:p local lines = vim.fn.readfile(path) vim.fn.writefile(lines, name) - local expected = - vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fixplurals/fixp_golden.go'), '\n') + local expected = vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fixplurals/fixp_golden.go'), '\n') local cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) local bufn = vim.fn.bufnr('') vim.treesitter.stop() vim.treesitter.start() - local parsers = require "nvim-treesitter.parsers" - local root_lang_tree = parsers.get_parser(bufn, 'go') + local root_lang_tree = vim.treesitter.get_parser(bufn, 'go') -- read current line root_lang_tree:parse() diff --git a/lua/tests/go_ts_node_spec.lua b/lua/tests/go_ts_node_spec.lua index ca47b2241..950dd5caf 100644 --- a/lua/tests/go_ts_node_spec.lua +++ b/lua/tests/go_ts_node_spec.lua @@ -43,7 +43,7 @@ describe('should get nodes ', function() require('plenary.reload').reload_module('go.nvim') require('plenary.reload').reload_module('nvim-treesitter/nvim-treesitter') - _GO_NVIM_CFG.verbose = true + -- _GO_NVIM_CFG.verbose = true local nodes = require('go.ts.nodes') it('get all nodes should get struct x', function() @@ -54,8 +54,7 @@ describe('should get nodes ', function() end) it('it should get struct y', function() vim.fn.setpos('.', { bufn, 8, 1, 0 }) - local query = require('go.ts.go').query_struct_block - .. require('go.ts.go').query_em_struct_block + local query = require('go.ts.go').query_struct_block .. require('go.ts.go').query_em_struct_block -- local query = require('go.ts.go').query_em_struct local ns = nodes.get_all_nodes(query, 'go', default, bufn) eq('y', ns[2].name) @@ -69,8 +68,7 @@ describe('should get nodes ', function() end) it('it should get struct y', function() vim.fn.setpos('.', { bufn, 8, 1, 0 }) - local query = require('go.ts.go').query_struct_block - .. require('go.ts.go').query_em_struct_block + local query = require('go.ts.go').query_struct_block .. require('go.ts.go').query_em_struct_block -- local query = require('go.ts.go').query_em_struct local ns = nodes.nodes_at_cursor(query, default, bufn) eq('y', ns[#ns].name) @@ -98,7 +96,7 @@ describe('should get nodes for play list ', function() local bufn = vim.fn.bufnr('') - _GO_NVIM_CFG.verbose = true + -- _GO_NVIM_CFG.verbose = true local nodes = require('go.ts.nodes') it('should get function name', function() vim.fn.setpos('.', { bufn, 21, 5, 0 }) @@ -178,8 +176,8 @@ describe('should get nodes for import golden ', function() vim.treesitter.stop() vim.treesitter.start() local buf = vim.api.nvim_win_get_buf(0) - local parsers = require "nvim-treesitter.parsers" - local root_lang_tree = parsers.get_parser(buf, 'go') + + local root_lang_tree = vim.treesitter.get_parser(buf, 'go') -- read current line print('current line', vim.api.nvim_get_current_line(), vim.o.filetype, buf) From a383fe6df3a67430a26715195b9f6e6fa71d4276 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 15:18:14 +1100 Subject: [PATCH 21/47] update test pipeline --- Makefile | 19 +++++++++++++++---- lua/go.lua | 4 ++++ lua/go/tags.lua | 4 ++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d433104c5..fe4647bec 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,19 @@ localtest: localtestsetup 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.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.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: @@ -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" diff --git a/lua/go.lua b/lua/go.lua index 00eec955d..65793ebc9 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -344,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 diff --git a/lua/go/tags.lua b/lua/go/tags.lua index 27b7bc01f..0595f9b7b 100644 --- a/lua/go/tags.lua +++ b/lua/go/tags.lua @@ -11,8 +11,8 @@ local tags = {} -- gomodifytags -file demo.go -line 8,11 -clear-tags xml local gomodify = 'gomodifytags' -local transform = _GO_NVIM_CFG.tag_transform -local options = _GO_NVIM_CFG.tag_options +local transform = require('go').config().tag_transform +local options = require('go').config().tag_options tags.modify = function(...) require('go.install').install(gomodify) From 6becdf798f42e0521a741a3689a6debddf9bab8d Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 18:01:41 +1100 Subject: [PATCH 22/47] fix log path in tests --- lua/tests/go_hover_spec.lua | 13 ++++++------- lua/tests/go_make_spec.lua | 8 ++++---- lua/tests/init.lua | 4 +--- lua/tests/minimal.lua | 8 ++++---- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lua/tests/go_hover_spec.lua b/lua/tests/go_hover_spec.lua index 2260d802a..42a40ce65 100644 --- a/lua/tests/go_hover_spec.lua +++ b/lua/tests/go_hover_spec.lua @@ -29,21 +29,21 @@ describe('regex should work', function() local str = [[func Println(a ...any) (n int, err error)]] local ret = require('go.lsp').find_ret(str) print(vim.inspect(ret)) - eq({'n', 'err'}, ret) + eq({ 'n', 'err' }, ret) end) it('should find return', function() local str = [[func fmt.Println(a ...any) (int, error)]] local ret, e = require('go.lsp').find_ret(str) print(vim.inspect(ret)) - eq({'i', 'err'}, ret) + eq({ 'i', 'err' }, ret) eq(true, e) end) it('should find return', function() local str = [[func fmt.Println(a, b int) (int, error)]] local ret, e = require('go.lsp').find_ret(str) print(vim.inspect(ret)) - eq({'i', 'err'}, ret) + eq({ 'i', 'err' }, ret) eq(true, e) end) @@ -51,7 +51,7 @@ describe('regex should work', function() local str = [[func fmt.Println(a, b int) int]] local ret, e = require('go.lsp').find_ret(str) print(vim.inspect(ret)) - eq({'i'}, ret) + eq({ 'i' }, ret) eq(false, e) end) @@ -59,7 +59,7 @@ describe('regex should work', function() local str = [[func fmt.Println(a, b int) MyType]] local ret, e = require('go.lsp').find_ret(str) print(vim.inspect(ret)) - eq({'myType'}, ret) + eq({ 'myType' }, ret) eq(false, e) end) @@ -67,7 +67,7 @@ describe('regex should work', function() local str = [[func fmt.Println(a, b int) (MyType, error)]] local ret, e = require('go.lsp').find_ret(str) print(vim.inspect(ret)) - eq({'myType', 'err'}, ret) + eq({ 'myType', 'err' }, ret) eq(true, e) end) end) @@ -86,6 +86,5 @@ describe('should run hover', function() local ret = require('go.lsp').gen_return(result) print(vim.inspect(ret)) - end) end) diff --git a/lua/tests/go_make_spec.lua b/lua/tests/go_make_spec.lua index 9f82ab83d..7d3fcb71c 100644 --- a/lua/tests/go_make_spec.lua +++ b/lua/tests/go_make_spec.lua @@ -16,9 +16,9 @@ describe('should run func make', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', }) - vim.cmd("silent cd " .. path) + 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') @@ -36,10 +36,10 @@ describe('should run func make', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', }) - vim.cmd("silent cd " .. path) + 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') diff --git a/lua/tests/init.lua b/lua/tests/init.lua index 3123f16a6..715fa6ea7 100644 --- a/lua/tests/init.lua +++ b/lua/tests/init.lua @@ -38,7 +38,7 @@ require('go').setup({ gofmt = 'gofumpt', goimports = 'goimports', verbose = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', lsp_cfg = true, }) @@ -49,8 +49,6 @@ require('nvim-treesitter').setup({ install_dir = vim.fn.stdpath('data') .. '/site', }) -require('nvim-treesitter').install({ 'go' }):wait(10000) -- wait max. 5 minutes - vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index 97e079560..4b9b21970 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -12,8 +12,8 @@ vim.cmd([[ runtime! plugin/guihua.lua ]]) -vim.opt.swapfile = false -- no swapfile -vim.opt.backup = false -- no backup +vim.opt.swapfile = false -- no swapfile +vim.opt.backup = false -- no backup vim.opt.writebackup = false -- no writebackup vim.cmd('filetype indent off') @@ -29,7 +29,7 @@ require('go').setup({ verbose = true, gofmt = 'gofumpt', goimports = 'goimports', - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', lsp_cfg = true, }) require('nvim-treesitter').setup({ @@ -37,7 +37,7 @@ require('nvim-treesitter').setup({ install_dir = vim.fn.stdpath('data') .. '/site', }) -require('nvim-treesitter').install({ 'go' }):wait(20000) +require('nvim-treesitter').install({ 'go' }):wait(60000) vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() From 1d88a7682d249327c761ba57831570d87aa79d1d Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 18:10:14 +1100 Subject: [PATCH 23/47] fix log_path warning in tests --- lua/tests/go_coverage_spec.lua | 57 +++++++++++++++++----------------- lua/tests/go_hover_spec.lua | 2 +- lua/tests/go_test_spec.lua | 16 +--------- lua/tests/go_utils_spec.lua | 1 - 4 files changed, 31 insertions(+), 45 deletions(-) diff --git a/lua/tests/go_coverage_spec.lua b/lua/tests/go_coverage_spec.lua index 297dada84..9e5bf8fb6 100644 --- a/lua/tests/go_coverage_spec.lua +++ b/lua/tests/go_coverage_spec.lua @@ -1,71 +1,72 @@ 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 read coveragefile", function() +describe('should read coveragefile', function() -- vim.fn.readfile('minimal.vim') -- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) - local status = require("plenary.reload").reload_module("go.nvim") - it("should read coverage file", function() + local status = require('plenary.reload').reload_module('go.nvim') + it('should read coverage file', function() -- - local path = cur_dir .. "/lua/tests/fixtures/coverage/coverage.out" -- %:p:h ? %:p - print("test:" .. path) + local path = cur_dir .. '/lua/tests/fixtures/coverage/coverage.out' -- %:p:h ? %:p + print('test:' .. path) -- go.nvim may not auto loaded vim.cmd([[packadd go.nvim]]) require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log" + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', }) - local cover = require("go.coverage") + local cover = require('go.coverage') local result = cover.read_cov(path) -- print(vim.inspect(result)) - local n = "branch.go" - local range = {['end'] = {character = 13, line = 4}, start = {character = 27, line = 3}} + local n = 'branch.go' + local range = { ['end'] = { character = 13, line = 4 }, start = { character = 27, line = 3 } } - eq(result[n][1].file, "github.com/go.nvim/branch.go") + eq(result[n][1].file, 'github.com/go.nvim/branch.go') eq(result[n][1].range, range) eq(result[n].file_lines, 9) eq(result[n].file_covered, 4) - range = {['end'] = {character = 13, line = 11}, start = {character = 2, line = 11}} + range = { ['end'] = { character = 13, line = 11 }, start = { character = 2, line = 11 } } eq(result[n][3].range, range) eq(result.total_lines, 9) eq(result.total_covered, 4) -- eq(result[n][1], "github.com/go.nvim/branch.go") end) - it("should generate sign list", function() + it('should generate sign list', function() -- - local path = cur_dir .. "/lua/tests/fixtures/coverage/coverage.out" -- %:p:h ? %:p - print("test:" .. path) + local path = cur_dir .. '/lua/tests/fixtures/coverage/coverage.out' -- %:p:h ? %:p + print('test:' .. path) -- go.nvim may not auto loaded vim.cmd([[packadd go.nvim]]) require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log", - gocoverage_sign = '|' + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', + gocoverage_sign = '|', }) - local cover = require("go.coverage") + local cover = require('go.coverage') cover.highlight() local coverage = { { covered = 1, - file = "github.com/go.nvim/branch.go", - filename = "branch.go", + file = 'github.com/go.nvim/branch.go', + filename = 'branch.go', num = 1, - range = {['end'] = {character = 13, line = 4}, start = {character = 27, line = 3}} - }, { + range = { ['end'] = { character = 13, line = 4 }, start = { character = 27, line = 3 } }, + }, + { covered = 1, - file = "github.com/go.nvim/branch.go", - filename = "branch.go", + file = 'github.com/go.nvim/branch.go', + filename = 'branch.go', num = 1, - range = {['end'] = {character = 13, line = 7}, start = {character = 2, line = 7}} - } + range = { ['end'] = { character = 13, line = 7 }, start = { character = 2, line = 7 } }, + }, } local result = cover.add(1, coverage) @@ -76,7 +77,7 @@ describe("should read coveragefile", function() id = 3, lnum = 3, name = 'goCoverageCovered', - priority = 7 + priority = 7, } eq(result[1], sign) -- eq(result[n][1], "github.com/go.nvim/branch.go") diff --git a/lua/tests/go_hover_spec.lua b/lua/tests/go_hover_spec.lua index 42a40ce65..7e5f7380a 100644 --- a/lua/tests/go_hover_spec.lua +++ b/lua/tests/go_hover_spec.lua @@ -21,7 +21,7 @@ describe('regex should work', function() require('go').setup({ trace = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', }) print(vim.fn.expand('$HOME') .. '/tmp/gonvim.log') diff --git a/lua/tests/go_test_spec.lua b/lua/tests/go_test_spec.lua index 6a052ca14..6de0059b1 100644 --- a/lua/tests/go_test_spec.lua +++ b/lua/tests/go_test_spec.lua @@ -22,8 +22,8 @@ describe('should run func test', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', test_runner = 'go', + log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -38,7 +38,6 @@ describe('should run func test', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', test_runner = 'go', }) @@ -55,7 +54,6 @@ describe('should run func test', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', test_runner = 'go', }) vim.cmd('cd ' .. godir) @@ -77,7 +75,6 @@ describe('should run func test', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', test_runner = 'go', }) vim.cmd('cd ' .. godir) @@ -101,7 +98,6 @@ describe('should run func test', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', test_runner = 'go', }) vim.cmd('cd ' .. godir) @@ -130,7 +126,6 @@ describe('should run func test', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', test_runner = 'go', }) vim.cmd('cd ' .. godir) @@ -172,7 +167,6 @@ describe('should run test file', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', test_runner = 'go', }) vim.cmd('cd ' .. godir) @@ -208,7 +202,6 @@ describe('should run test file with flags', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -245,7 +238,6 @@ describe('should run test package: ', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -290,7 +282,6 @@ describe('should allow select test func: ', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -312,7 +303,6 @@ describe('should run test file with flags inside file: ', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -349,7 +339,6 @@ describe('should run subcase tests: ', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -364,7 +353,6 @@ describe('should run subcase tests: ', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -378,7 +366,6 @@ describe('should run subcase tests: ', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") @@ -392,7 +379,6 @@ describe('should run subcase tests: ', function() require('go').setup({ trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) vim.cmd('cd ' .. godir) vim.cmd("silent exe 'e " .. path .. "'") diff --git a/lua/tests/go_utils_spec.lua b/lua/tests/go_utils_spec.lua index a2ac11fc3..2199d3fd6 100644 --- a/lua/tests/go_utils_spec.lua +++ b/lua/tests/go_utils_spec.lua @@ -9,7 +9,6 @@ describe('should get file name and number ', function() verbose = true, trace = true, lsp_cfg = true, - log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log', }) local utils = require('go.utils') From 6853bca17a5105fea38e95ee1609b9821ed6eca2 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 22:36:50 +1100 Subject: [PATCH 24/47] a few fix for treesitter --- lua/tests/minimal.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index 4b9b21970..a9b49adae 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -36,12 +36,13 @@ require('nvim-treesitter').setup({ -- Directory to install parsers and queries to install_dir = vim.fn.stdpath('data') .. '/site', }) - +vim.o.swapfile = false +vim.bo.swapfile = false require('nvim-treesitter').install({ 'go' }):wait(60000) vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() - vim.treesitter.start() + pcall(vim.treesitter.start) end, }) From 101907d640e4d67460ae1062894855191669de22 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 22 Nov 2025 23:13:06 +1100 Subject: [PATCH 25/47] increase install parser waiting time --- lua/tests/minimal.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index a9b49adae..455eb02a8 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -38,11 +38,15 @@ require('nvim-treesitter').setup({ }) vim.o.swapfile = false vim.bo.swapfile = false -require('nvim-treesitter').install({ 'go' }):wait(60000) +require('nvim-treesitter').install({ 'go' }):wait(300000) vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() pcall(vim.treesitter.start) + local queries = require('nvim-treesitter.config').get_installed('queries') + if not vim.tbl_contains(queries, 'go') then + error('No queries for go found') + end end, }) From 55f604f10b4444ceb448a51cd8b3915f3dc921fa Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 12:25:32 +1100 Subject: [PATCH 26/47] Add install parser step --- .github/workflows/ci.yml | 12 ++++++++++++ lua/tests/install-parsers.lua | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lua/tests/install-parsers.lua diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8bfb88282..8794b024e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,8 @@ jobs: unit_tests: name: unit tests runs-on: ${{ matrix.os }} + env: + NVIM_TS_DIR: ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter strategy: fail-fast: false matrix: @@ -50,6 +52,16 @@ jobs: 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: Setup Parsers cache + id: parsers-cache + uses: actions/cache@v4 + with: + path: ~/.local/share/nvim/site/parser + key: parsers-${{ hashFiles('parsers.lua') }} + - name: Compile parsers + if: steps.parsers-cache.outputs.cache-hit != 'true' + working-directory: ${{ env.NVIM_TS_DIR }} + run: nvim -l ./lua/tests/install-parsers.lua --max-jobs=2 - name: Run tests run: | export PATH="${PWD}/_neovim/bin:${PATH}" diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua new file mode 100644 index 000000000..e7f62fca8 --- /dev/null +++ b/lua/tests/install-parsers.lua @@ -0,0 +1,10 @@ +#!/usr/bin/env -S nvim -l +vim.opt.runtimepath:append(os.getenv('NVIM_TS_DIR')) +vim.opt.runtimepath:append('.') + +local parsers = { 'go' } +for i = 1, #_G.arg do + parsers[#parsers + 1] = _G.arg[i] ---@type string +end + +require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) -- wait max. 30 minutes From 0424144791ca6d719383fb789e663e1aa3f1dbfe Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 12:40:15 +1100 Subject: [PATCH 27/47] github pipeline update --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8794b024e..32113fe59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: name: unit tests runs-on: ${{ matrix.os }} env: - NVIM_TS_DIR: ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter + NVIM_TS_DIR: ${HOME}/.local/share/nvim/site/pack/vendor/start/nvim-treesitter strategy: fail-fast: false matrix: From e038c0d6fe3aafcd9968e77b51bf44caf376100f Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 12:42:59 +1100 Subject: [PATCH 28/47] update github pipeline --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32113fe59..4dbe34112 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: name: unit tests runs-on: ${{ matrix.os }} env: - NVIM_TS_DIR: ${HOME}/.local/share/nvim/site/pack/vendor/start/nvim-treesitter + NVIM_TS_DIR: "${HOME}/.local/share/nvim/site/pack/vendor/start/nvim-treesitter" strategy: fail-fast: false matrix: From 1477ad4157eef67affb3a4ff0dfda52a846a8f77 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 12:50:30 +1100 Subject: [PATCH 29/47] workflow updates --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dbe34112..53eefcc23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: name: unit tests runs-on: ${{ matrix.os }} env: - NVIM_TS_DIR: "${HOME}/.local/share/nvim/site/pack/vendor/start/nvim-treesitter" + NVIM_TS_DIR: .test-deps/nvim-treesitter strategy: fail-fast: false matrix: @@ -52,6 +52,12 @@ jobs: 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: Install nvim-treesitter + uses: actions/checkout@v4 + with: + repository: nvim-treesitter/nvim-treesitter + ref: main + path: ${{ env.NVIM_TS_DIR }} - name: Setup Parsers cache id: parsers-cache uses: actions/cache@v4 From ddd54720dd33bb35caaa86e2c5934f0973471ae9 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 12:56:37 +1100 Subject: [PATCH 30/47] update workflows --- .github/workflows/ci.yml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53eefcc23..366e652f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,22 +52,8 @@ jobs: 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: Install nvim-treesitter - uses: actions/checkout@v4 - with: - repository: nvim-treesitter/nvim-treesitter - ref: main - path: ${{ env.NVIM_TS_DIR }} - - name: Setup Parsers cache - id: parsers-cache - uses: actions/cache@v4 - with: - path: ~/.local/share/nvim/site/parser - key: parsers-${{ hashFiles('parsers.lua') }} - name: Compile parsers - if: steps.parsers-cache.outputs.cache-hit != 'true' - working-directory: ${{ env.NVIM_TS_DIR }} - run: nvim -l ./lua/tests/install-parsers.lua --max-jobs=2 + run: nvim -l lua/tests/install-parsers.lua --max-jobs=2 - name: Run tests run: | export PATH="${PWD}/_neovim/bin:${PATH}" From 08db52da655643bb07dc0636c825d25bfd5c0f1d Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 12:58:55 +1100 Subject: [PATCH 31/47] update nvim env vars --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 366e652f1..eac871b71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,9 @@ jobs: 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: nvim -l lua/tests/install-parsers.lua --max-jobs=2 + 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}" From 64c0f9b09e82f884aaa03176b29f83e46e7789d1 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 13:06:04 +1100 Subject: [PATCH 32/47] update minimal.lua --- init.lua | 68 +++++++++++++++++++++++++++++++++++++++++++ lua/tests/minimal.lua | 1 - 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 init.lua diff --git a/init.lua b/init.lua new file mode 100644 index 000000000..c7032eeb6 --- /dev/null +++ b/init.lua @@ -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, +}) diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index 455eb02a8..469a2d6e8 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -38,7 +38,6 @@ require('nvim-treesitter').setup({ }) vim.o.swapfile = false vim.bo.swapfile = false -require('nvim-treesitter').install({ 'go' }):wait(300000) vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() From d19b42eeeba1b4e15ce85551dfa633ab0403a51f Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 13:13:00 +1100 Subject: [PATCH 33/47] Update minimal.lua --- lua/tests/minimal.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index 469a2d6e8..165faab6c 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -44,6 +44,7 @@ vim.api.nvim_create_autocmd('FileType', { pcall(vim.treesitter.start) local queries = require('nvim-treesitter.config').get_installed('queries') if not vim.tbl_contains(queries, 'go') then + print('Installed queries: ' .. vim.inspect(queries)) error('No queries for go found') end end, From 2936b1d5478e015079d34d8acb79aafffa58b92b Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 14:15:10 +1100 Subject: [PATCH 34/47] update env var --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eac871b71..397eed397 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,6 @@ jobs: unit_tests: name: unit tests runs-on: ${{ matrix.os }} - env: - NVIM_TS_DIR: .test-deps/nvim-treesitter strategy: fail-fast: false matrix: From f379906fd845c38fe4024415c23e04f5726a2cf9 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 14:26:04 +1100 Subject: [PATCH 35/47] update setup script --- lua/tests/install-parsers.lua | 22 +++++++++++++++++++++- lua/tests/minimal.lua | 12 ++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index e7f62fca8..e953465bd 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -1,5 +1,5 @@ #!/usr/bin/env -S nvim -l -vim.opt.runtimepath:append(os.getenv('NVIM_TS_DIR')) +vim.opt.runtimepath:append('../nvim-treesitter') vim.opt.runtimepath:append('.') local parsers = { 'go' } @@ -7,4 +7,24 @@ for i = 1, #_G.arg do parsers[#parsers + 1] = _G.arg[i] ---@type string end +require('nvim-treesitter').setup({ + -- Directory to install parsers and queries to + install_dir = vim.fn.stdpath('data') .. '/site', +}) + require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) -- wait max. 30 minutes + + +-- Verify installation +print("Verifying parser installation...") +local install_info = require('nvim-treesitter.info') +local installed = install_info.installed_parsers() +print('Installed parsers: ' .. vim.inspect(installed)) + +for _, parser in ipairs(parsers) do + if vim.tbl_contains(installed, parser) then + print("โœ“ Parser " .. parser .. " successfully installed") + else + print("โœ— Parser " .. parser .. " failed to install") + end +end \ No newline at end of file diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index 165faab6c..8fb41626b 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -42,10 +42,14 @@ vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() pcall(vim.treesitter.start) - local queries = require('nvim-treesitter.config').get_installed('queries') - if not vim.tbl_contains(queries, 'go') then - print('Installed queries: ' .. vim.inspect(queries)) - error('No queries for go found') + -- Check if go parser is available using main branch API + local ok, parser = pcall(vim.treesitter.get_parser, 0, 'go') + if not ok then + -- Check what parsers are actually installed + local install_info = require('nvim-treesitter.info') + local installed = install_info.installed_parsers() + print('Installed parsers: ' .. vim.inspect(installed)) + error('No parser for go found') end end, }) From 68e46111f6157560b3436dd6807ae8d36eb38ada Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 14:36:13 +1100 Subject: [PATCH 36/47] fix treesitter main --- lua/tests/install-parsers.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index e953465bd..5c1e64695 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -17,12 +17,10 @@ require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) -- w -- Verify installation print("Verifying parser installation...") -local install_info = require('nvim-treesitter.info') -local installed = install_info.installed_parsers() -print('Installed parsers: ' .. vim.inspect(installed)) for _, parser in ipairs(parsers) do - if vim.tbl_contains(installed, parser) then + local ok = pcall(vim.treesitter.language.add, parser) + if ok then print("โœ“ Parser " .. parser .. " successfully installed") else print("โœ— Parser " .. parser .. " failed to install") From e0b2b09a39f44e231607cecb1427da2db8e790fe Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 14:43:50 +1100 Subject: [PATCH 37/47] update minimal.lua --- lua/tests/go_comment_spec.lua | 6 +++++- lua/tests/minimal.lua | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/tests/go_comment_spec.lua b/lua/tests/go_comment_spec.lua index 6d731b90f..a763edf53 100644 --- a/lua/tests/go_comment_spec.lua +++ b/lua/tests/go_comment_spec.lua @@ -3,9 +3,13 @@ local eq = assert.are.same local busted = require('plenary/busted') local cur_dir = vim.fn.expand('%:p:h') describe('should get nodes ', 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 + _GO_NVIM_CFG.verbose = true _GO_NVIM_CFG.comment_placeholder = ' ๎˜ง ' - local status = require('plenary.reload').reload_module('go.nvim') status = require('plenary.reload').reload_module('nvim-treesitter/nvim-treesitter') diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index 8fb41626b..a39b2b8e5 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -46,9 +46,7 @@ vim.api.nvim_create_autocmd('FileType', { local ok, parser = pcall(vim.treesitter.get_parser, 0, 'go') if not ok then -- Check what parsers are actually installed - local install_info = require('nvim-treesitter.info') - local installed = install_info.installed_parsers() - print('Installed parsers: ' .. vim.inspect(installed)) + print('Failed to get go parser') error('No parser for go found') end end, From e3d6bd6283d9819b4ab7929846e313c92419de38 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 14:49:01 +1100 Subject: [PATCH 38/47] add ts binary into runtime --- lua/tests/init.lua | 1 + lua/tests/install-parsers.lua | 6 +++++- lua/tests/minimal.lua | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/tests/init.lua b/lua/tests/init.lua index 715fa6ea7..4bb98c4b0 100644 --- a/lua/tests/init.lua +++ b/lua/tests/init.lua @@ -48,6 +48,7 @@ require('nvim-treesitter').setup({ -- Directory to install parsers and queries to install_dir = vim.fn.stdpath('data') .. '/site', }) +vim.opt.rtp:append(vim.fn.stdpath('data') .. '/site') vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index 5c1e64695..e351285de 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -7,9 +7,13 @@ for i = 1, #_G.arg do parsers[#parsers + 1] = _G.arg[i] ---@type string end +local install_dir = vim.fn.stdpath('data') .. '/site' +print('Installing to: ' .. install_dir) + +vim.opt.rtp:append(install_dir) require('nvim-treesitter').setup({ -- Directory to install parsers and queries to - install_dir = vim.fn.stdpath('data') .. '/site', + install_dir = install_dir, }) require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) -- wait max. 30 minutes diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index a39b2b8e5..b3d7ceb37 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -11,6 +11,7 @@ vim.cmd([[ runtime! plugin/nvim-lspconfig.vim runtime! plugin/guihua.lua ]]) +vim.opt.rtp:append(vim.fn.stdpath('data') .. '/site') vim.opt.swapfile = false -- no swapfile vim.opt.backup = false -- no backup From fb596d40b9b856a4dfed843f86d971022e319d63 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 14:56:20 +1100 Subject: [PATCH 39/47] add debug logs --- lua/tests/install-parsers.lua | 38 +++++++++++++++++++++++++++++++---- lua/tests/minimal.lua | 14 +++++-------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index e351285de..57671d8c9 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -10,7 +10,9 @@ end local install_dir = vim.fn.stdpath('data') .. '/site' print('Installing to: ' .. install_dir) +-- Add install_dir to runtimepath before setup vim.opt.rtp:append(install_dir) + require('nvim-treesitter').setup({ -- Directory to install parsers and queries to install_dir = install_dir, @@ -18,15 +20,43 @@ require('nvim-treesitter').setup({ require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) -- wait max. 30 minutes - -- Verify installation print("Verifying parser installation...") +print("Install directory: " .. install_dir) + +-- Check if directories exist +local parser_dir = install_dir .. '/parser' +local queries_dir = install_dir .. '/queries' +print('Parser directory exists: ' .. tostring(vim.fn.isdirectory(parser_dir) == 1)) +print('Queries directory exists: ' .. tostring(vim.fn.isdirectory(queries_dir) == 1)) + +-- List what's in the directories +if vim.fn.isdirectory(parser_dir) == 1 then + local files = vim.fn.glob(parser_dir .. '/*', false, true) + print('Parser files: ' .. vim.inspect(files)) +end +if vim.fn.isdirectory(queries_dir) == 1 then + local dirs = vim.fn.glob(queries_dir .. '/*', false, true) + print('Query subdirs: ' .. vim.inspect(dirs)) + -- Check specifically for go queries + local go_queries = vim.fn.glob(queries_dir .. '/go/*', false, true) + print('Go query files: ' .. vim.inspect(go_queries)) +end +-- Try to load the parser for _, parser in ipairs(parsers) do - local ok = pcall(vim.treesitter.language.add, parser) + local ok, err = pcall(vim.treesitter.language.add, parser) if ok then - print("โœ“ Parser " .. parser .. " successfully installed") + print("โœ“ Parser " .. parser .. " language loaded") + else + print("โœ— Parser " .. parser .. " language failed: " .. tostring(err)) + end + + -- Check if we can create a parser instance + local test_ok, test_err = pcall(vim.treesitter.get_string_parser, '', parser) + if test_ok then + print("โœ“ Can create " .. parser .. " parser instance") else - print("โœ— Parser " .. parser .. " failed to install") + print("โœ— Cannot create " .. parser .. " parser: " .. tostring(test_err)) end end \ No newline at end of file diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index b3d7ceb37..c202c8eee 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -4,6 +4,9 @@ vim.opt.rtp:append('../nvim-treesitter') vim.opt.rtp:append('../nvim-lspconfig/') vim.opt.rtp:append('../guihua.lua/') +-- Add the treesitter parser install directory to runtimepath BEFORE loading plugins +vim.opt.rtp:append(vim.fn.stdpath('data') .. '/site') + vim.cmd([[ runtime! plugin/plenary.vim runtime! plugin/nvim-treesitter.vim @@ -11,7 +14,6 @@ vim.cmd([[ runtime! plugin/nvim-lspconfig.vim runtime! plugin/guihua.lua ]]) -vim.opt.rtp:append(vim.fn.stdpath('data') .. '/site') vim.opt.swapfile = false -- no swapfile vim.opt.backup = false -- no backup @@ -42,14 +44,8 @@ vim.bo.swapfile = false vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() - pcall(vim.treesitter.start) - -- Check if go parser is available using main branch API - local ok, parser = pcall(vim.treesitter.get_parser, 0, 'go') - if not ok then - -- Check what parsers are actually installed - print('Failed to get go parser') - error('No parser for go found') - end + -- Don't use pcall here so we can see the actual error + vim.treesitter.start() end, }) From edd33599a28120625052d7de8e829ddc7fb72c41 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:02:35 +1100 Subject: [PATCH 40/47] fix minimal --- lua/tests/minimal.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index c202c8eee..896ebd864 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -35,17 +35,28 @@ require('go').setup({ log_path = vim.fn.expand('$HOME') .. '/.cache/nvim/gonvim.log', lsp_cfg = true, }) + require('nvim-treesitter').setup({ -- Directory to install parsers and queries to install_dir = vim.fn.stdpath('data') .. '/site', }) + vim.o.swapfile = false vim.bo.swapfile = false + +-- Don't create a FileType autocmd that calls vim.treesitter.start() +-- Treesitter will start automatically when needed +-- Just verify the parser is available when needed vim.api.nvim_create_autocmd('FileType', { pattern = { 'go' }, callback = function() - -- Don't use pcall here so we can see the actual error - vim.treesitter.start() + -- Only verify, don't start + local has_parser = pcall(vim.treesitter.language.add, 'go') + if not has_parser then + print('Warning: Go parser not available') + else + print('Go parser is available') + end end, }) From 48481ad2ca7d2bc858e33864065f6c0829d78f18 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:08:25 +1100 Subject: [PATCH 41/47] add debug logs --- lua/tests/install-parsers.lua | 24 +++++++++++++----------- lua/tests/minimal.lua | 22 +++++----------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index 57671d8c9..c82fa46e9 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -43,20 +43,22 @@ if vim.fn.isdirectory(queries_dir) == 1 then print('Go query files: ' .. vim.inspect(go_queries)) end +-- Set parser path explicitly +vim.treesitter.language.register('go', 'go') + -- Try to load the parser for _, parser in ipairs(parsers) do - local ok, err = pcall(vim.treesitter.language.add, parser) + local ok, lang = pcall(vim.treesitter.language.add, parser) if ok then - print("โœ“ Parser " .. parser .. " language loaded") - else - print("โœ— Parser " .. parser .. " language failed: " .. tostring(err)) - end - - -- Check if we can create a parser instance - local test_ok, test_err = pcall(vim.treesitter.get_string_parser, '', parser) - if test_ok then - print("โœ“ Can create " .. parser .. " parser instance") + print("โœ“ Parser " .. parser .. " language added") + -- Try to actually load it + local load_ok, err = pcall(vim.treesitter.language.inspect, parser) + if load_ok then + print("โœ“ Parser " .. parser .. " successfully loaded") + else + print("โœ— Parser " .. parser .. " failed to load: " .. tostring(err)) + end else - print("โœ— Cannot create " .. parser .. " parser: " .. tostring(test_err)) + print("โœ— Parser " .. parser .. " language failed: " .. tostring(lang)) end end \ No newline at end of file diff --git a/lua/tests/minimal.lua b/lua/tests/minimal.lua index 896ebd864..c4e6092a7 100644 --- a/lua/tests/minimal.lua +++ b/lua/tests/minimal.lua @@ -5,7 +5,8 @@ vim.opt.rtp:append('../nvim-lspconfig/') vim.opt.rtp:append('../guihua.lua/') -- Add the treesitter parser install directory to runtimepath BEFORE loading plugins -vim.opt.rtp:append(vim.fn.stdpath('data') .. '/site') +local parser_install_dir = vim.fn.stdpath('data') .. '/site' +vim.opt.rtp:prepend(parser_install_dir) vim.cmd([[ runtime! plugin/plenary.vim @@ -38,27 +39,14 @@ require('go').setup({ require('nvim-treesitter').setup({ -- Directory to install parsers and queries to - install_dir = vim.fn.stdpath('data') .. '/site', + install_dir = parser_install_dir, }) vim.o.swapfile = false vim.bo.swapfile = false --- Don't create a FileType autocmd that calls vim.treesitter.start() --- Treesitter will start automatically when needed --- Just verify the parser is available when needed -vim.api.nvim_create_autocmd('FileType', { - pattern = { 'go' }, - callback = function() - -- Only verify, don't start - local has_parser = pcall(vim.treesitter.language.add, 'go') - if not has_parser then - print('Warning: Go parser not available') - else - print('Go parser is available') - end - end, -}) +-- Disable automatic treesitter start for now +vim.g.ts_highlight_disable = true vim.cmd([[set completeopt+=menuone,noselect,popup]]) vim.lsp.enable('gopls') From 00fe257aa71e61230d6cdca9707fec355558305d Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:12:37 +1100 Subject: [PATCH 42/47] add logs --- lua/tests/install-parsers.lua | 51 ++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index c82fa46e9..6e14c767a 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -3,9 +3,6 @@ vim.opt.runtimepath:append('../nvim-treesitter') vim.opt.runtimepath:append('.') local parsers = { 'go' } -for i = 1, #_G.arg do - parsers[#parsers + 1] = _G.arg[i] ---@type string -end local install_dir = vim.fn.stdpath('data') .. '/site' print('Installing to: ' .. install_dir) @@ -18,7 +15,17 @@ require('nvim-treesitter').setup({ install_dir = install_dir, }) -require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) -- wait max. 30 minutes +print('Starting parser installation...') +local ok, result = pcall(function() + return require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) +end) + +if not ok then + print('Installation failed: ' .. tostring(result)) + os.exit(1) +end + +print('Installation completed, verifying...') -- Verify installation print("Verifying parser installation...") @@ -32,33 +39,39 @@ print('Queries directory exists: ' .. tostring(vim.fn.isdirectory(queries_dir) = -- List what's in the directories if vim.fn.isdirectory(parser_dir) == 1 then - local files = vim.fn.glob(parser_dir .. '/*', false, true) + local files = vim.fn.readdir(parser_dir) print('Parser files: ' .. vim.inspect(files)) + if #files == 0 then + print('ERROR: No parser files found!') + os.exit(1) + end +else + print('ERROR: Parser directory does not exist!') + os.exit(1) end + if vim.fn.isdirectory(queries_dir) == 1 then - local dirs = vim.fn.glob(queries_dir .. '/*', false, true) + local dirs = vim.fn.readdir(queries_dir) print('Query subdirs: ' .. vim.inspect(dirs)) -- Check specifically for go queries - local go_queries = vim.fn.glob(queries_dir .. '/go/*', false, true) - print('Go query files: ' .. vim.inspect(go_queries)) + if vim.fn.isdirectory(queries_dir .. '/go') == 1 then + local go_queries = vim.fn.readdir(queries_dir .. '/go') + print('Go query files: ' .. vim.inspect(go_queries)) + end +else + print('ERROR: Queries directory does not exist!') + os.exit(1) end --- Set parser path explicitly -vim.treesitter.language.register('go', 'go') - -- Try to load the parser for _, parser in ipairs(parsers) do local ok, lang = pcall(vim.treesitter.language.add, parser) if ok then print("โœ“ Parser " .. parser .. " language added") - -- Try to actually load it - local load_ok, err = pcall(vim.treesitter.language.inspect, parser) - if load_ok then - print("โœ“ Parser " .. parser .. " successfully loaded") - else - print("โœ— Parser " .. parser .. " failed to load: " .. tostring(err)) - end else print("โœ— Parser " .. parser .. " language failed: " .. tostring(lang)) + os.exit(1) end -end \ No newline at end of file +end + +print('All parsers installed successfully!') \ No newline at end of file From 68e9bf4f66b111574d240b892c122e242bd61ba5 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:15:30 +1100 Subject: [PATCH 43/47] fix install-parsers --- lua/tests/install-parsers.lua | 52 +++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index 6e14c767a..e91af1b61 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -7,6 +7,10 @@ local parsers = { 'go' } local install_dir = vim.fn.stdpath('data') .. '/site' print('Installing to: ' .. install_dir) +-- Create directories if they don't exist +vim.fn.mkdir(install_dir .. '/parser', 'p') +vim.fn.mkdir(install_dir .. '/queries', 'p') + -- Add install_dir to runtimepath before setup vim.opt.rtp:append(install_dir) @@ -25,7 +29,38 @@ if not ok then os.exit(1) end -print('Installation completed, verifying...') +print('Installation completed, checking build artifacts...') + +-- Check the nvim-treesitter cache directory where parsers are actually built +local cache_dir = vim.fn.stdpath('cache') .. '/nvim-treesitter' +print('Cache directory: ' .. cache_dir) + +if vim.fn.isdirectory(cache_dir) == 1 then + local cache_contents = vim.fn.glob(cache_dir .. '/**', false, true) + print('Cache contents: ' .. vim.inspect(cache_contents)) +end + +-- Try to find where the parser was actually compiled +local possible_locations = { + cache_dir .. '/parser', + install_dir .. '/parser', + vim.fn.stdpath('data') .. '/parser', +} + +for _, loc in ipairs(possible_locations) do + if vim.fn.isdirectory(loc) == 1 then + local files = vim.fn.glob(loc .. '/*', false, true) + if #files > 0 then + print('Found parser files in: ' .. loc) + print('Files: ' .. vim.inspect(files)) + -- Copy to install_dir if needed + if loc ~= install_dir .. '/parser' then + print('Copying parsers to install directory...') + vim.fn.system(string.format('cp -r %s/* %s/', loc, install_dir .. '/parser')) + end + end + end +end -- Verify installation print("Verifying parser installation...") @@ -42,7 +77,7 @@ if vim.fn.isdirectory(parser_dir) == 1 then local files = vim.fn.readdir(parser_dir) print('Parser files: ' .. vim.inspect(files)) if #files == 0 then - print('ERROR: No parser files found!') + print('ERROR: No parser files found after installation!') os.exit(1) end else @@ -53,14 +88,13 @@ end if vim.fn.isdirectory(queries_dir) == 1 then local dirs = vim.fn.readdir(queries_dir) print('Query subdirs: ' .. vim.inspect(dirs)) - -- Check specifically for go queries - if vim.fn.isdirectory(queries_dir .. '/go') == 1 then - local go_queries = vim.fn.readdir(queries_dir .. '/go') - print('Go query files: ' .. vim.inspect(go_queries)) - end else - print('ERROR: Queries directory does not exist!') - os.exit(1) + print('WARNING: Queries directory does not exist - copying from nvim-treesitter') + -- Copy queries from nvim-treesitter source + local ts_queries = '../nvim-treesitter/queries' + if vim.fn.isdirectory(ts_queries) == 1 then + vim.fn.system(string.format('cp -r %s/* %s/', ts_queries, queries_dir)) + end end -- Try to load the parser From c18b6a26490e4ea134c9131472b81faf9709911a Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:20:15 +1100 Subject: [PATCH 44/47] add fix for install-parsers --- lua/tests/install-parsers.lua | 98 +++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index e91af1b61..03fa7f692 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -29,55 +29,69 @@ if not ok then os.exit(1) end -print('Installation completed, checking build artifacts...') - --- Check the nvim-treesitter cache directory where parsers are actually built -local cache_dir = vim.fn.stdpath('cache') .. '/nvim-treesitter' -print('Cache directory: ' .. cache_dir) - -if vim.fn.isdirectory(cache_dir) == 1 then - local cache_contents = vim.fn.glob(cache_dir .. '/**', false, true) - print('Cache contents: ' .. vim.inspect(cache_contents)) -end - --- Try to find where the parser was actually compiled -local possible_locations = { - cache_dir .. '/parser', - install_dir .. '/parser', - vim.fn.stdpath('data') .. '/parser', +print('Installation completed, searching for compiled parsers...') + +-- In treesitter main branch, parsers might be in different locations +local search_paths = { + vim.fn.stdpath('cache') .. '/nvim-treesitter', + vim.fn.stdpath('data') .. '/nvim-treesitter', + vim.fn.stdpath('state') .. '/nvim-treesitter', + install_dir, + '~/.local/share/nvim/site', + '~/.cache/nvim/nvim-treesitter', } -for _, loc in ipairs(possible_locations) do - if vim.fn.isdirectory(loc) == 1 then - local files = vim.fn.glob(loc .. '/*', false, true) - if #files > 0 then - print('Found parser files in: ' .. loc) - print('Files: ' .. vim.inspect(files)) - -- Copy to install_dir if needed - if loc ~= install_dir .. '/parser' then - print('Copying parsers to install directory...') - vim.fn.system(string.format('cp -r %s/* %s/', loc, install_dir .. '/parser')) +-- Search recursively for .so files +for _, base_path in ipairs(search_paths) do + local expanded = vim.fn.expand(base_path) + if vim.fn.isdirectory(expanded) == 1 then + print('Searching in: ' .. expanded) + local so_files = vim.fn.glob(expanded .. '/**/*.so', false, true) + if #so_files > 0 then + print('Found .so files: ' .. vim.inspect(so_files)) + -- Copy all .so files to install_dir/parser + for _, so_file in ipairs(so_files) do + local filename = vim.fn.fnamemodify(so_file, ':t') + local dest = install_dir .. '/parser/' .. filename + print('Copying ' .. so_file .. ' to ' .. dest) + vim.fn.system(string.format('cp "%s" "%s"', so_file, dest)) end end end end --- Verify installation -print("Verifying parser installation...") -print("Install directory: " .. install_dir) +-- Also look for queries +local queries_found = false +for _, base_path in ipairs(search_paths) do + local expanded = vim.fn.expand(base_path) + local queries_path = expanded .. '/queries/go' + if vim.fn.isdirectory(queries_path) == 1 then + print('Found queries in: ' .. queries_path) + vim.fn.system(string.format('cp -r "%s" "%s/"', queries_path, install_dir .. '/queries')) + queries_found = true + break + end +end --- Check if directories exist +-- If queries not found, copy from nvim-treesitter source +if not queries_found then + print('Copying queries from nvim-treesitter source...') + local ts_queries = vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter/queries/go') + if vim.fn.isdirectory(ts_queries) == 1 then + vim.fn.system(string.format('cp -r "%s" "%s/"', ts_queries, install_dir .. '/queries')) + end +end + +-- Verify installation +print("\nVerifying parser installation...") local parser_dir = install_dir .. '/parser' -local queries_dir = install_dir .. '/queries' -print('Parser directory exists: ' .. tostring(vim.fn.isdirectory(parser_dir) == 1)) -print('Queries directory exists: ' .. tostring(vim.fn.isdirectory(queries_dir) == 1)) +local queries_dir = install_dir .. '/queries/go' --- List what's in the directories if vim.fn.isdirectory(parser_dir) == 1 then local files = vim.fn.readdir(parser_dir) print('Parser files: ' .. vim.inspect(files)) if #files == 0 then - print('ERROR: No parser files found after installation!') + print('ERROR: No parser files found!') os.exit(1) end else @@ -86,15 +100,10 @@ else end if vim.fn.isdirectory(queries_dir) == 1 then - local dirs = vim.fn.readdir(queries_dir) - print('Query subdirs: ' .. vim.inspect(dirs)) + local files = vim.fn.readdir(queries_dir) + print('Query files: ' .. vim.inspect(files)) else - print('WARNING: Queries directory does not exist - copying from nvim-treesitter') - -- Copy queries from nvim-treesitter source - local ts_queries = '../nvim-treesitter/queries' - if vim.fn.isdirectory(ts_queries) == 1 then - vim.fn.system(string.format('cp -r %s/* %s/', ts_queries, queries_dir)) - end + print('WARNING: Queries directory does not exist!') end -- Try to load the parser @@ -104,8 +113,7 @@ for _, parser in ipairs(parsers) do print("โœ“ Parser " .. parser .. " language added") else print("โœ— Parser " .. parser .. " language failed: " .. tostring(lang)) - os.exit(1) end end -print('All parsers installed successfully!') \ No newline at end of file +print('Parser installation complete!') \ No newline at end of file From a794d326b13ff4278af6fc3b50ec53702c9028ee Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:25:37 +1100 Subject: [PATCH 45/47] copy parsers --- lua/tests/install-parsers.lua | 117 ++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 49 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index 03fa7f692..060f71061 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -29,56 +29,79 @@ if not ok then os.exit(1) end -print('Installation completed, searching for compiled parsers...') - --- In treesitter main branch, parsers might be in different locations -local search_paths = { - vim.fn.stdpath('cache') .. '/nvim-treesitter', - vim.fn.stdpath('data') .. '/nvim-treesitter', - vim.fn.stdpath('state') .. '/nvim-treesitter', - install_dir, - '~/.local/share/nvim/site', - '~/.cache/nvim/nvim-treesitter', +print('Installation completed, searching for go parser...') + +-- Check the build directory specifically for go parser +local build_locations = { + vim.fn.stdpath('cache') .. '/nvim-treesitter/tree-sitter-go', + vim.fn.stdpath('data') .. '/nvim-treesitter/tree-sitter-go', + install_dir .. '/parser', + '/tmp/tree-sitter-go', } --- Search recursively for .so files -for _, base_path in ipairs(search_paths) do - local expanded = vim.fn.expand(base_path) +local go_parser_found = false + +for _, location in ipairs(build_locations) do + local expanded = vim.fn.expand(location) + print('Checking: ' .. expanded) if vim.fn.isdirectory(expanded) == 1 then - print('Searching in: ' .. expanded) - local so_files = vim.fn.glob(expanded .. '/**/*.so', false, true) - if #so_files > 0 then - print('Found .so files: ' .. vim.inspect(so_files)) - -- Copy all .so files to install_dir/parser - for _, so_file in ipairs(so_files) do - local filename = vim.fn.fnamemodify(so_file, ':t') - local dest = install_dir .. '/parser/' .. filename - print('Copying ' .. so_file .. ' to ' .. dest) + print(' Directory exists, listing contents:') + local files = vim.fn.glob(expanded .. '/*', false, true) + for _, file in ipairs(files) do + print(' ' .. file) + end + + -- Look for go.so specifically + local go_so = vim.fn.glob(expanded .. '/**/go.so', false, true) + if #go_so > 0 then + print(' Found go.so: ' .. vim.inspect(go_so)) + for _, so_file in ipairs(go_so) do + local dest = install_dir .. '/parser/go.so' + print(' Copying ' .. so_file .. ' to ' .. dest) vim.fn.system(string.format('cp "%s" "%s"', so_file, dest)) + go_parser_found = true end end end end --- Also look for queries -local queries_found = false -for _, base_path in ipairs(search_paths) do - local expanded = vim.fn.expand(base_path) - local queries_path = expanded .. '/queries/go' - if vim.fn.isdirectory(queries_path) == 1 then - print('Found queries in: ' .. queries_path) - vim.fn.system(string.format('cp -r "%s" "%s/"', queries_path, install_dir .. '/queries')) - queries_found = true - break +-- If not found, search everywhere +if not go_parser_found then + print('\nSearching entire filesystem for go.so...') + local search_roots = { + vim.fn.stdpath('cache'), + vim.fn.stdpath('data'), + vim.fn.stdpath('state'), + '/tmp', + } + + for _, root in ipairs(search_roots) do + local go_files = vim.fn.glob(root .. '/**/go.so', false, true) + if #go_files > 0 then + print('Found go.so files: ' .. vim.inspect(go_files)) + for _, so_file in ipairs(go_files) do + local dest = install_dir .. '/parser/go.so' + print('Copying ' .. so_file .. ' to ' .. dest) + vim.fn.system(string.format('cp "%s" "%s"', so_file, dest)) + go_parser_found = true + end + break + end end end --- If queries not found, copy from nvim-treesitter source -if not queries_found then - print('Copying queries from nvim-treesitter source...') - local ts_queries = vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter/queries/go') +-- Copy queries from nvim-treesitter source +print('\nCopying queries...') +local ts_queries_paths = { + vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter/queries/go'), + '../nvim-treesitter/queries/go', +} + +for _, ts_queries in ipairs(ts_queries_paths) do if vim.fn.isdirectory(ts_queries) == 1 then + print('Copying queries from: ' .. ts_queries) vim.fn.system(string.format('cp -r "%s" "%s/"', ts_queries, install_dir .. '/queries')) + break end end @@ -90,8 +113,13 @@ local queries_dir = install_dir .. '/queries/go' if vim.fn.isdirectory(parser_dir) == 1 then local files = vim.fn.readdir(parser_dir) print('Parser files: ' .. vim.inspect(files)) - if #files == 0 then - print('ERROR: No parser files found!') + + -- Check specifically for go.so + local go_so_exists = vim.fn.filereadable(parser_dir .. '/go.so') == 1 + print('go.so exists: ' .. tostring(go_so_exists)) + + if not go_so_exists then + print('ERROR: go.so not found!') os.exit(1) end else @@ -103,17 +131,8 @@ if vim.fn.isdirectory(queries_dir) == 1 then local files = vim.fn.readdir(queries_dir) print('Query files: ' .. vim.inspect(files)) else - print('WARNING: Queries directory does not exist!') -end - --- Try to load the parser -for _, parser in ipairs(parsers) do - local ok, lang = pcall(vim.treesitter.language.add, parser) - if ok then - print("โœ“ Parser " .. parser .. " language added") - else - print("โœ— Parser " .. parser .. " language failed: " .. tostring(lang)) - end + print('ERROR: Queries directory does not exist!') + os.exit(1) end print('Parser installation complete!') \ No newline at end of file From 4ed002885b4fb9d9962f6fb689775a10735d366d Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:28:40 +1100 Subject: [PATCH 46/47] fix install-parsers --- lua/tests/install-parsers.lua | 109 +++++++++++++++++----------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index 060f71061..1bd0d0ea0 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -20,72 +20,71 @@ require('nvim-treesitter').setup({ }) print('Starting parser installation...') -local ok, result = pcall(function() - return require('nvim-treesitter').install(parsers, { force = true }):wait(1800000) -end) -if not ok then - print('Installation failed: ' .. tostring(result)) - os.exit(1) +-- Use synchronous install and capture output +local install = require('nvim-treesitter.install') +for _, parser in ipairs(parsers) do + print('Installing parser: ' .. parser) + local success, err = pcall(function() + install.update(parser) + end) + if not success then + print('Installation error: ' .. tostring(err)) + end end +-- Wait a bit for compilation to complete +vim.wait(5000, function() return false end) + print('Installation completed, searching for go parser...') --- Check the build directory specifically for go parser -local build_locations = { - vim.fn.stdpath('cache') .. '/nvim-treesitter/tree-sitter-go', - vim.fn.stdpath('data') .. '/nvim-treesitter/tree-sitter-go', - install_dir .. '/parser', - '/tmp/tree-sitter-go', +-- Check all possible locations +local all_locations = { + vim.fn.stdpath('cache') .. '/nvim-treesitter', + vim.fn.stdpath('data') .. '/nvim-treesitter', + vim.fn.stdpath('data') .. '/site', + '/tmp', } -local go_parser_found = false - -for _, location in ipairs(build_locations) do - local expanded = vim.fn.expand(location) - print('Checking: ' .. expanded) - if vim.fn.isdirectory(expanded) == 1 then - print(' Directory exists, listing contents:') - local files = vim.fn.glob(expanded .. '/*', false, true) - for _, file in ipairs(files) do - print(' ' .. file) - end - - -- Look for go.so specifically - local go_so = vim.fn.glob(expanded .. '/**/go.so', false, true) - if #go_so > 0 then - print(' Found go.so: ' .. vim.inspect(go_so)) - for _, so_file in ipairs(go_so) do +for _, root in ipairs(all_locations) do + print('\nSearching in: ' .. root) + if vim.fn.isdirectory(root) == 1 then + -- Use find command to locate go.so + local result = vim.fn.system(string.format('find "%s" -name "go.so" 2>/dev/null', root)) + if result ~= '' then + print('Found go.so via find: ' .. result) + local files = vim.split(result, '\n', { trimempty = true }) + for _, file in ipairs(files) do local dest = install_dir .. '/parser/go.so' - print(' Copying ' .. so_file .. ' to ' .. dest) - vim.fn.system(string.format('cp "%s" "%s"', so_file, dest)) - go_parser_found = true + print('Copying ' .. file .. ' to ' .. dest) + vim.fn.system(string.format('cp "%s" "%s"', file, dest)) end end - end -end - --- If not found, search everywhere -if not go_parser_found then - print('\nSearching entire filesystem for go.so...') - local search_roots = { - vim.fn.stdpath('cache'), - vim.fn.stdpath('data'), - vim.fn.stdpath('state'), - '/tmp', - } - - for _, root in ipairs(search_roots) do - local go_files = vim.fn.glob(root .. '/**/go.so', false, true) - if #go_files > 0 then - print('Found go.so files: ' .. vim.inspect(go_files)) - for _, so_file in ipairs(go_files) do - local dest = install_dir .. '/parser/go.so' - print('Copying ' .. so_file .. ' to ' .. dest) - vim.fn.system(string.format('cp "%s" "%s"', so_file, dest)) - go_parser_found = true + + -- Also check for the build directory + local build_result = vim.fn.system(string.format('find "%s" -type d -name "tree-sitter-go" 2>/dev/null', root)) + if build_result ~= '' then + print('Found tree-sitter-go directories: ' .. build_result) + local dirs = vim.split(build_result, '\n', { trimempty = true }) + for _, dir in ipairs(dirs) do + print('Contents of ' .. dir .. ':') + local ls_result = vim.fn.system(string.format('ls -la "%s" 2>/dev/null', dir)) + print(ls_result) + + -- Try to manually compile if source exists + if vim.fn.filereadable(dir .. '/src/parser.c') == 1 then + print('Found parser.c, attempting manual compilation...') + local compile_cmd = string.format( + 'cc -o "%s/go.so" -I"%s/src" "%s/src/parser.c" -shared -Os -lstdc++ -fPIC 2>&1', + install_dir .. '/parser', + dir, + dir + ) + print('Compile command: ' .. compile_cmd) + local compile_result = vim.fn.system(compile_cmd) + print('Compile result: ' .. compile_result) + end end - break end end end From 1f388d5da285a8009a1947e33ecc3285f0f54dbf Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 23 Nov 2025 15:32:41 +1100 Subject: [PATCH 47/47] download and compile --- lua/tests/install-parsers.lua | 156 +++++++++++++++++----------------- 1 file changed, 79 insertions(+), 77 deletions(-) diff --git a/lua/tests/install-parsers.lua b/lua/tests/install-parsers.lua index 1bd0d0ea0..374360871 100644 --- a/lua/tests/install-parsers.lua +++ b/lua/tests/install-parsers.lua @@ -2,8 +2,6 @@ vim.opt.runtimepath:append('../nvim-treesitter') vim.opt.runtimepath:append('.') -local parsers = { 'go' } - local install_dir = vim.fn.stdpath('data') .. '/site' print('Installing to: ' .. install_dir) @@ -11,81 +9,79 @@ print('Installing to: ' .. install_dir) vim.fn.mkdir(install_dir .. '/parser', 'p') vim.fn.mkdir(install_dir .. '/queries', 'p') --- Add install_dir to runtimepath before setup -vim.opt.rtp:append(install_dir) - -require('nvim-treesitter').setup({ - -- Directory to install parsers and queries to - install_dir = install_dir, -}) - -print('Starting parser installation...') - --- Use synchronous install and capture output -local install = require('nvim-treesitter.install') -for _, parser in ipairs(parsers) do - print('Installing parser: ' .. parser) - local success, err = pcall(function() - install.update(parser) - end) - if not success then - print('Installation error: ' .. tostring(err)) +-- Manual compilation approach +local function compile_parser() + local build_dir = '/tmp/tree-sitter-go' + + -- Clean up any existing build + vim.fn.system('rm -rf ' .. build_dir) + + -- Clone the tree-sitter-go repository + print('Cloning tree-sitter-go...') + local clone_result = vim.fn.system(string.format( + 'git clone --depth 1 https://github.com/tree-sitter/tree-sitter-go.git %s 2>&1', + build_dir + )) + print(clone_result) + + if vim.fn.isdirectory(build_dir .. '/src') ~= 1 then + print('ERROR: Failed to clone tree-sitter-go') + return false + end + + -- Compile the parser + print('Compiling parser...') + local parser_c = build_dir .. '/src/parser.c' + local scanner_c = build_dir .. '/src/scanner.c' + local output_so = install_dir .. '/parser/go.so' + + local sources = parser_c + if vim.fn.filereadable(scanner_c) == 1 then + sources = sources .. ' ' .. scanner_c + end + + local compile_cmd = string.format( + 'cc -o "%s" -I"%s/src" %s -shared -Os -fPIC 2>&1', + output_so, + build_dir, + sources + ) + + print('Compile command: ' .. compile_cmd) + local compile_result = vim.fn.system(compile_cmd) + print('Compile output: ' .. compile_result) + + -- Check if compilation succeeded + if vim.fn.filereadable(output_so) == 1 then + print('โœ“ Successfully compiled go.so') + return true + else + print('โœ— Failed to compile go.so') + return false end end --- Wait a bit for compilation to complete -vim.wait(5000, function() return false end) - -print('Installation completed, searching for go parser...') - --- Check all possible locations -local all_locations = { - vim.fn.stdpath('cache') .. '/nvim-treesitter', - vim.fn.stdpath('data') .. '/nvim-treesitter', - vim.fn.stdpath('data') .. '/site', - '/tmp', -} +-- Try nvim-treesitter first +print('Attempting nvim-treesitter installation...') +vim.opt.rtp:append(install_dir) -for _, root in ipairs(all_locations) do - print('\nSearching in: ' .. root) - if vim.fn.isdirectory(root) == 1 then - -- Use find command to locate go.so - local result = vim.fn.system(string.format('find "%s" -name "go.so" 2>/dev/null', root)) - if result ~= '' then - print('Found go.so via find: ' .. result) - local files = vim.split(result, '\n', { trimempty = true }) - for _, file in ipairs(files) do - local dest = install_dir .. '/parser/go.so' - print('Copying ' .. file .. ' to ' .. dest) - vim.fn.system(string.format('cp "%s" "%s"', file, dest)) - end - end - - -- Also check for the build directory - local build_result = vim.fn.system(string.format('find "%s" -type d -name "tree-sitter-go" 2>/dev/null', root)) - if build_result ~= '' then - print('Found tree-sitter-go directories: ' .. build_result) - local dirs = vim.split(build_result, '\n', { trimempty = true }) - for _, dir in ipairs(dirs) do - print('Contents of ' .. dir .. ':') - local ls_result = vim.fn.system(string.format('ls -la "%s" 2>/dev/null', dir)) - print(ls_result) - - -- Try to manually compile if source exists - if vim.fn.filereadable(dir .. '/src/parser.c') == 1 then - print('Found parser.c, attempting manual compilation...') - local compile_cmd = string.format( - 'cc -o "%s/go.so" -I"%s/src" "%s/src/parser.c" -shared -Os -lstdc++ -fPIC 2>&1', - install_dir .. '/parser', - dir, - dir - ) - print('Compile command: ' .. compile_cmd) - local compile_result = vim.fn.system(compile_cmd) - print('Compile result: ' .. compile_result) - end - end - end +local ok, _ = pcall(function() + require('nvim-treesitter').setup({ + install_dir = install_dir, + }) + + local install = require('nvim-treesitter.install') + install.update('go') + vim.wait(5000, function() return false end) +end) + +-- Check if nvim-treesitter installation worked +local go_so_path = install_dir .. '/parser/go.so' +if vim.fn.filereadable(go_so_path) ~= 1 then + print('nvim-treesitter installation did not create go.so, trying manual compilation...') + if not compile_parser() then + print('ERROR: Manual compilation also failed') + os.exit(1) end end @@ -94,16 +90,23 @@ print('\nCopying queries...') local ts_queries_paths = { vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter/queries/go'), '../nvim-treesitter/queries/go', + '/tmp/tree-sitter-go/queries', } +local queries_copied = false for _, ts_queries in ipairs(ts_queries_paths) do if vim.fn.isdirectory(ts_queries) == 1 then print('Copying queries from: ' .. ts_queries) vim.fn.system(string.format('cp -r "%s" "%s/"', ts_queries, install_dir .. '/queries')) + queries_copied = true break end end +if not queries_copied then + print('WARNING: Could not find queries directory') +end + -- Verify installation print("\nVerifying parser installation...") local parser_dir = install_dir .. '/parser' @@ -113,9 +116,9 @@ if vim.fn.isdirectory(parser_dir) == 1 then local files = vim.fn.readdir(parser_dir) print('Parser files: ' .. vim.inspect(files)) - -- Check specifically for go.so local go_so_exists = vim.fn.filereadable(parser_dir .. '/go.so') == 1 print('go.so exists: ' .. tostring(go_so_exists)) + print('go.so size: ' .. vim.fn.getfsize(parser_dir .. '/go.so') .. ' bytes') if not go_so_exists then print('ERROR: go.so not found!') @@ -130,8 +133,7 @@ if vim.fn.isdirectory(queries_dir) == 1 then local files = vim.fn.readdir(queries_dir) print('Query files: ' .. vim.inspect(files)) else - print('ERROR: Queries directory does not exist!') - os.exit(1) + print('WARNING: Queries directory does not exist - tests may fail') end -print('Parser installation complete!') \ No newline at end of file +print('\nโœ“ Parser installation complete!') \ No newline at end of file