Skip to content

Commit

Permalink
fix(nvim): go.nvim setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed May 24, 2024
1 parent b756224 commit d402285
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 36 deletions.
1 change: 1 addition & 0 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ if has('autocmd') " vim-tiny does not have autocmd
" :open 无法使用通配符,不能使用wildmode
" :next 可以打开多个文件
command! -nargs=1 FindFilesToQf call SystemToQf('find . -name "*' . <q-args> . '*" | xargs file | sed "s/:/:1:/"')
command! -nargs=1 FdToQf call noplug#SystemToQf('fd ' . <q-args> . ' | xargs file | sed "s/:/:1:/"')

" neovim 0.10.0 uses ripgrep as greppg by default
command! -nargs=1 RgToQf call SystemToQf('rg --vimgrep ' . <q-args>)
Expand Down
36 changes: 29 additions & 7 deletions install/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,49 @@ function install_rg_fd() {
"
else
# ripgrep:
# any-jump.vim cpp需要PCRE2 feature
# Ubuntu18.04 需要前往https://github.com/BurntSushi/ripgrep/releases
# 下载.deb文件(ripgrep_14.1.0-1_amd64.deb 可以用)
sudo apt-get install -y ripgrep fd-find

# 输出结果
if [ "$path_found" = false ]; then
echo "$path_to_check is in \$PATH"
else
echo "$path_to_check is not in \$PATH"
fi

ln -s $(which fdfind) $HOME/.local/bin/fd
prompt=$prompt"
=== fd ===
请检查 $HOME/.local/bin/fd 是否在 \$PATH 中
"
fi
}

function install_other_apt_packages() {
# ripgrep:
# any-jump.vim cpp需要PCRE2 feature
# Ubuntu18.04 需要前往https://github.com/BurntSushi/ripgrep/releases
# 下载.deb文件(ripgrep_14.1.0-1_amd64.deb 可以用)
#
# apt install -y golang
# Leaderf needs python3-dev and python3-distutils
# wamerican: American English字典文件,安装后位于/usr/share/dict/american-english, 用于vim dictionary
# wordnet: nvim cmp dictionary 可以用wordnet解释单词
sudo apt-get install -y curl ripgrep fd-find tree bat git cmake sqlformat python3-dev python3-distutils wamerican
sudo apt-get install -y curl tree bat git cmake sqlformat python3-dev python3-distutils wamerican

# ripgrep-all(master分支)
# See: https://github.com/phiresky/ripgrep-all/issues/113
# apt install ripgrep pandoc poppler-utils ffmpeg
}

_cargo_installed=false
function install_cargo() {
if [ "$_cargo_installed" = false ]; then
_cargo_installed=true
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
fi
}

function install_git_delta() {
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
install_cargo
prompt=$prompt"
=== git-delta ===
source ~/.bashrc
Expand Down Expand Up @@ -114,6 +134,8 @@ function install_gvm() {
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
prompt=$prompt"
=== Go ===
必须确保GOPATH/bin在环境变量,保证gopls能找到。
不要用apt安装gopls,该版本为unknown,影响go.nvim插件解析。
source ~/.bashrc
gvm install go1.16.3
gvm use go1.16.3
Expand Down
4 changes: 2 additions & 2 deletions root/.config/nvim/lua/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ local function setup_lsp(on_attach, capabilities)
-- npm i -g vscode-langservers-extracted
-- "pylsp": too slow
-- "pylyzer": report too many diagnostics
local other_servers = { "jsonls", "basedpyright", "typst_lsp", "gopls", "cmake" }
local other_servers = { "jsonls", "basedpyright", "typst_lsp", "cmake" }
if vim.g.python_formatter == "ruff" then
-- pip install ruff-lsp ruff
table.insert(other_servers, "ruff_lsp")
Expand Down Expand Up @@ -195,7 +195,7 @@ function M.lspconfig()
})
vim.keymap.set("n", "<leader>da", vim.diagnostic.open_float)

setup_lsp(M.on_attach, M.capabilities)
setup_lsp(M.on_attach, M.get_capabilities())

-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
Expand Down
27 changes: 13 additions & 14 deletions root/.config/nvim/lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,19 @@ return {
},
-- A graphical display window manager in neovim
-- {'altermo/nxwm',branch='x11'},
-- TODO: uncomment it when issue #236 https://github.com/sourcegraph/sg.nvim/issues/236 is fixed.
-- {
-- "sourcegraph/sg.nvim",
-- dependencies = {
-- "nvim-lua/plenary.nvim", --[[ "nvim-telescope/telescope.nvim ]]
-- },
-- config = function()
-- vim.keymap.set("n", "<leader>sg", function()
-- require("sg.extensions.telescope").fuzzy_search_results()
-- end)
-- end,
-- -- If you have a recent version of lazy.nvim, you don't need to add this!
-- build = "nvim -l build/init.lua",
-- },
{
"sourcegraph/sg.nvim",
dependencies = {
"nvim-lua/plenary.nvim", --[[ "nvim-telescope/telescope.nvim ]]
},
config = function()
vim.keymap.set("n", "<leader>sg", function()
require("sg.extensions.telescope").fuzzy_search_results()
end)
end,
-- If you have a recent version of lazy.nvim, you don't need to add this!
build = "nvim -l build/init.lua",
},

-- find and replace
{
Expand Down
20 changes: 7 additions & 13 deletions root/.config/nvim/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ if vim.g.vimrc_lsp == "nvim-lsp" then
ft = { "rust" },
},
{
-- NOTE: must ensure GOPATH/bin is in $PATH,
-- do not use apt install gopls, whose version is (unknown) and can not be parsed by go.nvim.
"ray-x/go.nvim",
dependencies = { -- optional packages
"ray-x/guihua.lua",
Expand All @@ -206,23 +208,15 @@ if vim.g.vimrc_lsp == "nvim-lsp" then
},
config = function()
require("go").setup({
-- debug
verbose = false,
lsp_cfg = {
on_attach = lsp.on_attach,
capabilities = lsp.get_capabilities(),
capabilities = require("lsp").get_capabilities(),
},
})
-- Run gofmt + goimports on save
local format_sync_grp = vim.api.nvim_create_augroup("goimports", {})
local lsp = require("lsp")
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
require("go.format").goimports()
end,
group = format_sync_grp,
-- after go.nvim's on_attach is called, then this on_attach will be called
lsp_on_client_start = require("lsp").on_attach,
})
end,
event = { "CmdlineEnter" },
ft = { "go", "gomod" },
-- 该命令在网络环境差的情况下可能会卡顿,故手动执行
-- build = ':lua require("go.install").update_all_sync()' -- if you need to install/update all binaries
Expand Down
1 change: 1 addition & 0 deletions root/.vim/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ if has('autocmd') " vim-tiny does not have autocmd
" :open 无法使用通配符,不能使用wildmode
" :next 可以打开多个文件
command! -nargs=1 FindFilesToQf call noplug#SystemToQf('find . -name "*' . <q-args> . '*" | xargs file | sed "s/:/:1:/"')
command! -nargs=1 FdToQf call noplug#SystemToQf('fd ' . <q-args> . ' | xargs file | sed "s/:/:1:/"')
" neovim 0.10.0 uses ripgrep as greppg by default
command! -nargs=1 RgToQf call noplug#SystemToQf('rg --vimgrep ' . <q-args>)

Expand Down

0 comments on commit d402285

Please sign in to comment.