Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ localtestsetup:
@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 -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 "TSUpdate go" -c "q"
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,19 @@ The plugin covers most features required for a gopher.

## Installation

Use your favorite package manager to install. The dependency `nvim-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.
Use your favorite package manager to install.
Additionally, you need to have tree-sitter-go installed for
syntax highlighting and some code generation features.

> [!NOTE]
> The 13K stars nvim-treesitter was archived when I was refactoring the code to its main branch. This plugin no longer
> requires nvim-treesitter but requires neovim 0.12 if you use master version. I do not guarantee the behavior of nvim
> The 13K stars nvim-treesitter was archived when I was refactoring
> the code to its main branch.
>
> This plugin no longer requires nvim-treesitter
> but requires neovim 0.12 and
> tree-sitter-go for syntax highlighting and some code generation features.
>
> I do not guarantee the behavior of nvim
> 0.11 will still be correct. To use nvim 0.11 pls use go.nvim v0.11 release

### [lazy.nvim](https://github.com/folke/lazy.nvim)
Expand All @@ -98,7 +104,6 @@ recommended to run this plugin.
dependencies = { -- optional packages
"ray-x/guihua.lua",
"neovim/nvim-lspconfig",
-- { "nvim-treesitter/nvim-treesitter", branch = 'main' } -- optional for master version
},
opts = function()

Expand Down
155 changes: 57 additions & 98 deletions doc/advanced-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Use your favorite package manager to install. The dependency treesitter main bra

### vim-plug
```viml
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/go.nvim'
Plug 'ray-x/guihua.lua' ; required if you using treesitter main branch
Expand All @@ -38,7 +37,6 @@ Plug 'ray-x/guihua.lua' ; required if you using treesitter main branch
use 'ray-x/go.nvim'
use 'ray-x/guihua.lua' -- required if using treesitter main branch
use 'neovim/nvim-lspconfig'
use 'nvim-treesitter/nvim-treesitter'
```
## Default Configuration

Expand Down Expand Up @@ -139,7 +137,6 @@ require('go').setup({
dap_retries = 20, -- see dap option max_retries
dap_enrich_config = nil, -- see dap option enrich_config
build_tags = "tag1,tag2", -- set default build tags
textobjects = true, -- enable default text objects through treesittter-text-objects
test_runner = 'go', -- one of {`go`, `dlv`, `ginkgo`, `gotestsum`}
verbose_tests = true, -- set to add verbose flag to tests deprecated, see '-v' option
run_in_floaterm = false, -- set to true to run in a float window. :GoTermClose closes the floatterm
Expand Down Expand Up @@ -202,102 +199,66 @@ This will override your global `go.nvim` setup

## Text Object

I did not provide textobject support in the plugin. Please use treesitter textobject plugin. My treesitter config:
I did not provide textobject support in the plugin. Please use treesitter textobject plugin.

```lua
require "nvim-treesitter.configs".setup {
incremental_selection = {
enable = enable,
keymaps = {
-- mappings for incremental selection (visual mappings)
init_selection = "gnn", -- maps in normal mode to init the node/scope selection
node_incremental = "grn", -- increment to the upper named parent
scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
node_decremental = "grm" -- decrement to the previous node
}
},
--- https://github.com/nvim-treesitter/nvim-treesitter-textobjects
require("nvim-treesitter-textobjects").setup {
move = {
-- whether to set jumps in the jumplist
set_jumps = true,
},
}

textobjects = {
-- syntax-aware textobjects
enable = enable,
lsp_interop = {
enable = enable,
peek_definition_code = {
["DF"] = "@function.outer",
["DF"] = "@class.outer"
}
},
keymaps = {
["iL"] = {
-- you can define your own textobjects directly here
go = "(function_definition) @function",
},
-- or you use the queries from supported languages with textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["aC"] = "@class.outer",
["iC"] = "@class.inner",
["ac"] = "@conditional.outer",
["ic"] = "@conditional.inner",
["ae"] = "@block.outer",
["ie"] = "@block.inner",
["al"] = "@loop.outer",
["il"] = "@loop.inner",
["is"] = "@statement.inner",
["as"] = "@statement.outer",
["ad"] = "@comment.outer",
["am"] = "@call.outer",
["im"] = "@call.inner"
},
move = {
enable = enable,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["]m"] = "@function.outer",
["]]"] = "@class.outer"
},
goto_next_end = {
["]M"] = "@function.outer",
["]["] = "@class.outer"
},
goto_previous_start = {
["[m"] = "@function.outer",
["[["] = "@class.outer"
},
goto_previous_end = {
["[M"] = "@function.outer",
["[]"] = "@class.outer"
}
},
select = {
enable = enable,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
-- Or you can define your own textobjects like this
["iF"] = {
python = "(function_definition) @function",
cpp = "(function_definition) @function",
c = "(function_definition) @function",
java = "(method_declaration) @function",
go = "(method_declaration) @function"
}
}
},
swap = {
enable = enable,
swap_next = {
["<leader>a"] = "@parameter.inner"
},
swap_previous = {
["<leader>A"] = "@parameter.inner"
}
}
}
}
-- keymaps
-- You can use the capture groups defined in `textobjects.scm`
vim.keymap.set({ "n", "x", "o" }, "]m", function()
require("nvim-treesitter-textobjects.move").goto_next_start("@function.outer", "textobjects")
end)
vim.keymap.set({ "n", "x", "o" }, "]]", function()
require("nvim-treesitter-textobjects.move").goto_next_start("@class.outer", "textobjects")
end)
-- You can also pass a list to group multiple queries.
vim.keymap.set({ "n", "x", "o" }, "]o", function()
require("nvim-treesitter-textobjects.move").goto_next_start({"@loop.inner", "@loop.outer"}, "textobjects")
end)
-- You can also use captures from other query groups like `locals.scm` or `folds.scm`
vim.keymap.set({ "n", "x", "o" }, "]s", function()
require("nvim-treesitter-textobjects.move").goto_next_start("@local.scope", "locals")
end)
vim.keymap.set({ "n", "x", "o" }, "]z", function()
require("nvim-treesitter-textobjects.move").goto_next_start("@fold", "folds")
end)

vim.keymap.set({ "n", "x", "o" }, "]M", function()
require("nvim-treesitter-textobjects.move").goto_next_end("@function.outer", "textobjects")
end)
vim.keymap.set({ "n", "x", "o" }, "][", function()
require("nvim-treesitter-textobjects.move").goto_next_end("@class.outer", "textobjects")
end)

vim.keymap.set({ "n", "x", "o" }, "[m", function()
require("nvim-treesitter-textobjects.move").goto_previous_start("@function.outer", "textobjects")
end)
vim.keymap.set({ "n", "x", "o" }, "[[", function()
require("nvim-treesitter-textobjects.move").goto_previous_start("@class.outer", "textobjects")
end)

vim.keymap.set({ "n", "x", "o" }, "[M", function()
require("nvim-treesitter-textobjects.move").goto_previous_end("@function.outer", "textobjects")
end)
vim.keymap.set({ "n", "x", "o" }, "[]", function()
require("nvim-treesitter-textobjects.move").goto_previous_end("@class.outer", "textobjects")
end)

-- Go to either the start or the end, whichever is closer.
-- Use if you want more granular movements
vim.keymap.set({ "n", "x", "o" }, "]d", function()
require("nvim-treesitter-textobjects.move").goto_next("@conditional.outer", "textobjects")
end)
vim.keymap.set({ "n", "x", "o" }, "[d", function()
require("nvim-treesitter-textobjects.move").goto_previous("@conditional.outer", "textobjects")
end)
```

</details>
Expand Down Expand Up @@ -460,7 +421,6 @@ enable the gopls. If you want to use your own gopls setup, you can set it to fal
'ray-x/go.nvim',
dependencies = {
'ray-x/guihua.lua', -- optional
'nvim-treesitter/nvim-treesitter',
'neovim/nvim-lspconfig',
},
opts = {} -- by default lsp_cfg = false
Expand Down Expand Up @@ -559,7 +519,6 @@ The following vimrc will enable all features provided by go.nvim
set termguicolors
call plug#begin('~/.vim/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-treesitter/nvim-treesitter'

Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
Expand Down
1 change: 0 additions & 1 deletion doc/go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ You can setup go.nvim with following options:
dap_retries = 20,
dap_enrich_config = nil,
build_tags = "", -- extra build tags for tests or debugger
textobjects = true, -- treesitter text objects
test_runner = "go", -- one of {"go", "richgo", "dlv", "ginkgo", "gotestsum"}
run_in_floaterm = false, -- run commands in float window
floaterm = {
Expand Down
12 changes: 1 addition & 11 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ local plugin_dir = vim.fn.expand('~/.local/share/nvim/site/pack/vendor/start')
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')

Expand Down Expand Up @@ -51,16 +47,10 @@ require('go').setup({

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
if not require('go.treesitter').are_parsers_installed({ 'go' }) then
error('No queries for go found')
end
pcall(vim.treesitter.start)
Expand Down
10 changes: 0 additions & 10 deletions lua/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local vfn = vim.fn
-- Keep this in sync with README.md
-- Keep this in sync with doc/go.txt
_GO_NVIM_CFG = {
treesitter_main = false,
disable_defaults = false, -- true|false when true disable all default settings, user need to set all settings
remap_commands = {}, -- Vim commands to remap or disable, e.g. `{ GoFmt = "GoFormat", GoDoc = false }`
go = 'go', -- set to go1.18beta1 if necessary
Expand Down Expand Up @@ -134,7 +133,6 @@ _GO_NVIM_CFG = {
dap_enrich_config = nil, -- see dap option enrich_config
dap_retries = 20, -- see dap option max_retries
build_tags = '', --- you can provide extra build tags for tests or debugger
textobjects = true, -- treesitter binding for text objects
test_runner = 'go', -- one of {`go`, `richgo`, `dlv`, `ginkgo`, `gotestsum`}
verbose_tests = false, -- set to add verbose flag to tests deprecated see '-v'
run_in_floaterm = false, -- set to true to run in float window.
Expand Down Expand Up @@ -229,10 +227,6 @@ function go.setup(cfg)
}
end

-- ts master branch use nvim-treesitter.configs
-- ts main branch use nvim-treesitter.config
local has_ts_main = pcall(require, 'nvim-treesitter.config')
_GO_NVIM_CFG.treesitter_main = has_ts_main
-- legacy options
if type(cfg.null_ls) == 'boolean' then
vim.notify('go.nvim config: null_ls=boolean deprecated, refer to README for more info', vim.log.levels.WARN)
Expand Down Expand Up @@ -305,10 +299,6 @@ function go.setup(cfg)
require('go.codelens').setup()
end

if _GO_NVIM_CFG.textobjects then
require('go.ts.textobjects').setup()
end

require('go.env').setup()
end, 1)

Expand Down
10 changes: 3 additions & 7 deletions lua/go/asyncmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ local trace = util.trace
local getopt = require('go.alt_getopt')

local is_windows = util.is_windows()
local is_git_shell = is_windows
and (vim.fn.exists('$SHELL') and vim.fn.expand('$SHELL'):find('bash.exe') ~= nil)
local is_git_shell = is_windows and (vim.fn.exists('$SHELL') and vim.fn.expand('$SHELL'):find('bash.exe') ~= nil)

local function compile_efm()
local efm = [[%-G#\ %.%#]]
Expand Down Expand Up @@ -65,10 +64,7 @@ function M.make(...)
end
end
if vim.fn.empty(makeprg) == 0 and args[1] == 'go' then
vim.notify(
'makeprg is already set to ' .. makeprg .. ' args: ' .. vim.inspect(args),
vim.log.levels.WARN
)
vim.notify('makeprg is already set to ' .. makeprg .. ' args: ' .. vim.inspect(args), vim.log.levels.WARN)
end
-- local indent = "%\\%( %\\)"
if not makeprg then
Expand Down Expand Up @@ -286,7 +282,7 @@ M.runjob = function(cmd, runner, args, efm)
end
if next(errorlines) ~= nil and runner == 'golangci-lint' then
efm =
[[level=%tarning\ msg="%m:\ [%f:%l:%c:\ %.%#]",level=%tarning\ msg="%m",level=%trror\ msg="%m:\ [%f:%l:%c:\ %.%#]",level=%trror\ msg="%m",%f:%l:%c:\ %m,%f:%l:\ %m,%f:%l\ %m]]
[[level=%tarning\ msg="%m:\ [%f:%l:%c:\ %.%#]",level=%tarning\ msg="%m",level=%trror\ msg="%m:\ [%f:%l:%c:\ %.%#]",level=%trror\ msg="%m",%f:%l:%c:\ %m,%f:%l:\ %m,%f:%l\ %m]]
end

sprite.on_close()
Expand Down
21 changes: 10 additions & 11 deletions lua/go/coverage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ M.run = function(...)
else
table.remove(args, 1)
local test_coverage = M.read_cov(covfn)
vim.notify(string.format('total coverage: %d%%', test_coverage.total_covered / test_coverage.total_lines * 100),
vim.log.levels.INFO)
vim.notify(string.format('total coverage: %d%%', test_coverage.total_covered / test_coverage.total_lines * 100), vim.log.levels.INFO)
return test_coverage
end
arg = select(2, ...)
Expand Down Expand Up @@ -431,15 +430,15 @@ M.run = function(...)

vim.notify(
'go coverage finished with message: '
.. vim.inspect(cmd)
.. 'error: '
.. vim.inspect(data)
.. '\n'
.. 'job '
.. tostring(job_id)
.. '\n'
.. 'ev '
.. event,
.. vim.inspect(cmd)
.. 'error: '
.. vim.inspect(data)
.. '\n'
.. 'job '
.. tostring(job_id)
.. '\n'
.. 'ev '
.. event,
vim.log.levels.WARN
)
end,
Expand Down
Loading
Loading