Skip to content

Commit

Permalink
nvim: Replace vim-go with go.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioCarrion committed Feb 25, 2024
1 parent 16da614 commit 78c8350
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 132 deletions.
3 changes: 2 additions & 1 deletion 2023/01/nvim/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# neovim

* [JetBrains font](https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/JetBrainsMono.zip)
* [JetBrains font](https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/JetBrainsMono.zip): install
JetBrainsMono Neerd Font Mono

## Install

Expand Down
2 changes: 2 additions & 0 deletions 2023/01/nvim/ftdetect/markdown.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vim.opt.textwidth = 0
vim.opt.wrapmargin=0
4 changes: 3 additions & 1 deletion 2023/01/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ require("plugins.setup")
require("plugins.default")

require("plugins.lualine")
require("plugins.barbar")
require("plugins.nvim-tree")
require("plugins.comment")
require("plugins.telescope")
require("plugins.nvim-treesitter")
require("plugins.gitsigns")
require("plugins.nvim-cmp")
require("plugins.catppuccin-theme")
require("plugins.barbar")
require("plugins.nvim-surround")
require("plugins.go")
require("plugins.navigator")
33 changes: 18 additions & 15 deletions 2023/01/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"barbar.nvim": { "branch": "master", "commit": "4ba9ac54f0c5d82131905160afff94172e3325e6" },
"catppuccin": { "branch": "main", "commit": "079500a625f3ae5aa6efb758f1a17fe4c7a57e52" },
"barbar.nvim": { "branch": "master", "commit": "c3ab0dbfe143ffb89a245e5b530f5349d6bb64e1" },
"catppuccin": { "branch": "main", "commit": "c2034f7b549152e5cc757820426341ea5000bc7a" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-nvim-ultisnips": { "branch": "main", "commit": "24bca5c3e137b28cd87442d4fc51a2b312dd99cc" },
"csv.vim": { "branch": "master", "commit": "962f88787ec6873eba1c7dbbd81d2723f1ee3c4b" },
"gitsigns.nvim": { "branch": "main", "commit": "d195f0c35ced5174d3ecce1c4c8ebb3b5bc23fa9" },
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
"lspkind-nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" },
"lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" },
"gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" },
"go.nvim": { "branch": "master", "commit": "24d2fa373d55d9900cd4b502a88214dc17e6fab6" },
"guihua.lua": { "branch": "master", "commit": "9fb6795474918b492d9ab01b1ebaf85e8bf6fe0b" },
"lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" },
"lsp_signature.nvim": { "branch": "master", "commit": "fed2c8389c148ff1dfdcdca63c2b48d08a50dea0" },
"lspkind-nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" },
"lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" },
"navigator.lua": { "branch": "master", "commit": "29d5f05bf9094cd0770018e19a27da81c247c503" },
"nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" },
"nvim-lsp-installer": { "branch": "main", "commit": "17e0bfa5f2c8854d1636fcd036dc8284db136baa" },
"nvim-lspconfig": { "branch": "master", "commit": "e85816c5803410cacb52e9b4fbdb72a1f1a6bd11" },
"nvim-lspconfig": { "branch": "master", "commit": "1759ea68fbbb1303192020d3e59936189359e0ed" },
"nvim-lspconfig-bundler": { "branch": "main", "commit": "9a27ba348a639cc191d16a16102fcdc2c5c58b48" },
"nvim-surround": { "branch": "main", "commit": "633a0ab03159569a66b65671b0ffb1a6aed6cf18" },
"nvim-tree.lua": { "branch": "master", "commit": "50f30bcd8c62ac4a83d133d738f268279f2c2ce2" },
"nvim-treesitter": { "branch": "master", "commit": "0dfbf5e48e8551212c2a9f1c74cb080c8e76b5d1" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a" },
"nvim-web-devicons": { "branch": "master", "commit": "a1425903ab52a0a0460622519e827f224e5b4fee" },
"plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" },
"nvim-surround": { "branch": "main", "commit": "703ec63aa798e5e07d309b35e42def34bebe0174" },
"nvim-tree.lua": { "branch": "master", "commit": "f39f7b6fcd3865ac2146de4cb4045286308f2935" },
"nvim-treesitter": { "branch": "master", "commit": "f197a15b0d1e8d555263af20add51450e5aaa1f0" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "19a91a38b02c1c28c14e0ba468d20ae1423c39b2" },
"nvim-web-devicons": { "branch": "master", "commit": "aaec87dbdaa776bfa0a13c8694bec9bcb7454719" },
"plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" },
"telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
"ultisnips": { "branch": "master", "commit": "b393ba65386d47664421e1f8b246a87a6e8b218c" },
"vim-clang-format": { "branch": "master", "commit": "6b791825ff478061ad1c57b21bb1ed5a5fd0eb29" },
"vim-go": { "branch": "master", "commit": "e8c18054cc44973ee4f59ee463dda4bf6439713c" }
"vim-clang-format": { "branch": "master", "commit": "6b791825ff478061ad1c57b21bb1ed5a5fd0eb29" }
}
4 changes: 2 additions & 2 deletions 2023/01/nvim/lua/plugins/barbar.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local setup, bufferline = pcall(require, "bufferline")
local setup, barbar = pcall(require, "barbar")
if not setup then return end

bufferline.setup({
barbar.setup({
clickable = false, -- Enables/disable clickable tabs
tabpages = true, -- Enable/disable current/total tabpages indicator (top right corner)
icons = {
Expand Down
1 change: 1 addition & 0 deletions 2023/01/nvim/lua/plugins/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ vim.opt.relativenumber = true
vim.opt.laststatus = 2
vim.opt.vb = true
vim.opt.ruler = true
vim.opt.spell = true
vim.opt.spelllang = "en_us"
vim.opt.autoindent = true
vim.opt.colorcolumn = "120"
Expand Down
77 changes: 77 additions & 0 deletions 2023/01/nvim/lua/plugins/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
local setup, go = pcall(require, "go")
if not setup then return end

local lsp_setup, go_lsp = pcall(require, "go.lsp")
if not lsp_setup then return end

local lspconfig_setup, lspconfig = pcall(require, "lspconfig")
if not lspconfig_setup then return end

local lsp_signature_setup, lsp_signature = pcall(require, "lsp_signature")
if not lsp_signature_setup then return end

go.setup({
gofmt = "gofmt"
-- run_in_floaterm = true,
-- floaterm = { -- position
-- posititon = 'auto', -- one of {`top`, `bottom`, `left`, `right`, `center`, `auto`}
-- width = 0.45, -- width of float window if not auto
-- height = 0.98, -- height of float window if not auto
-- title_colors = 'nord', -- default to nord, one of {'nord', 'tokyo', 'dracula', 'rainbow', 'solarized ', 'monokai'}
-- -- can also set to a list of colors to define colors to choose from
-- -- e.g {'#D8DEE9', '#5E81AC', '#88C0D0', '#EBCB8B', '#A3BE8C', '#B48EAD'}
-- },
})

lspconfig.gopls.setup(go_lsp.config())

vim.cmd("augroup go")
vim.cmd("autocmd!")

-- vim.cmd("autocmd FileType go nmap <leader>Gb :GoBuild %:.:h<CR>")
vim.cmd("autocmd FileType go nmap <leader>Gb :GoBuild %:p:h<CR>")
vim.cmd("autocmd FileType go nmap <leader>Gt :GoTestPkg<CR>")
vim.cmd("autocmd FileType go nmap <leader>Gc :GoCoverage -p<CR>")

-- vim.cmd("autocmd FileType go nmap <Leader>gc :lua require('go.comment').gen()")

-- vim.fn.getcwd()

-- vim.cmd("autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()")
--

vim.cmd(
"autocmd BufWritePre (InsertLeave?) <buffer> lua vim.lsp.buf.formatting_sync(nil,500)")

vim.cmd(
"autocmd Filetype go command! -bang A :lua require('go.alternate').switch(true, '')")
vim.cmd(
"autocmd Filetype go command! -bang AV :lua require('go.alternate').switch(true, 'vsplit')")
vim.cmd(
"autocmd Filetype go command! -bang AS :lua require('go.alternate').switch(true, 'split')")

vim.cmd("augroup END")

-- {

lsp_signature.setup({
auto_close_after = 1,
handler_opts = {
border = "rounded" -- double, rounded, single, shadow, none, or a table of borders
},
floating_window = true, -- show hint in a floating window, set to false for virtual text only mode
floating_window_off_x = 5, -- adjust float windows x position.
floating_window_off_y = function() -- adjust float windows y position. e.g. set to -2 can make floating window move up 2 lines
local linenr = vim.api.nvim_win_get_cursor(0)[1] -- buf line number
local pumheight = vim.o.pumheight
local winline = vim.fn.winline() -- line number in the window
local winheight = vim.fn.winheight(0)

-- window top
if winline - 1 < pumheight then return pumheight end

-- window bottom
if winheight - winline < pumheight then return -pumheight end
return 0
end
})
4 changes: 4 additions & 0 deletions 2023/01/nvim/lua/plugins/navigator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
local setup, navigator = pcall(require, "navigator")
if not setup then return end

navigator.setup()
71 changes: 0 additions & 71 deletions 2023/01/nvim/lua/plugins/nvim-cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,77 +33,6 @@ cmp.setup({

local capabilities = cmp_nvim_lsp.default_capabilities()

local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = {noremap = true, silent = true, buffer = bufnr}
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
end

lspconfig['gopls'].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
gopls = {
analyses = {
assign = true,
atomic = true,
bools = true,
composites = true,
copylocks = true,
deepequalerrors = true,
embed = true,
errorsas = true,
fieldalignment = false, -- XXX
httpresponse = true,
ifaceassert = true,
loopclosure = true,
lostcancel = true,
nilfunc = true,
nilness = true,
nonewvars = true,
printf = true,
shadow = false, -- XXX
shift = true,
simplifycompositelit = true,
simplifyrange = true,
simplifyslice = true,
sortslice = true,
stdmethods = true,
stringintconv = true,
structtag = true,
testinggoroutine = true,
tests = true,
timeformat = true,
unmarshal = true,
unreachable = true,
unsafeptr = true,
unusedparams = true,
unusedresult = true,
unusedvariable = true,
unusedwrite = true,
useany = true
},
hoverKind = "FullDocumentation",
linkTarget = "pkg.go.dev",
semanticTokens = true,
usePlaceholders = true,
vulncheck = "Imports"
}
}
}

lspconfig['pyright'].setup {}

lspconfig['solargraph'].setup {}
Expand Down
13 changes: 4 additions & 9 deletions 2023/01/nvim/lua/plugins/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@ vim.cmd([[
nnoremap - :NvimTreeToggle<CR>
]])

-- local keymap = vim.keymap -- for conciseness
-- keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>") -- toggle file explorer

-- vim.opt.foldmethod = "expr"
-- vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
-- vim.opt.foldenable = false -- " Disable folding at startup.

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.opt.termguicolors = true

local HEIGHT_RATIO = 0.8 -- You can change this
local WIDTH_RATIO = 0.5 -- You can change this too
local HEIGHT_RATIO = 0.8
local WIDTH_RATIO = 0.5

nvimtree.setup({
disable_netrw = true,
hijack_netrw = true,
respect_buf_cwd = true,
hijack_cursor = true,
sync_root_with_cwd = true,
update_focused_file = {enable = true, update_root = true},
view = {
relativenumber = true,
float = {
Expand Down
25 changes: 0 additions & 25 deletions 2023/01/nvim/lua/plugins/nvim-treesitter.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
local setup, treesitter = pcall(require, "nvim-treesitter.configs")
if not setup then return end

vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
vim.opt.foldenable = false

local vim = vim
local api = vim.api
local M = {}
function M.nvim_create_augroups(definitions)
for group_name, definition in pairs(definitions) do
api.nvim_command('augroup ' .. group_name)
api.nvim_command('autocmd!')
for _, def in ipairs(definition) do
local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
api.nvim_command(command)
end
api.nvim_command('augroup END')
end
end

local autoCommands = {
open_folds = {{"BufReadPost,FileReadPost", "*", "normal zR"}}
}

M.nvim_create_augroups(autoCommands)

treesitter.setup {
ensure_installed = {
"dockerfile", "gitignore", "go", "gomod", "gowork", "javascript",
Expand Down
34 changes: 30 additions & 4 deletions 2023/01/nvim/lua/plugins/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ require("lazy").setup({
"romgrk/barbar.nvim",
dependencies = {
"nvim-tree/nvim-web-devicons", "lewis6991/gitsigns.nvim"
}
},
init = function() vim.g.barbar_auto_setup = false end,
},
{"nvim-lualine/lualine.nvim"},
{"nvim-tree/nvim-tree.lua", dependencies = {"nvim-tree/nvim-web-devicons"}},
{
"nvim-tree/nvim-tree.lua",
dependencies = {"nvim-tree/nvim-web-devicons"},
tag = "v0.99",
},
{"nvim-telescope/telescope-fzf-native.nvim", build = "make"},
{
"nvim-telescope/telescope.nvim",
Expand All @@ -33,11 +38,32 @@ require("lazy").setup({
-- Development
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate"
tag = "v0.9.2",
build = ":TSUpdate",
},
{"nvim-treesitter/nvim-treesitter-textobjects"},
{"rhysd/vim-clang-format"},
{"fatih/vim-go"},
{
"ray-x/go.nvim",
dependencies = { -- optional packages
"ray-x/guihua.lua",
"neovim/nvim-lspconfig",
"nvim-treesitter/nvim-treesitter",
},
event = {"CmdlineEnter"},
ft = {"go", 'gomod'},
},
{
"ray-x/navigator.lua",
requires = {
{ "ray-x/guihua.lua", run = "cd lua/fzy && make" },
{ "neovim/nvim-lspconfig" },
},
},
{
"ray-x/lsp_signature.nvim",
event = "VeryLazy",
},
{"SirVer/ultisnips"},
{"hrsh7th/cmp-nvim-lsp"},
{"hrsh7th/nvim-cmp"},
Expand Down
13 changes: 9 additions & 4 deletions 2023/01/nvim/lua/plugins/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ telescope.setup({
telescope.load_extension("fzf")

local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})

vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) -- Lists files in your current working directory, respects .gitignore
-- vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) -- Searches for the string under your cursor or selection in your current working directory
-- vim.keymap.set('n', '<leader>fb', builtin.buffers, {}) -- Lists open buffers in current neovim instance
-- vim.keymap.set('n', '<leader>fh', builtin.help_tags, {}) -- Lists available help tags and opens a new window with the relevant help info on <cr>
vim.keymap.set('n', '<leader>fx', builtin.treesitter, {})
vim.keymap.set('n', '<leader>fr', builtin.lsp_references, {}) -- Lists LSP references for word under the cursor
-- vim.keymap.set('n', '<leader>fi', builtin.lsp_implementations, {}) -- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
-- vim.keymap.set('n', '<leader>fd', builtin.lsp_definitions, {}) -- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope

0 comments on commit 78c8350

Please sign in to comment.