Initial commit

neovim config with support for flutter, rust and go lsp.
some remaps.
some settings.
This commit is contained in:
Marco 2023-09-14 20:15:11 +02:00
commit 6737dcf50a
21 changed files with 488 additions and 0 deletions

View File

@ -0,0 +1,59 @@
local cmp = require ('cmp')
cmp.setup({
snippet = {
expand = function(args)
require('snippy').expand_snippet(args.body) -- For `snippy` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require('lspconfig')['gopls'].setup {
capabilities = capabilities
}

2
after/plugin/color.lua Normal file
View File

@ -0,0 +1,2 @@
vim.o.background = "dark" -- or "light" for light mode
vim.cmd([[colorscheme gruvbox]])

View File

@ -0,0 +1,21 @@
local dap = require('dap')
dap.adapters.dart = {
type = "executable",
-- As of this writing, this functionality is open for review in https://github.com/flutter/flutter/pull/91802
command = "flutter",
args = {"debug_adapter"}
}
dap.configurations.dart = {
{
type = "dart",
request = "launch",
name = "Launch Flutter Program",
-- The nvim-dap plugin populates this variable with the filename of the current buffer
program = "./lib/main.dart",
-- The nvim-dap plugin populates this variable with the editor's current working directory
cwd = "${workspaceFolder}",
-- This gets forwarded to the Flutter CLI tool, substitute `linux` for whatever device you wish to launch
toolArgs = {"-d", "linux"}
}
}

View File

@ -0,0 +1,3 @@
require('dap-go').setup()
vim.keymap.set('n', '<leader>td', function() require('dap-go').debug_test() end)

View File

@ -0,0 +1,12 @@
require("dapui").setup()
local dap, dapui = require("dap"), require("dapui")
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end

View File

@ -0,0 +1,24 @@
vim.keymap.set('n', '<F5>', function() require('dap').continue() end)
vim.keymap.set('n', '<F10>', function() require('dap').step_over() end)
vim.keymap.set('n', '<F11>', function() require('dap').step_into() end)
vim.keymap.set('n', '<F12>', function() require('dap').step_out() end)
vim.keymap.set('n', '<Leader>b', function() require('dap').toggle_breakpoint() end)
vim.keymap.set('n', '<Leader>B', function() require('dap').set_breakpoint() end)
vim.keymap.set('n', '<Leader>lp', function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) end)
vim.keymap.set('n', '<Leader>dr', function() require('dap').repl.open() end)
vim.keymap.set('n', '<Leader>dl', function() require('dap').run_last() end)
vim.keymap.set({'n', 'v'}, '<Leader>dh', function()
require('dap.ui.widgets').hover()
end)
vim.keymap.set({'n', 'v'}, '<Leader>dp', function()
require('dap.ui.widgets').preview()
end)
vim.keymap.set('n', '<Leader>df', function()
local widgets = require('dap.ui.widgets')
widgets.centered_float(widgets.frames)
end)
vim.keymap.set('n', '<Leader>ds', function()
local widgets = require('dap.ui.widgets')
widgets.centered_float(widgets.scopes)
end)

View File

@ -0,0 +1,5 @@
vim.api.nvim_set_keymap('n', '<leader>do', '<cmd>lua vim.diagnostic.open_float()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>d[', '<cmd>lua vim.diagnostic.goto_prev()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>d]', '<cmd>lua vim.diagnostic.goto_next()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>dd', '<cmd>Telescope diagnostics<CR>', { noremap = true, silent = true })

View File

@ -0,0 +1,10 @@
vim.api.nvim_create_autocmd('FileType', {
pattern = 'sh',
callback = function()
vim.lsp.start({
print("Bash lsp started");
name = 'bash-language-server',
cmd = { 'bash-language-server', 'start' },
})
end,
})

View File

@ -0,0 +1,22 @@
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(ev)
local opts = { noremap=true, silent=false, buffer = ev.buf }
vim.keymap.set('n', '<leader>gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.keymap.set('n', '<leader>ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.keymap.set('n', '<leader>gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.keymap.set('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.keymap.set('n', '<leader>gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.keymap.set('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.keymap.set('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.keymap.set('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.keymap.set('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float({scope="buffer"})<CR>', opts)
vim.keymap.set('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
vim.keymap.set('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
vim.keymap.set('n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
vim.keymap.set('n', '<leader>gd', function() vim.lsp.buf.definition() end, opts)
vim.keymap.set('n', '<leader>fo', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})

View File

@ -0,0 +1 @@
require('flutter-tools').setup {}

View File

@ -0,0 +1,19 @@
local nvim_lsp = require ('lspconfig')
local on_attach = function(client, bufnr)
end
nvim_lsp.gopls.setup{
cmd = {'gopls'},
filetypes = {"go", "gomod"},
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
on_attach = on_attach,
}

View File

@ -0,0 +1,12 @@
local rt = require("rust-tools")
rt.setup({
server = {
on_attach = function(_, bufnr)
-- Hover actions
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
-- Code action groups
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
end,
},
})

View File

@ -0,0 +1,2 @@
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})

View File

@ -0,0 +1,27 @@
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all" (the five listed parsers should always be installed)
ensure_installed = { "go", "rust", "toml", "c", "lua", "vim", "vimdoc", "query" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
highlight = {
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
ident = { enable = true },
rainbow = {
enable = true,
extended_mode = true,
max_file_lines = nil,
}
}

View File

@ -0,0 +1 @@
vim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)

1
init.lua Normal file
View File

@ -0,0 +1 @@
require("myworkflow")

3
lua/myworkflow/init.lua Normal file
View File

@ -0,0 +1,3 @@
require("myworkflow.remap")
require("myworkflow.set")
require("myworkflow.packer")

36
lua/myworkflow/packer.lua Normal file
View File

@ -0,0 +1,36 @@
-- Only required if you have packer configured as `opt`
vim.cmd [[packadd packer.nvim]]
return require('packer').startup(function(use)
use { 'nvim-telescope/telescope.nvim',
requires = { { 'nvim-lua/plenary.nvim' } }
}
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use 'mbbill/undotree'
use('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' })
-- Colors
use 'ellisonleao/gruvbox.nvim'
-- LSP
use 'neovim/nvim-lspconfig'
use 'simrat39/rust-tools.nvim'
use 'akinsho/flutter-tools.nvim'
-- debugging
use 'mfussenegger/nvim-dap'
use 'leoluz/nvim-dap-go'
use 'rcarriga/nvim-dap-ui'
-- Autocompletion
use 'hrsh7th/cmp-nvim-lsp'
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-cmdline'
use 'hrsh7th/nvim-cmp'
-- Snippets (not really sure what this is for)
use 'dcampos/nvim-snippy'
use 'dcampos/cmp-snippy'
end)

7
lua/myworkflow/remap.lua Normal file
View File

@ -0,0 +1,7 @@
vim.g.mapleader = " "
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
vim.keymap.set("i", "<C-c>", "<Esc>")

32
lua/myworkflow/set.lua Normal file
View File

@ -0,0 +1,32 @@
vim.opt.nu = true
vim.opt.rnu = true
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.wrap = false
vim.opt.termguicolors = true
vim.opt.colorcolumn = "80"
vim.opt.hlsearch = true
vim.opt.incsearch = true
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
vim.opt.undofile = true
vim.opt.scrolloff = 8
vim.opt.signcolumn = "yes"
vim.opt.isfname:append("@-@")
vim.opt.updatetime = 50
vim.o.mouse = 'a'

189
plugin/packer_compiled.lua Normal file
View File

@ -0,0 +1,189 @@
-- Automatically generated packer.nvim plugin loader code
if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then
vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"')
return
end
vim.api.nvim_command('packadd packer.nvim')
local no_errors, error_msg = pcall(function()
_G._packer = _G._packer or {}
_G._packer.inside_compile = true
local time
local profile_info
local should_profile = false
if should_profile then
local hrtime = vim.loop.hrtime
profile_info = {}
time = function(chunk, start)
if start then
profile_info[chunk] = hrtime()
else
profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6
end
end
else
time = function(chunk, start) end
end
local function save_profiles(threshold)
local sorted_times = {}
for chunk_name, time_taken in pairs(profile_info) do
sorted_times[#sorted_times + 1] = {chunk_name, time_taken}
end
table.sort(sorted_times, function(a, b) return a[2] > b[2] end)
local results = {}
for i, elem in ipairs(sorted_times) do
if not threshold or threshold and elem[2] > threshold then
results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms'
end
end
if threshold then
table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)')
end
_G._packer.profile_output = results
end
time([[Luarocks path setup]], true)
local package_path_str = "/home/m/.cache/nvim/packer_hererocks/2.1.1692616192/share/lua/5.1/?.lua;/home/m/.cache/nvim/packer_hererocks/2.1.1692616192/share/lua/5.1/?/init.lua;/home/m/.cache/nvim/packer_hererocks/2.1.1692616192/lib/luarocks/rocks-5.1/?.lua;/home/m/.cache/nvim/packer_hererocks/2.1.1692616192/lib/luarocks/rocks-5.1/?/init.lua"
local install_cpath_pattern = "/home/m/.cache/nvim/packer_hererocks/2.1.1692616192/lib/lua/5.1/?.so"
if not string.find(package.path, package_path_str, 1, true) then
package.path = package.path .. ';' .. package_path_str
end
if not string.find(package.cpath, install_cpath_pattern, 1, true) then
package.cpath = package.cpath .. ';' .. install_cpath_pattern
end
time([[Luarocks path setup]], false)
time([[try_loadstring definition]], true)
local function try_loadstring(s, component, name)
local success, result = pcall(loadstring(s), name, _G.packer_plugins[name])
if not success then
vim.schedule(function()
vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {})
end)
end
return result
end
time([[try_loadstring definition]], false)
time([[Defining packer_plugins]], true)
_G.packer_plugins = {
["cmp-buffer"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/cmp-buffer",
url = "https://github.com/hrsh7th/cmp-buffer"
},
["cmp-cmdline"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/cmp-cmdline",
url = "https://github.com/hrsh7th/cmp-cmdline"
},
["cmp-nvim-lsp"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
url = "https://github.com/hrsh7th/cmp-nvim-lsp"
},
["cmp-path"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/cmp-path",
url = "https://github.com/hrsh7th/cmp-path"
},
["cmp-snippy"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/cmp-snippy",
url = "https://github.com/dcampos/cmp-snippy"
},
["flutter-tools.nvim"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/flutter-tools.nvim",
url = "https://github.com/akinsho/flutter-tools.nvim"
},
["gruvbox.nvim"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/gruvbox.nvim",
url = "https://github.com/ellisonleao/gruvbox.nvim"
},
["nvim-cmp"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/nvim-cmp",
url = "https://github.com/hrsh7th/nvim-cmp"
},
["nvim-dap"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/nvim-dap",
url = "https://github.com/mfussenegger/nvim-dap"
},
["nvim-dap-go"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/nvim-dap-go",
url = "https://github.com/leoluz/nvim-dap-go"
},
["nvim-dap-ui"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/nvim-dap-ui",
url = "https://github.com/rcarriga/nvim-dap-ui"
},
["nvim-lspconfig"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
url = "https://github.com/neovim/nvim-lspconfig"
},
["nvim-snippy"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/nvim-snippy",
url = "https://github.com/dcampos/nvim-snippy"
},
["nvim-treesitter"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
url = "https://github.com/nvim-treesitter/nvim-treesitter"
},
["packer.nvim"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/packer.nvim",
url = "https://github.com/wbthomason/packer.nvim"
},
["plenary.nvim"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/plenary.nvim",
url = "https://github.com/nvim-lua/plenary.nvim"
},
["rust-tools.nvim"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/rust-tools.nvim",
url = "https://github.com/simrat39/rust-tools.nvim"
},
["telescope.nvim"] = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/telescope.nvim",
url = "https://github.com/nvim-telescope/telescope.nvim"
},
undotree = {
loaded = true,
path = "/home/m/.local/share/nvim/site/pack/packer/start/undotree",
url = "https://github.com/mbbill/undotree"
}
}
time([[Defining packer_plugins]], false)
_G._packer.inside_compile = false
if _G._packer.needs_bufread == true then
vim.cmd("doautocmd BufRead")
end
_G._packer.needs_bufread = false
if should_profile then save_profiles() end
end)
if not no_errors then
error_msg = error_msg:gsub('"', '\\"')
vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None')
end