diff --git a/neovim/ftplugin/rust.lua b/neovim/ftplugin/rust.lua new file mode 100644 index 0000000..9b82115 --- /dev/null +++ b/neovim/ftplugin/rust.lua @@ -0,0 +1,16 @@ +local bufnr = vim.api.nvim_get_current_buf() + +function rustLspMap(mode, keys, cmd) + vim.keymap.set( + mode, + keys, + function() vim.cmd.RustLsp(cmd) end, + { silent = true, buffer = bufnr } + ) +end + +-- Use rust-analyzer's grouping of actions +rustLspMap("n", "gra", "codeAction") + +-- Use rustaceanvim's hover actions +rustLspMap("n", "K", {'hover', 'actions'}) diff --git a/neovim/init.lua b/neovim/init.lua index b688c3e..4ba1910 100644 --- a/neovim/init.lua +++ b/neovim/init.lua @@ -72,7 +72,7 @@ vim.opt.completeopt = "menu,menuone,noselect" vim.o.secure = true -vim.keymap.set("", "w", "") +vim.keymap.set("", "w", "", { remap = true }) vim.keymap.set("", 'w"', ":split") vim.keymap.set("", 'w%', ":vsplit") @@ -88,6 +88,8 @@ vim.keymap.set("", ';0', ":close") vim.keymap.set("", 'w', ":w") +vim.keymap.set("n", "]", ":rightbelow wincmd ]") + -- TODO: Delete these ; fake-leader bindings vim.keymap.set("", ';w', ":w") @@ -133,3 +135,18 @@ vim.keymap.set("n", "", function() vim.cmd.colorscheme(theme) vim.cmd.redraw() end) + +-- Split windows vertically if there's enough width for two "full size" panes. +-- Otherwise, split horizontally. +vim.api.nvim_create_autocmd('WinNew', { + callback = function() + if vim.fn.win_gettype(0) ~= '' then + return + end + if vim.api.nvim_win_get_width(0) > 2 * 80 then + vim.cmd.wincmd(vim.o.splitright and 'L' or 'H') + end + end +}) + +vim.diagnostic.config({ jump = { float = true } }) diff --git a/neovim/lazy-lock.json b/neovim/lazy-lock.json index 5a076db..ee12406 100644 --- a/neovim/lazy-lock.json +++ b/neovim/lazy-lock.json @@ -1,47 +1,45 @@ { - "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, - "aerial.nvim": { "branch": "master", "commit": "9ebc13583cff447f5493a63e99dfca526b3c3088" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, + "LuaSnip": { "branch": "master", "commit": "f958d9837c8fa7816bb8fb54977e658affc63c31" }, + "aerial.nvim": { "branch": "master", "commit": "5e687b5a14004fa2dd9eccbee042b96869fe1557" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "context.vim": { "branch": "master", "commit": "82eb26de265292808917b82f3eda2725b53d785c" }, "gitsigns.nvim": { "branch": "main", "commit": "220446c8c86a280180d852efac60991eaf1a21d4" }, "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "keytrail.nvim": { "branch": "main", "commit": "153a76d5891065a328be82316b6813662904da71" }, - "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "lush.nvim": { "branch": "main", "commit": "45a79ec4acb5af783a6a29673a999ce37f00497e" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" }, - "mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" }, - "nerdtree": { "branch": "master", "commit": "9b465acb2745beb988eff3c1e4aa75f349738230" }, - "nim.nvim": { "branch": "master", "commit": "076239e8869e3e9b061b17cbca2cea2df73d5f92" }, - "none-ls.nvim": { "branch": "main", "commit": "a117163db44c256d53c3be8717f3e1a2a28e6299" }, - "nui.nvim": { "branch": "main", "commit": "8d3bce9764e627b62b07424e0df77f680d47ffdb" }, - "nvim-autopairs": { "branch": "master", "commit": "6522027785b305269fa17088395dfc0f456cedd2" }, - "nvim-cmp": { "branch": "main", "commit": "1e1900b0769324a9675ef85b38f99cca29e203b3" }, + "lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" }, + "lush.nvim": { "branch": "main", "commit": "9c60ec2279d62487d942ce095e49006af28eed6e" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "6bdb14f230de0904229ec367b410fb817e59b072" }, + "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, + "nerdtree": { "branch": "master", "commit": "690d061b591525890f1471c6675bcb5bdc8cdff9" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, + "nvim-autopairs": { "branch": "master", "commit": "7a2c97cccd60abc559344042fefb1d5a85b3e33b" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, "nvim-coverage": { "branch": "main", "commit": "a939e425e363319d952a6c35fb3f38b34041ded2" }, - "nvim-dap": { "branch": "master", "commit": "6a5bba0ddea5d419a783e170c20988046376090d" }, - "nvim-lspconfig": { "branch": "master", "commit": "fb733ac734249ccf293e5c8018981d4d8f59fa8f" }, - "nvim-surround": { "branch": "main", "commit": "6c54643ef42016b744888b06d2381abd23f9b7ea" }, - "nvim-treesitter": { "branch": "master", "commit": "5f38dffb6a07669a678f073bfe0f62b1a020dffc" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "9937e5e356e5b227ec56d83d0a9d0a0f6bc9cad4" }, - "nvim-ts-autotag": { "branch": "main", "commit": "a1d526af391f6aebb25a8795cbc05351ed3620b5" }, + "nvim-dap": { "branch": "master", "commit": "6782b097af2417a4c3e33849b0a26ae2188bd7ea" }, + "nvim-lspconfig": { "branch": "master", "commit": "ac98db2f9f06a56498ec890a96928774eae412c3" }, + "nvim-surround": { "branch": "main", "commit": "75de1782c781961e392efcca57601bf436f4d550" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "71385f191ec06ffc60e80e6b0c9a9d5daed4824c" }, + "nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" }, "openingh.nvim": { "branch": "main", "commit": "99fe3b052c827ea0ec4d88d7d141d4a4239f1487" }, - "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, - "rust-tools.nvim": { "branch": "master", "commit": "676187908a1ce35ffcd727c654ed68d851299d3e" }, - "sql-ghosty.nvim": { "branch": "main", "commit": "66109b7ca519d32faab2dc99adc99680a2ffaa83" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "rustaceanvim": { "branch": "master", "commit": "2f5afad4fc62c609dfd2ef4613999a0e8bddcccc" }, + "sql-ghosty.nvim": { "branch": "main", "commit": "7a61ef8536a515fd68ff211fb4362049a1c1e191" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope-symbols.nvim": { "branch": "master", "commit": "a6d0127a53d39b9fc2af75bd169d288166118aec" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "unimpaired.nvim": { "branch": "main", "commit": "a282ab8ce0d0d4b5b1200ea484993aecf65dd94c" }, + "unimpaired.nvim": { "branch": "main", "commit": "4995cb674cb4c5e442f0cd9d86f6f9c20333a0b8" }, "vim-abolish": { "branch": "master", "commit": "dcbfe065297d31823561ba787f51056c147aa682" }, "vim-addon-local-vimrc": { "branch": "master", "commit": "5430ada07e199aba932f9eab68399e624512596f" }, - "vim-better-whitespace": { "branch": "master", "commit": "86a0579b330b133b8181b8e088943e81c26a809e" }, + "vim-better-whitespace": { "branch": "master", "commit": "de99b55a6fe8c96a69f9376f16b1d5d627a56e81" }, "vim-bufkill": { "branch": "master", "commit": "3113181d0c1bfb8719f3ddcd2e2f35a8d763d1e5" }, "vim-commentary": { "branch": "master", "commit": "64a654ef4a20db1727938338310209b6a63f60c9" }, "vim-easy-align": { "branch": "master", "commit": "9815a55dbcd817784458df7a18acacc6f82b1241" }, - "vim-endwise": { "branch": "master", "commit": "f6a32fbe4d4e511d446ac189e926f8e24f69cc1e" }, - "vim-fugitive": { "branch": "master", "commit": "4a745ea72fa93bb15dd077109afbb3d1809383f2" }, - "vim-illuminate": { "branch": "master", "commit": "19cb21f513fc2b02f0c66be70107741e837516a1" }, + "vim-endwise": { "branch": "master", "commit": "eab530110d7a0d985902a3964894816b50dbf31a" }, + "vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }, + "vim-illuminate": { "branch": "master", "commit": "0d1e93684da00ab7c057410fecfc24f434698898" }, "vim-repeat": { "branch": "master", "commit": "65846025c15494983dafe5e3b46c8f88ab2e9635" }, - "which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" } + "which-key.nvim": { "branch": "main", "commit": "b4177e3eaf15fe5eb8357ebac2286d488be1ed00" } } diff --git a/neovim/lua/jdkaplan/cool_theme.lua b/neovim/lua/jdkaplan/cool_theme.lua index 64f15af..e34b68a 100644 --- a/neovim/lua/jdkaplan/cool_theme.lua +++ b/neovim/lua/jdkaplan/cool_theme.lua @@ -108,6 +108,7 @@ local theme = lush(function(injected_functions) Error { fg = '#EEEEEE', bg = '#AF0000' }, -- Any erroneous construct Todo { fg = '#D70000' }, -- Anything that needs extra attention; mostly the keywords TODO FIXME and XXX + LspInlayHint { fg = '#777777' }, LspReferenceText {} , -- Used for highlighting "text" references LspReferenceRead {} , -- Used for highlighting "read" references LspReferenceWrite {} , -- Used for highlighting "write" references diff --git a/neovim/lua/jdkaplan/warm_theme.lua b/neovim/lua/jdkaplan/warm_theme.lua index fc155ed..f69893a 100644 --- a/neovim/lua/jdkaplan/warm_theme.lua +++ b/neovim/lua/jdkaplan/warm_theme.lua @@ -108,6 +108,7 @@ local theme = lush(function(injected_functions) Error { fg = '#000000', bg = '#FF5F00' }, -- Any erroneous construct Todo { fg = '#FF0000' }, -- Anything that needs extra attention; mostly the keywords TODO FIXME and XXX + LspInlayHint { fg = '#015F00' }, LspReferenceText {} , -- Used for highlighting "text" references LspReferenceRead {} , -- Used for highlighting "read" references LspReferenceWrite {} , -- Used for highlighting "write" references diff --git a/neovim/lua/plugins/ide.lua b/neovim/lua/plugins/ide.lua index 7bd08ee..4efffa9 100644 --- a/neovim/lua/plugins/ide.lua +++ b/neovim/lua/plugins/ide.lua @@ -1,3 +1,5 @@ +vim.lsp.inlay_hint.enable(true) + return { -- HUD { @@ -16,7 +18,7 @@ return { { "m", "AerialToggle" }, { "n", "AerialNavToggle" }, }, - config =true, + config = true, }, { "wellle/context.vim", @@ -369,239 +371,24 @@ return { build = "make", }, - -- Mason + LSP - "alaviss/nim.nvim", - "simrat39/rust-tools.nvim", - "neovim/nvim-lspconfig", + -- LSP { - "nvimtools/none-ls.nvim", - config = function(_plugin, opts) - local null_ls = require("null-ls") - - local group = vim.api.nvim_create_augroup("lsp_format_on_save", { clear = false }) - - local prettier_filetypes = {} - for k, v in ipairs(null_ls.builtins.formatting.prettier.filetypes) do - prettier_filetypes[k] = v - end - table.insert(prettier_filetypes, "htmldjango") -- Jinja templates - - null_ls.setup({ - sources = { - null_ls.builtins.formatting.prettier.with({ - filetypes = prettier_filetypes, - }), - }, - on_attach = function(client, bufnr) - if client.supports_method("textDocument/formatting") then - vim.keymap.set("n", "f", function() - vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() }) - end, { buffer = bufnr, desc = "[lsp] format" }) - - -- format on save - vim.api.nvim_clear_autocmds({ buffer = bufnr, group = group }) - vim.api.nvim_create_autocmd("BufWritePre", { - buffer = bufnr, - group = group, - callback = function() - vim.lsp.buf.format({ bufnr = bufnr, async = false }) - end, - desc = "[lsp] format on save", - }) - end - - if client.supports_method("textDocument/rangeFormatting") then - vim.keymap.set("x", "f", function() - vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() }) - end, { buffer = bufnr, desc = "[lsp] format" }) - end - end, - }) - end, + "mrcjkb/rustaceanvim", + version = '^6', + lazy = false, }, { - "williamboman/mason.nvim", - build = function(_plugin) - require("mason-registry").refresh() - end, - opts = { - PATH = "append", - }, - }, - { - "williamboman/mason-lspconfig.nvim", + "mason-org/mason-lspconfig.nvim", + opts = {}, dependencies = { "neovim/nvim-lspconfig", - "williamboman/mason.nvim", + { + "mason-org/mason.nvim", + opts = { + PATH = "append", + }, + }, }, - config = function(_plugin, opts) - local mason_lspconfig = require("mason-lspconfig") - mason_lspconfig.setup(opts) - - local lsp_settings = { - rust_analyzer = { - ["rust-analyzer"] = { - checkOnSave = true, - check = { command = "clippy" }, - }, - }, - gopls = { - gofumpt = true, - }, - sorbet = {}, -- This one is _extra_ special for some reason. - } - - local on_attach = function(client, bufno) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufno, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufno, ...) end - - -- Enable completion through omnifunc, triggered by - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - local opts = { noremap=true, silent=true } - - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'R', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('v', 'ca', 'lua vim.lsp.buf.range_code_action()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'd', 'lua vim.diagnostic.open_float()', opts) - buf_set_keymap('n', 'j', 'lua vim.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'k', 'lua vim.diagnostic.goto_prev()', opts) - buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) - end - - local default_setup = function(server_name) - local capabilities = require('cmp_nvim_lsp').default_capabilities() - - require("lspconfig")[server_name].setup({ - on_attach = function(client, bufno) - on_attach(client, bufno) - vim.api.nvim_command [[autocmd BufWritePre lua vim.lsp.buf.format()]] - end, - settings = lsp_settings[server_name] or {}, - capabilities = capabilities, - }) - end - - local default_setup_nofmt = function(server_name) - local capabilities = require('cmp_nvim_lsp').default_capabilities() - - require("lspconfig")[server_name].setup({ - on_attach = on_attach, - settings = lsp_settings[server_name] or {}, - capabilities = capabilities, - }) - end - - mason_lspconfig.setup_handlers({ - -- This is the default handler for servers not named below. - default_setup, - - ["eslint"] = default_setup_nofmt, - ["ts_ls"] = default_setup_nofmt, - ["zls"] = function() - -- The default filetype competes with zls formatting, so skip it. - -- TODO(neovim v0.11): This will become the default. - vim.g.zig_fmt_autosave = 0 - default_setup("zls") - end, - - ["gopls"] = function() - local capabilities = require('cmp_nvim_lsp').default_capabilities() - - require("lspconfig")["gopls"].setup({ - on_attach = on_attach, - settings = lsp_settings["gopls"] or {}, - capabilities = capabilities, - }) - - -- https://github.com/golang/tools/blob/master/gopls/doc/vim.md#neovim-imports - vim.api.nvim_create_autocmd("BufWritePre", { - pattern = "*.go", - callback = function() - local params = vim.lsp.util.make_range_params() - params.context = {only = {"source.organizeImports"}} - - local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000) - - for cid, res in pairs(result or {}) do - for _, r in pairs(res.result or {}) do - if r.edit then - local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16" - vim.lsp.util.apply_workspace_edit(r.edit, enc) - end - end - end - - vim.lsp.buf.format({async = false}) - end - }) - end, - - ["rust_analyzer"] = function() - local capabilities = require('cmp_nvim_lsp').default_capabilities() - - -- rust-analyzer will be configured by rust-tools. Don't use lspconfig - -- directly (or through the default setup) for this. - local rt = require('rust-tools') - - rt.setup({ - tools = { - autoSetHints = true, - hover_with_actions = false, - inlay_hints = { - only_current_line = true, - -- Parameter hints are more annoying than useful here. Neovim can't show - -- virtual text in the middle of the line like other editors do. It would - -- mess with grid-based motion anyway. - show_parameter_hints = false, - parameter_hints_prefix = "", - other_hints_prefix = "//", - }, - }, - - server = { - standalone = false, - capabilities = capabilities, - on_attach = function(client, bufno) - on_attach(client, bufno) - - vim.api.nvim_command [[autocmd BufWritePre lua vim.lsp.buf.format()]] - - vim.keymap.set("n", "K", rt.hover_actions.hover_actions, { buffer = bufno }) - end, - settings = lsp_settings.rust_analyzer, - }, - - dap = { - adapter = require('rust-tools.dap').get_codelldb_adapter( - '/usr/bin/codelldb', - '/usr/lib/liblldb.so' - ), - }, - }) - end, - - ["sorbet"] = function() - local capabilities = require("cmp_nvim_lsp").default_capabilities() - - require("lspconfig").sorbet.setup({ - on_attach = function(client, bufno) - on_attach(client, bufno) - end, - cmd = { "bundle", "exec", "srb", "typecheck", "--lsp", "--disable-watchman" }, - capabilities = capabilities, - }) - end, - }) - end, }, -- Completion + snippets