582 lines
17 KiB
Lua
Raw Normal View History

2023-07-14 16:21:54 -04:00
-- theming
-- Default options
2023-09-04 10:14:39 -04:00
vim.opt.termguicolors = true
vim.cmd.colorscheme 'duskfox'
2023-07-14 16:21:54 -04:00
2023-07-20 10:48:23 -04:00
-- turn on relative line numbers
vim.opt.relativenumber = true
2023-08-14 11:43:36 -04:00
vim.opt.number = true
2023-09-21 09:38:23 -04:00
vim.opt.expandtab = true
vim.opt.paste = false
vim.opt.autoindent = true
vim.opt.linebreak = true
vim.opt.mouse = ""
2023-10-28 09:18:46 -04:00
-- neovim tabstop and shift behavior got more complicated.
-- This should cover all the cases though
2023-09-21 09:38:23 -04:00
vim.opt.tabstop = 4
2023-10-28 09:18:46 -04:00
vim.opt.shiftwidth = 4
--vim.opt.smarttab = false
2023-08-17 15:34:36 -04:00
2023-08-18 16:57:12 -04:00
vim.g.BASH_AuthorName = 'Jeremy Wall'
vim.g.BASH_AuthorRef = 'jw'
vim.g.BASH_Email = 'jeremy@marzhillstudios.com'
-- We want to use a different leader key
vim.g.mapleader = ','
2023-08-17 15:34:36 -04:00
vim.cmd("noswapfile")
vim.cmd("syntax on")
vim.cmd("filetype plugin on")
vim.cmd([[
au BufNewFile,BufRead *Makefile,*.mk set noexpandtab
]])
vim.cmd([[
au BufNewFile,BufRead *.py,*.java set tabstop=2
]])
vim.cmd([[
au BufNewFile,BufRead *.app set filetype=erlang
]])
2023-10-28 09:18:46 -04:00
vim.cmd([[
au BufNewFile,BufRead *.tf set filetype=terraform
]])
2023-11-22 18:08:31 -05:00
vim.cmd([[
au BufNewFile,BufRead *.hcl,*.hcl2 set filetype=hcl
]])
2023-08-17 15:34:36 -04:00
vim.cmd([[
au BufNewFile,BufRead .bash_* set filetype=sh
]])
vim.cmd([[
au BufNewFile,BufRead *.sil set filetype=tex
]])
vim.cmd([[
au BufNewFile,BufRead *.erl filetype indent off
]])
vim.cmd([[
au BufNewFile,BufRead *.hrl filetype indent off
]])
2023-07-20 10:48:23 -04:00
--
2023-07-14 16:21:54 -04:00
--https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- TODO(jwall): See about proper snippet support (ie. license comments?)
local cmp = require('cmp')
cmp.setup({
-- Enable LSP snippets
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-k>'] = cmp.mapping.select_prev_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
},
-- Installed sources:
sources = cmp.config.sources(
{
{ name = 'nvim_lsp', keyword_length = 3 }, -- from language server
2024-01-31 20:52:11 -05:00
{ name = 'nvim_lsp_signature_help' }, -- display function signatures with current parameter emphasized
},
{
{ name = 'path' }, -- file paths
},
{
{ name = 'nvim_lua', keyword_length = 2 }, -- complete neovim's Lua runtime API such vim.lsp.*
{ name = 'buffer', keyword_length = 2 }, -- source current buffer
{ name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip
}),
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
2023-09-04 10:14:39 -04:00
},
})
2023-07-14 16:21:54 -04:00
-- logging
--vim.lsp.set_log_level('trace')
--vim.lsp.log.set_format_func(vim.inspect)
local caps = vim.tbl_deep_extend(
'force',
vim.lsp.protocol.make_client_capabilities(),
require('cmp_nvim_lsp').default_capabilities(),
-- File watching is disabled by default for neovim.
-- See: https://github.com/neovim/neovim/pull/22405
{ workspace = { didChangeWatchedFiles = { dynamicRegistration = true } } },
{ window = { progress = false } }
);
2024-01-09 08:30:42 -05:00
2023-07-20 10:48:23 -04:00
local lspconfig = require("lspconfig")
2023-10-28 09:18:46 -04:00
-- Terraform lsp setup
lspconfig.terraformls.setup {}
2023-10-28 09:18:46 -04:00
2023-07-14 16:21:54 -04:00
-- Nix language server support
lspconfig.nil_ls.setup {
--single_file_support = true,
--on_attach = function(client, bufnr)
-- -- disable the semanticTokens because it has issues.
-- -- client.server_capabilities.semanticTokensProvider = nil
--end,
capabilities = caps,
}
2023-07-14 16:21:54 -04:00
--require('roslyn').setup({
-- on_attach = function (client, _)
-- --vim.notify(vim.inspect(client))
-- end,
-- capabilities = caps,
-- log_level = "Trace",
--});
2024-01-09 08:30:42 -05:00
2023-07-20 10:48:23 -04:00
local vim_pid = vim.fn.getpid()
2023-07-19 21:50:11 -04:00
-- "FormatterOptions:EnableEditorConfigSupport=true"
local omnisharp_cmd = { 'omnisharp', '--languageserver', '-v', '--hostPID', tostring(vim_pid), }
local function toSnakeCase(str)
return string.gsub(str, "%s*[- ]%s*", "_")
end
lspconfig.omnisharp.setup {
cmd = omnisharp_cmd,
enable_roslyn_analyzers = true,
enable_editorconfig_support = true,
enable_import_completion = true,
-- Omnisharp has issues with the semanticTokens feature we need to massage it a bit.
on_attach = function(client, bufnr)
-- https://github.com/OmniSharp/omnisharp-roslyn/issues/2483#issuecomment-1492605642
local tokenModifiers = client.server_capabilities.semanticTokensProvider.legend.tokenModifiers
for i, v in ipairs(tokenModifiers) do
tokenModifiers[i] = toSnakeCase(v)
end
local tokenTypes = client.server_capabilities.semanticTokensProvider.legend.tokenTypes
for i, v in ipairs(tokenTypes) do
tokenTypes[i] = toSnakeCase(v)
end
end,
handlers = {
["textDocument/definition"] = require('omnisharp_extended').handler,
},
capabilities = caps,
}
2023-07-14 16:21:54 -04:00
2023-07-30 15:15:42 -04:00
--ocaml
lspconfig.ocamllsp.setup {
capabilities = caps
2023-09-04 10:14:39 -04:00
}
2023-07-30 15:15:42 -04:00
2023-07-14 16:21:54 -04:00
-- Java language server support
lspconfig.java_language_server.setup {
capabilities = caps
2023-09-04 10:14:39 -04:00
}
2023-07-14 16:21:54 -04:00
-- Typescript language server support
lspconfig.tsserver.setup {
capabilities = caps
2023-09-04 10:14:39 -04:00
}
2023-07-14 16:21:54 -04:00
2023-07-16 22:21:45 -04:00
-- Rust language server support
lspconfig.rust_analyzer.setup {
2024-01-22 15:53:22 -05:00
settings = {
-- https://github.com/rust-lang/rust-analyzer/blob/master/docs/user/generated_config.adoc
2024-01-31 20:52:11 -05:00
['rust-analyzer'] = {
cargo = { features = "all" }
}
2024-01-22 15:53:22 -05:00
},
capabilities = caps
}
2023-07-20 10:48:23 -04:00
-- lua language server setup.
lspconfig.lua_ls.setup {
settings = {
Lua = {
runtime = { version = 'LuaJIT', },
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { 'vim' },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
-- Disable the checkThirdParty prompts.
checkThirdParty = false,
},
telemetry = {
enable = false,
},
},
},
capabilities = caps
}
2023-07-16 22:21:45 -04:00
-- lsp configuration
2023-07-14 16:21:54 -04:00
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local opts = { buffer = args.buf }
vim.keymap.set("n", '<C-Space>', function()
vim.lsp.buf.hover()
end, opts)
vim.keymap.set({ "n", "v" }, "<Leader>a", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<Leader>f", vim.lsp.buf.format, opts)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.server_capabilities.codelens then
vim.lsp.codelens.refresh()
end
end,
2023-07-14 16:21:54 -04:00
})
vim.api.nvim_create_autocmd({ 'BufEnter', 'InsertLeave', 'CursorHold' }, {
2023-08-28 14:08:20 -04:00
callback = function(_)
local clients = vim.lsp.get_active_clients()
for cid = 1, #clients do
if clients[cid].server_capabilities.codelens then
vim.lsp.codelens.refresh()
break
2023-08-28 14:08:20 -04:00
end
2023-08-22 17:53:41 -04:00
end
end,
})
-- LSP Diagnostics Options Setup
2023-07-14 16:21:54 -04:00
local sign = function(opts)
vim.fn.sign_define(opts.name, {
texthl = opts.name,
text = opts.text,
numhl = ''
})
2023-07-14 16:21:54 -04:00
end
sign({ name = 'DiagnosticSignError', text = '🔥' })
sign({ name = 'DiagnosticSignWarn', text = '⚠️' })
sign({ name = 'DiagnosticSignHint', text = '➡️' })
sign({ name = 'DiagnosticSignInfo', text = '🗒️' })
2023-07-14 16:21:54 -04:00
vim.diagnostic.config({
virtual_text = false,
signs = true,
update_in_insert = true,
underline = true,
severity_sort = false,
float = {
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
})
vim.cmd([[
set signcolumn=yes
autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false })
]])
--Set completeopt to have a better completion experience
-- :help completeopt
-- menuone: popup even when there's only one match
-- noinsert: Do not insert text until a selection is made
-- noselect: Do not select, force to select one from the menu
-- shortness: avoid showing extra messages when using completion
-- updatetime: set updatetime for CursorHold
vim.opt.completeopt = { 'menuone', 'noselect', 'noinsert' }
vim.opt.shortmess = vim.opt.shortmess + { c = true }
2023-09-15 16:44:38 -04:00
vim.api.nvim_set_option('updatetime', 300)
vim.opt.sessionoptions = { 'buffers', 'curdir', 'skiprtp', 'localoptions', 'terminal', 'tabpages' }
2023-07-14 16:21:54 -04:00
-- Fixed column for diagnostics to appear
-- Show autodiagnostic popup on cursor hover_range
-- Goto previous / next diagnostic warning / error
-- Show inlay_hints more frequently
2023-07-14 16:21:54 -04:00
vim.cmd([[
set signcolumn=yes
autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false })
]])
-- Treesitter Plugin Setup
2023-10-28 09:18:46 -04:00
2023-07-14 16:21:54 -04:00
require('nvim-treesitter.configs').setup {
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
indent = { enable = true },
rainbow = {
enable = true,
extended_mode = true,
max_file_lines = nil,
},
--textobjects = {
-- enable = true,
-- select = {
-- enable = true,
-- lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
-- keymaps = {
-- -- You can use the capture groups defined in textobjects.scm
-- ['aa'] = '@parameter.outer',
-- ['ia'] = '@parameter.inner',
-- ['af'] = '@function.outer',
-- ['if'] = '@function.inner',
-- ['ac'] = '@class.outer',
-- ['ic'] = '@class.inner',
-- },
-- },
--},
--incremental_selection = {
-- enable = true,
-- keymaps = {
-- init_selection = '<Leader>c',
-- node_incremental = '<Leader>c',
-- scope_incremental = '<Leader>ci',
-- node_decremental = '<Leader>cx',
-- },
--},
2023-08-22 17:53:41 -04:00
}
require 'treesitter-context'.setup {
2024-01-31 20:52:11 -05:00
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
max_lines = 5, -- How many lines the window should span. Values <= 0 mean no limit.
min_window_height = 45, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to collapse for a single context line
2024-01-31 20:52:11 -05:00
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
-- Separator between context and content. Should be a single character string, like '-'.
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
separator = nil,
2024-01-31 20:52:11 -05:00
zindex = 20, -- The Z-index of the context window
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
2023-07-14 16:21:54 -04:00
}
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true
2023-07-16 22:21:45 -04:00
-- setup nvim-tree
require("nvim-tree").setup {
2023-07-19 18:58:36 -04:00
hijack_unnamed_buffer_when_opening = true,
update_focused_file = {
enable = true,
},
renderer = {
icons = {
2023-07-19 18:58:36 -04:00
show = {
file = false,
},
glyphs = {
default = "-",
2023-07-19 18:58:36 -04:00
symlink = "S",
bookmark = "🎗",
modified = "",
folder = {
arrow_closed = "",
arrow_open = "",
default = "📁",
open = "📂",
empty = "📁",
empty_open = "📂",
symlink = "S",
symlink_open = "S",
},
git = {
unstaged = "",
staged = "",
unmerged = "",
renamed = "",
untracked = "",
deleted = "X",
ignored = "",
},
2023-07-19 18:58:36 -04:00
},
},
2023-09-15 16:44:38 -04:00
},
2023-07-19 18:58:36 -04:00
diagnostics = {
enable = true,
show_on_dirs = true,
icons = {
hint = "➡️",
info = "🗒️",
warning = "⚠️",
error = "🔥",
},
},
}
2023-07-16 21:20:15 -04:00
require('trouble').setup {
2023-07-20 10:48:23 -04:00
icons = false,
signs = {
hint = "➡️",
information = "🗒️",
warning = "⚠️",
error = "🔥",
other = "?",
},
}
2023-07-16 21:20:15 -04:00
vim.keymap.set("n", "<C-p>", function()
require("nvim-tree.api").tree.toggle()
end)
2023-07-16 22:21:45 -04:00
2023-07-20 14:09:01 -04:00
vim.keymap.set("n", "<Leader>tc", function()
vim.cmd("tabclose")
end)
2023-07-25 14:37:23 -04:00
vim.keymap.set("n", "<Leader>tn", function()
vim.cmd("tabnew")
end)
vim.keymap.set("n", "<Leader>tk", function()
2023-08-03 08:23:16 -04:00
vim.cmd("tabnext")
2023-07-25 14:37:23 -04:00
end)
vim.keymap.set("n", "<Leader>tj", function()
vim.cmd("tabprev")
end)
2023-07-20 14:09:01 -04:00
vim.keymap.set("n", "<Leader>ts", function()
vim.cmd("tabs")
end)
2023-07-31 10:34:26 -04:00
vim.keymap.set("n", "<Leader>mg", function()
vim.cmd("MagitOnly")
end)
require('possession').setup {
2023-09-11 10:26:01 -04:00
commands = {
save = 'SSave',
load = 'SLoad',
delete = 'SDelete',
list = 'SList',
},
autosave = {
current = true,
on_load = true,
on_quit = true,
},
telescope = {
list = {
default_action = 'load',
mappings = {
save = { n = '<c-x>', i = '<c-x>' },
load = { n = '<c-v>', i = '<c-v>' },
delete = { n = '<c-t>', i = '<c-t>' },
rename = { n = '<c-r>', i = '<c-r>' },
},
},
},
}
2023-08-14 11:43:36 -04:00
-- Telelscope configuration
local telescope = require('telescope')
2023-08-04 15:41:25 -04:00
local telescope_builtins = require('telescope.builtin')
2023-08-28 14:08:20 -04:00
local telescope_actions = require('telescope.actions')
2023-08-04 15:41:25 -04:00
2023-09-11 10:26:01 -04:00
telescope.load_extension('possession')
-- https://github.com/nvim-telescope/telescope.nvim
2023-08-14 11:43:36 -04:00
telescope.setup({
defaults = {
initial_mode = "normal",
2023-08-28 14:08:20 -04:00
mappings = {
n = {
["<Leader>ql"] = telescope_actions.send_selected_to_qflist + telescope_actions.open_qflist,
},
2023-08-28 14:08:20 -04:00
},
},
2023-08-14 11:43:36 -04:00
})
2023-08-04 15:41:25 -04:00
2023-12-08 18:03:17 -05:00
local harpoon = require('harpoon')
harpoon:setup()
2024-01-31 20:52:04 -05:00
local lean = require 'lean'
lean.setup {
lsp = {
on_attach = function(client, bufnr)
local opts = { buffer = bufnr }
vim.keymap.set({ "n", "v" }, "<Leader>ti", function() vim.cmd("LeanInfoviewToggle") end, opts)
vim.keymap.set({ "n", "v" }, "<Leader>sg", function() vim.cmd("LeanGoal") end, opts)
vim.keymap.set({ "n", "v" }, "<Leader>stg", function() vim.cmd("LeanTermGoal") end, opts)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
end
},
mappings = true,
2024-01-29 21:49:43 -05:00
}
2024-01-05 16:34:03 -05:00
-- telescope keymaps
vim.keymap.set("n", "<Leader>pl", telescope.extensions.possession.list)
2023-08-04 15:41:25 -04:00
vim.keymap.set("n", "<Leader>nff", telescope_builtins.fd)
2023-08-14 11:43:36 -04:00
vim.keymap.set("n", "<Leader>rl", telescope_builtins.lsp_references)
2023-08-17 15:34:36 -04:00
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename)
2023-08-14 11:43:36 -04:00
vim.keymap.set("n", "<Leader>sl", telescope_builtins.lsp_workspace_symbols)
2023-08-17 15:34:36 -04:00
vim.keymap.set("n", "<Leader>dl", telescope_builtins.diagnostics)
2023-08-18 16:57:35 -04:00
vim.keymap.set("n", "<Leader>rg", telescope_builtins.live_grep)
2023-08-14 11:43:36 -04:00
vim.keymap.set("n", "<Leader>bl", function() telescope_builtins.buffers({}) end)
2024-01-05 16:34:03 -05:00
-- harpoon keymaps
vim.keymap.set("n", "<Leader>ha", function() harpoon:list():append() end)
vim.keymap.set("n", "<Leader>he", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
vim.keymap.set("n", "<Leader>hj", function() harpoon:list():prev() end)
vim.keymap.set("n", "<Leader>hk", function() harpoon:list():next() end)
-- codelens keymaps
vim.keymap.set("n", "<Leader>rr", vim.lsp.codelens.run)
2023-08-04 15:41:25 -04:00
2024-01-05 16:34:03 -05:00
-- debugging DAP keymaps
vim.keymap.set("n", "<Leader>tdb", function()
vim.cmd("DBUIToggle")
end)
2023-08-28 14:08:20 -04:00
local dap = require('dap')
dap.adapters.lldb = {
type = "executable",
command = "/run/current-system/sw/bin/lldb",
name = "lldb",
}
dap.adapters.coreclr = {
type = 'executable',
command = '/run/current-system/sw/bin/netcoredbg',
args = { '--interpreter=vscode' }
}
dap.configurations.rust = {
{
name = 'Launch Rust',
type = 'lldb',
request = 'launch',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = false,
args = {},
},
}
dap.configurations.cs = {
{
name = "Launch - netcoredbg",
type = "coreclr",
request = "launch",
program = function()
return vim.fn.input('Path to dll', vim.fn.getcwd(), 'file')
end,
},
}