From ab788929d981fb2e10c30e8a982254e01e2a123f Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 09:31:44 +0100 Subject: [PATCH 01/23] wip: feat(nvim/rust-tools): begin migration --- default.nix | 18 ++++-- init.lua | 63 +++++++++++++++++- init.vim | 11 ---- rust.lua | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 253 insertions(+), 19 deletions(-) create mode 100644 rust.lua diff --git a/default.nix b/default.nix index 444db70..9573f50 100644 --- a/default.nix +++ b/default.nix @@ -45,7 +45,6 @@ in fzf-vim coc-sh coc-nvim - coc-rust-analyzer coc-json coc-yaml coc-tsserver @@ -63,6 +62,7 @@ in nvim-dap-ui nvim-notify rust-tools-nvim + plenary-nvim crates-nvim nvim-lspconfig telescope-nvim @@ -76,11 +76,19 @@ in lldb = pkgs.lldb; rust_analyzer = rust-analyzer; }; + pathsLua = pkgs.writeTextFile { + name = "nvim-deps.lua"; + text = '' + return { + ${concatStringsSep ",\n " (mapAttrsToList (name: path: ''${name}_path = "${path}"'') paths)} + } + ''; + }; confDir = lib.sourceFilesBySuffices ./. [ "lua" "vim" ]; in with lib; '' vim.cmd [[source ${confDir}/init.vim]] - ${concatStringsSep "\n" (mapAttrsToList (name: path: ''${name}_path = "${path}"'') paths)} + package.path = package.path .. ";${confDir}/?.lua;${pathsLua};" dofile("${confDir}/init.lua") ''; }; @@ -186,9 +194,9 @@ in sdk = [ rust-sdk ]; }; imports.group.enable = true; - # inlayHints = { - # closureReturnTypeHints.enable = false; - # }; + inlayHints = { + closureReturnTypeHints.enable = false; + }; highlightRelated = { yieldPoints.enable = true; references.enable = true; diff --git a/init.lua b/init.lua index 4fbafb0..110306e 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,4 @@ +local deps = require("nvim-deps") vim.opt.termguicolors = true vim.notify = require("notify") vim.notify.setup({background_colour = "#000000"}) @@ -43,9 +44,9 @@ neogit.setup({ }) local dap, dapui = require("dap"), require("dapui") dap.adapters.lldb = { - type = "executable", - command = lldb_path .. "/bin/lldb-vscode", - name = "lldb" + type = "executable", + command = deps.lldb_path .. "/bin/lldb-vscode", + name = "lldb", } local lldb = { name = "Launch lldb", @@ -98,9 +99,65 @@ vim.fn.sign_define("DapBreakpointRejected", dap_breakpoint.rejected) dapui.setup() +<<<<<<< HEAD -- Auto open and close 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 +======= + -- Auto open and close 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 + +-- Setup language servers. +local lspconfig = require('lspconfig') + + +-- Global mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +vim.keymap.set('n', 'e', vim.diagnostic.open_float) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + +-- Use LspAttach autocommand to only map the following keys +-- after the language server attaches to the current buffer +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, +}) + +require("rust") diff --git a/init.vim b/init.vim index a12f1ae..a17e9ce 100644 --- a/init.vim +++ b/init.vim @@ -95,17 +95,6 @@ let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#show_tab_nr = 1 let g:airline#extensions#tabline#tab_nr_type = 1 -" DAP -nnoremap lua require'dap'.continue() -nnoremap lua require'dap'.step_over() -nnoremap lua require'dap'.step_into() -nnoremap lua require'dap'.step_out() -nnoremap b lua require'dap'.toggle_breakpoint() -nnoremap B lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: ')) -nnoremap lp lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) -nnoremap dr lua require'dap'.repl.open() -nnoremap dl lua require'dap'.run_last() - if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif diff --git a/rust.lua b/rust.lua new file mode 100644 index 0000000..c55be41 --- /dev/null +++ b/rust.lua @@ -0,0 +1,180 @@ +local rt = require("rust-tools") +local deps = require("nvim-deps") + +rt.setup( +{ + tools = { -- rust-tools options + + -- how to execute terminal commands + -- options right now: termopen / quickfix / toggleterm / vimux + executor = require("rust-tools.executors").termopen, + + -- callback to execute once rust-analyzer is done initializing the workspace + -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" + on_initialized = nil, + + -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. + reload_workspace_from_cargo_toml = true, + + -- These apply to the default RustSetInlayHints command + inlay_hints = { + -- automatically set inlay hints (type hints) + -- default: true + auto = true, + + -- Only show inlay hints for the current line + only_current_line = false, + + -- whether to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = true, + + -- prefix for parameter hints + -- default: "<-" + parameter_hints_prefix = "<- ", + + -- prefix for all the other hints (type, chaining) + -- default: "=>" + other_hints_prefix = "=> ", + + -- whether to align to the length of the longest line in the file + max_len_align = false, + + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + + -- whether to align to the extreme right or not + right_align = false, + + -- padding from the right if right_align is true + right_align_padding = 7, + + -- The color of the hints + highlight = "Comment", + }, + + -- options same as lsp hover / vim.lsp.util.open_floating_preview() + hover_actions = { + + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, + }, + + -- Maximal width of the hover window. Nil means no max. + max_width = nil, + + -- Maximal height of the hover window. Nil means no max. + max_height = nil, + + -- whether the hover action window gets automatically focused + -- default: false + auto_focus = false, + }, + + -- settings for showing the crate graph based on graphviz and the dot + -- command + crate_graph = { + -- Backend used for displaying the graph + -- see: https://graphviz.org/docs/outputs/ + -- default: x11 + backend = "x11", + -- where to store the output, nil for no output stored (relative + -- path from pwd) + -- default: nil + output = nil, + -- true for all crates.io and external crates, false only the local + -- crates + -- default: true + full = true, + + -- List of backends found on: https://graphviz.org/docs/outputs/ + -- Is used for input validation and autocompletion + -- Last updated: 2021-08-26 + enabled_graphviz_backends = { + "bmp", + "cgimage", + "canon", + "dot", + "gv", + "xdot", + "xdot1.2", + "xdot1.4", + "eps", + "exr", + "fig", + "gd", + "gd2", + "gif", + "gtk", + "ico", + "cmap", + "ismap", + "imap", + "cmapx", + "imap_np", + "cmapx_np", + "jpg", + "jpeg", + "jpe", + "jp2", + "json", + "json0", + "dot_json", + "xdot_json", + "pdf", + "pic", + "pct", + "pict", + "plain", + "plain-ext", + "png", + "pov", + "ps", + "ps2", + "psd", + "sgi", + "svg", + "svgz", + "tga", + "tiff", + "tif", + "tk", + "vml", + "vmlz", + "wbmp", + "webp", + "xlib", + "x11", + }, + }, + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + -- standalone file support + -- setting it to false may improve startup time + standalone = true, + cmd = { (deps.rust_analyzer_path .. "/bin/rust-analyzer") }, + }, -- rust-analyzer options + + -- debugging stuff + dap = { + adapter = { + type = "executable", + command = deps.lldb_path .. "lldb-vscode", + name = "rt_lldb", + }, + }, +} +) From 649d2529783d86f747dd3a638bc091b858cc0058 Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 15:36:59 +0100 Subject: [PATCH 02/23] wip: feat(nvim/rust-tools): begin migration --- init.lua | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/init.lua b/init.lua index 110306e..07a51b2 100644 --- a/init.lua +++ b/init.lua @@ -99,24 +99,12 @@ vim.fn.sign_define("DapBreakpointRejected", dap_breakpoint.rejected) dapui.setup() -<<<<<<< HEAD -- Auto open and close 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 -======= - -- Auto open and close 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 -- Setup language servers. local lspconfig = require('lspconfig') From 3742917ca4af544dbde284148139e89df67a73fb Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 16:02:17 +0100 Subject: [PATCH 03/23] feat(nvim/dev-icons): enable --- default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/default.nix b/default.nix index 9573f50..91df923 100644 --- a/default.nix +++ b/default.nix @@ -42,6 +42,7 @@ in rainbow nerdtree nerdtree-git-plugin + nvim-web-devicons fzf-vim coc-sh coc-nvim From 8851240d87dafbc37d1b86fdfadff4c8ae094e03 Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 16:11:54 +0100 Subject: [PATCH 04/23] feat(nvim/nerdtree): removed --- default.nix | 2 -- init.vim | 9 --------- 2 files changed, 11 deletions(-) diff --git a/default.nix b/default.nix index 91df923..4808fcb 100644 --- a/default.nix +++ b/default.nix @@ -40,8 +40,6 @@ in # vim-grammarous markdown-preview-nvim rainbow - nerdtree - nerdtree-git-plugin nvim-web-devicons fzf-vim coc-sh diff --git a/init.vim b/init.vim index a17e9ce..5c15a12 100644 --- a/init.vim +++ b/init.vim @@ -28,15 +28,6 @@ nmap ]G (coc-diagnostic-prev-error) nmap [g (coc-diagnostic-next) nmap ]g (coc-diagnostic-prev) -" NERDTree config -" autocmd VimEnter * NERDTree -autocmd BufEnter * NERDTreeMirror - -"CTRL-t to toggle tree view with CTRL-t -nmap :NERDTreeToggle -"Set F2 to put the cursor to the nerdtree -nmap :NERDTreeFind - function! ShowDocumentation() if CocAction('hasProvider', 'hover') call CocActionAsync('doHover') From abbbb93ceff02c6c151812c24ea598ac9fcace5e Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 17:43:28 +0100 Subject: [PATCH 05/23] feat(nvim): removed coc --- completion.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ default.nix | 21 ++++++++------------ init.vim | 42 ---------------------------------------- 3 files changed, 60 insertions(+), 55 deletions(-) create mode 100644 completion.lua diff --git a/completion.lua b/completion.lua new file mode 100644 index 0000000..d5c3351 --- /dev/null +++ b/completion.lua @@ -0,0 +1,52 @@ +-- Completion Plugin Setup +local cmp = require'cmp' +cmp.setup({ + -- Enable LSP snippets + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }) + }, + -- Installed sources: + sources = { + { name = 'path' }, -- file paths + { name = 'nvim_lsp', keyword_length = 3 }, -- from language server + { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized + { 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 + { name = 'calc'}, -- source for math calculation + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon ={ + nvim_lsp = 'λ', + vsnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + item.menu = menu_icon[entry.source.name] + return item + end, + }, +}) diff --git a/default.nix b/default.nix index 4808fcb..b3e27b2 100644 --- a/default.nix +++ b/default.nix @@ -42,24 +42,19 @@ in rainbow nvim-web-devicons fzf-vim - coc-sh - coc-nvim - coc-json - coc-yaml - coc-tsserver - coc-prettier - coc-pyright - coc-diagnostic - vimtex - coc-vimtex - coc-html - coc-go - coc-spell-checker editorconfig-nvim # tmuxline-vim nvim-dap nvim-dap-ui nvim-notify + nvim-cmp + cmp-nvim-lsp + cmp-nvim-lua + cmp-buffer + cmp-path + cmp-spell + cmp-conventionalcommits + cmp-calc rust-tools-nvim plenary-nvim crates-nvim diff --git a/init.vim b/init.vim index 5c15a12..a618340 100644 --- a/init.vim +++ b/init.vim @@ -5,45 +5,6 @@ set hidden " disable mouse set mouse= -" GoTo code navigation. -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - - -" Rename -nmap rn (coc-rename) - -" Use K to show documentation in preview window. -nnoremap K :call ShowDocumentation() - -nmap ac (coc-codeaction) -nmap as (coc-codeaction-cursor) -nmap cl (coc-codelens-action) - -nmap [G (coc-diagnostic-next-error) -nmap ]G (coc-diagnostic-prev-error) - -nmap [g (coc-diagnostic-next) -nmap ]g (coc-diagnostic-prev) - -function! ShowDocumentation() - if CocAction('hasProvider', 'hover') - call CocActionAsync('doHover') - else - call feedkeys('K', 'in') - endif -endfunction - -" Highlight the symbol and its references when holding the cursor. -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Formatting selected code. -xmap f (coc-format-selected) -nmap f (coc-format-selected) -nmap F (coc-format) - " " Copy to clipboard vnoremap y "+y @@ -67,9 +28,6 @@ map to :tabonly " Display line numbers set number relativenumber -inoremap coc#pum#visible() ? coc#_select_confirm() - \: "\u\\=coc#on_enter()\" - map :mksession! .nvim_session " Quick write session with F3 map :source .nvim_session " And load session with F4 From 477195785973185bf8efd47ad91f22c3278892b6 Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 17:47:51 +0100 Subject: [PATCH 06/23] feat(nvim/cmp): connect rust-tools --- completion.lua | 125 ++++++++++++--------- init.lua | 54 ++++----- rust.lua | 293 ++++++++++++++++++++++--------------------------- 3 files changed, 236 insertions(+), 236 deletions(-) diff --git a/completion.lua b/completion.lua index d5c3351..afd08e3 100644 --- a/completion.lua +++ b/completion.lua @@ -1,52 +1,79 @@ +-- 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} +vim.api.nvim_set_option('updatetime', 300) + +-- Fixed column for diagnostics to appear +-- Show autodiagnostic popup on cursor hover_range +-- Goto previous / next diagnostic warning / error +-- Show inlay_hints more frequently +vim.cmd([[ +set signcolumn=yes +autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) +]]) + +vim.opt.spell = true +vim.opt.spelllang = {'en_us'} -- Completion Plugin Setup -local cmp = require'cmp' +local cmp = require 'cmp' cmp.setup({ - -- Enable LSP snippets - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, - mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - -- Add tab support - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }) - }, - -- Installed sources: - sources = { - { name = 'path' }, -- file paths - { name = 'nvim_lsp', keyword_length = 3 }, -- from language server - { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized - { 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 - { name = 'calc'}, -- source for math calculation - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - formatting = { - fields = {'menu', 'abbr', 'kind'}, - format = function(entry, item) - local menu_icon ={ - nvim_lsp = 'λ', - vsnip = '⋗', - buffer = 'Ω', - path = '🖫', - } - item.menu = menu_icon[entry.source.name] - return item - end, - }, + -- Enable LSP snippets + snippet = {expand = function(args) vim.fn["vsnip#anonymous"](args.body) end}, + -- = CTRL + -- = SHIFT + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true + }) + }, + -- Installed sources: + sources = { + {name = 'path'}, -- file paths + {name = 'nvim_lsp', keyword_length = 3}, -- from language server + {name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized + {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 + {name = 'calc'}, -- source for math calculation + { + name = 'spell', + option = { + keep_all_entries = false, + enable_in_context = function() return true end + } + }, {name = 'conventionalcommits'} + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered() + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + vsnip = '⋗', + buffer = 'Ω', + path = '🖫' + } + item.menu = menu_icon[entry.source.name] + return item + end + } }) diff --git a/init.lua b/init.lua index 07a51b2..2546c17 100644 --- a/init.lua +++ b/init.lua @@ -109,7 +109,6 @@ dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end -- Setup language servers. local lspconfig = require('lspconfig') - -- Global mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions vim.keymap.set('n', 'e', vim.diagnostic.open_float) @@ -120,32 +119,33 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist) -- Use LspAttach autocommand to only map the following keys -- after the language server attaches to the current buffer vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('UserLspConfig', {}), - callback = function(ev) - -- Enable completion triggered by - vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' - -- Buffer local mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - local opts = { buffer = ev.buf } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, opts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) - vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) - vim.keymap.set('n', 'f', function() - vim.lsp.buf.format { async = true } - end, opts) - end, + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = {buffer = ev.buf} + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap + .set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, + opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set({'n', 'v'}, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', + function() vim.lsp.buf.format {async = true} end, opts) + end }) - +require("completion") require("rust") diff --git a/rust.lua b/rust.lua index c55be41..a3b04b3 100644 --- a/rust.lua +++ b/rust.lua @@ -1,180 +1,153 @@ local rt = require("rust-tools") +local nvim_lsp = require 'lspconfig' +local c = vim.lsp.protocol.make_client_capabilities() local deps = require("nvim-deps") -rt.setup( -{ - tools = { -- rust-tools options +rt.setup({ + tools = { -- rust-tools options + -- how to execute terminal commands + -- options right now: termopen / quickfix / toggleterm / vimux + executor = require("rust-tools.executors").termopen, - -- how to execute terminal commands - -- options right now: termopen / quickfix / toggleterm / vimux - executor = require("rust-tools.executors").termopen, + -- callback to execute once rust-analyzer is done initializing the workspace + -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" + on_initialized = nil, - -- callback to execute once rust-analyzer is done initializing the workspace - -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" - on_initialized = nil, + -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. + reload_workspace_from_cargo_toml = true, - -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. - reload_workspace_from_cargo_toml = true, + -- These apply to the default RustSetInlayHints command + inlay_hints = { + -- automatically set inlay hints (type hints) + -- default: true + auto = true, - -- These apply to the default RustSetInlayHints command - inlay_hints = { - -- automatically set inlay hints (type hints) - -- default: true - auto = true, + -- Only show inlay hints for the current line + only_current_line = false, - -- Only show inlay hints for the current line - only_current_line = false, + -- whether to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = true, - -- whether to show parameter hints with the inlay hints or not - -- default: true - show_parameter_hints = true, + -- prefix for parameter hints + -- default: "<-" + parameter_hints_prefix = "<- ", - -- prefix for parameter hints - -- default: "<-" - parameter_hints_prefix = "<- ", + -- prefix for all the other hints (type, chaining) + -- default: "=>" + other_hints_prefix = "=> ", - -- prefix for all the other hints (type, chaining) - -- default: "=>" - other_hints_prefix = "=> ", + -- whether to align to the length of the longest line in the file + max_len_align = false, - -- whether to align to the length of the longest line in the file - max_len_align = false, + -- padding from the left if max_len_align is true + max_len_align_padding = 1, - -- padding from the left if max_len_align is true - max_len_align_padding = 1, + -- whether to align to the extreme right or not + right_align = false, - -- whether to align to the extreme right or not - right_align = false, + -- padding from the right if right_align is true + right_align_padding = 7, - -- padding from the right if right_align is true - right_align_padding = 7, + -- The color of the hints + highlight = "Comment" + }, - -- The color of the hints - highlight = "Comment", + -- options same as lsp hover / vim.lsp.util.open_floating_preview() + hover_actions = { + + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + {"╭", "FloatBorder"}, {"─", "FloatBorder"}, + {"╮", "FloatBorder"}, {"│", "FloatBorder"}, + {"╯", "FloatBorder"}, {"─", "FloatBorder"}, + {"╰", "FloatBorder"}, {"│", "FloatBorder"} + }, + + -- Maximal width of the hover window. Nil means no max. + max_width = nil, + + -- Maximal height of the hover window. Nil means no max. + max_height = nil, + + -- whether the hover action window gets automatically focused + -- default: false + auto_focus = false + }, + + -- settings for showing the crate graph based on graphviz and the dot + -- command + crate_graph = { + -- Backend used for displaying the graph + -- see: https://graphviz.org/docs/outputs/ + -- default: x11 + backend = "x11", + -- where to store the output, nil for no output stored (relative + -- path from pwd) + -- default: nil + output = nil, + -- true for all crates.io and external crates, false only the local + -- crates + -- default: true + full = true, + + -- List of backends found on: https://graphviz.org/docs/outputs/ + -- Is used for input validation and autocompletion + -- Last updated: 2021-08-26 + enabled_graphviz_backends = { + "bmp", "cgimage", "canon", "dot", "gv", "xdot", "xdot1.2", + "xdot1.4", "eps", "exr", "fig", "gd", "gd2", "gif", "gtk", + "ico", "cmap", "ismap", "imap", "cmapx", "imap_np", "cmapx_np", + "jpg", "jpeg", "jpe", "jp2", "json", "json0", "dot_json", + "xdot_json", "pdf", "pic", "pct", "pict", "plain", "plain-ext", + "png", "pov", "ps", "ps2", "psd", "sgi", "svg", "svgz", "tga", + "tiff", "tif", "tk", "vml", "vmlz", "wbmp", "webp", "xlib", + "x11" + } + } }, - -- options same as lsp hover / vim.lsp.util.open_floating_preview() - hover_actions = { + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + -- standalone file support + -- setting it to false may improve startup time + standalone = true, + cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")}, + capabilities = require("cmp_nvim_lsp").default_capabilities(c), + on_attach = function(_, bufnr) + local keymap_opts = {buffer = bufnr} + -- Hover actions + vim.keymap.set("n", "h", rt.hover_actions.hover_actions, + keymap_opts) + -- Code action groups + vim.keymap.set("n", "as", + rt.code_action_group.code_action_group, keymap_opts) + vim.keymap.set('n', 'c', rt.open_cargo_toml.open_cargo_toml) + vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) + local diag_float_grp = vim.api.nvim_create_augroup( + "DiagnosticFloat", {clear = true}) + vim.api.nvim_create_autocmd("CursorHold", { + callback = function() + vim.diagnostic.open_float(nil, {focusable = false}) + end, + group = diag_float_grp + }) - -- the border that is used for the hover window - -- see vim.api.nvim_open_win() - border = { - { "╭", "FloatBorder" }, - { "─", "FloatBorder" }, - { "╮", "FloatBorder" }, - { "│", "FloatBorder" }, - { "╯", "FloatBorder" }, - { "─", "FloatBorder" }, - { "╰", "FloatBorder" }, - { "│", "FloatBorder" }, - }, + -- Goto previous/next diagnostic warning/error + vim.keymap.set("n", "g[", vim.diagnostic.goto_prev, keymap_opts) + vim.keymap.set("n", "g]", vim.diagnostic.goto_next, keymap_opts) + end + }, -- rust-analyzer options - -- Maximal width of the hover window. Nil means no max. - max_width = nil, - - -- Maximal height of the hover window. Nil means no max. - max_height = nil, - - -- whether the hover action window gets automatically focused - -- default: false - auto_focus = false, - }, - - -- settings for showing the crate graph based on graphviz and the dot - -- command - crate_graph = { - -- Backend used for displaying the graph - -- see: https://graphviz.org/docs/outputs/ - -- default: x11 - backend = "x11", - -- where to store the output, nil for no output stored (relative - -- path from pwd) - -- default: nil - output = nil, - -- true for all crates.io and external crates, false only the local - -- crates - -- default: true - full = true, - - -- List of backends found on: https://graphviz.org/docs/outputs/ - -- Is used for input validation and autocompletion - -- Last updated: 2021-08-26 - enabled_graphviz_backends = { - "bmp", - "cgimage", - "canon", - "dot", - "gv", - "xdot", - "xdot1.2", - "xdot1.4", - "eps", - "exr", - "fig", - "gd", - "gd2", - "gif", - "gtk", - "ico", - "cmap", - "ismap", - "imap", - "cmapx", - "imap_np", - "cmapx_np", - "jpg", - "jpeg", - "jpe", - "jp2", - "json", - "json0", - "dot_json", - "xdot_json", - "pdf", - "pic", - "pct", - "pict", - "plain", - "plain-ext", - "png", - "pov", - "ps", - "ps2", - "psd", - "sgi", - "svg", - "svgz", - "tga", - "tiff", - "tif", - "tk", - "vml", - "vmlz", - "wbmp", - "webp", - "xlib", - "x11", - }, - }, - }, - - -- all the opts to send to nvim-lspconfig - -- these override the defaults set by rust-tools.nvim - -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer - server = { - -- standalone file support - -- setting it to false may improve startup time - standalone = true, - cmd = { (deps.rust_analyzer_path .. "/bin/rust-analyzer") }, - }, -- rust-analyzer options - - -- debugging stuff - dap = { - adapter = { - type = "executable", - command = deps.lldb_path .. "lldb-vscode", - name = "rt_lldb", - }, - }, -} -) + -- debugging stuff + dap = { + adapter = { + type = "executable", + command = deps.lldb_path .. "/bin/lldb-vscode", + name = "rt_lldb" + } + } +}) From ea9b7b7bd2d03db78df08977966079585456270d Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 17:48:45 +0100 Subject: [PATCH 07/23] feat(nvim/dap): setup lldb --- init.lua | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/init.lua b/init.lua index 2546c17..f808759 100644 --- a/init.lua +++ b/init.lua @@ -44,34 +44,10 @@ neogit.setup({ }) local dap, dapui = require("dap"), require("dapui") dap.adapters.lldb = { - type = "executable", - command = deps.lldb_path .. "/bin/lldb-vscode", - name = "lldb", + type = "executable", + command = deps.lldb_path .. "/bin/lldb-vscode", + name = "lldb" } -local lldb = { - name = "Launch lldb", - type = "lldb", -- matches the adapter - request = "launch", -- could also attach to a currently running process - program = function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", - "file") - end, - cwd = "$${workspaceFolder}", - stopOnEntry = false, - args = {}, - console = internalConsole, - runInTerminal = true -} - -dap.configurations.rust = { - lldb -- different debuggers or more configurations can be used here -} ---[[ local opts = { - dap = { - adapter = require("rust-tools.dap").get_codelldb_adapter("${pkgs.lldb}/bin/lldb-vscode", "${pkgs.lldb.lib}/lib/liblldb.so"), - }, - } - require("rust-tools").setup { opts } ]] local dap_breakpoint = { error = { text = "🟥", @@ -93,6 +69,9 @@ local dap_breakpoint = { } } +vim.keymap.set('n', 'dk', function() dap.continue() end) +vim.keymap.set('n', 'dl', function() dap.run_last() end) +vim.keymap.set('n', 'b', function() dap.toggle_breakpoint() end) vim.fn.sign_define("DapBreakpoint", dap_breakpoint.error) vim.fn.sign_define("DapStopped", dap_breakpoint.stopped) vim.fn.sign_define("DapBreakpointRejected", dap_breakpoint.rejected) From 78eacedab02155ff3be04a3416a196024c1897d3 Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 18:03:13 +0100 Subject: [PATCH 08/23] feat(nvim/cmp): icons --- completion.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/completion.lua b/completion.lua index afd08e3..97f2554 100644 --- a/completion.lua +++ b/completion.lua @@ -57,7 +57,7 @@ cmp.setup({ keep_all_entries = false, enable_in_context = function() return true end } - }, {name = 'conventionalcommits'} + }, {name = 'conventionalcommits', keyword_length = 1 }, }, window = { completion = cmp.config.window.bordered(), @@ -70,7 +70,9 @@ cmp.setup({ nvim_lsp = 'λ', vsnip = '⋗', buffer = 'Ω', - path = '🖫' + path = '📁', + spell = '💬', + calc = '√', } item.menu = menu_icon[entry.source.name] return item From 8ca3f4820d9d20f7ae673ab3653a8abda8f165fe Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 18:22:09 +0100 Subject: [PATCH 09/23] feat(nvim/dap): icons --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index f808759..439cd99 100644 --- a/init.lua +++ b/init.lua @@ -56,13 +56,13 @@ local dap_breakpoint = { numhl = "" }, rejected = { - text = "", + text = "❗", texthl = "LspDiagnosticsSignHint", linehl = "", numhl = "" }, stopped = { - text = "⭐️", + text = "🛑", texthl = "LspDiagnosticsSignInformation", linehl = "DiagnosticUnderlineInfo", numhl = "LspDiagnosticsSignInformation" From a909ea3bf3ed7cd41e2207b51aee7d204b376174 Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 18:43:44 +0100 Subject: [PATCH 10/23] feat(nvim/rust): load crates plugin --- completion.lua | 5 ++++- rust.lua | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/completion.lua b/completion.lua index 97f2554..2d2d642 100644 --- a/completion.lua +++ b/completion.lua @@ -57,7 +57,9 @@ cmp.setup({ keep_all_entries = false, enable_in_context = function() return true end } - }, {name = 'conventionalcommits', keyword_length = 1 }, + }, + {name = 'conventionalcommits', keyword_length = 1 }, + {name = 'crates'}, }, window = { completion = cmp.config.window.bordered(), @@ -73,6 +75,7 @@ cmp.setup({ path = '📁', spell = '💬', calc = '√', + crates = '📦', } item.menu = menu_icon[entry.source.name] return item diff --git a/rust.lua b/rust.lua index a3b04b3..1f994f0 100644 --- a/rust.lua +++ b/rust.lua @@ -118,8 +118,10 @@ rt.setup({ cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")}, capabilities = require("cmp_nvim_lsp").default_capabilities(c), on_attach = function(_, bufnr) + require('crates').setup() local keymap_opts = {buffer = bufnr} -- Hover actions + -- call twice to focus vim.keymap.set("n", "h", rt.hover_actions.hover_actions, keymap_opts) -- Code action groups From 838f1fb2623a3e6ad33575ee8da5ddbc7bd309f1 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 22:04:48 +0100 Subject: [PATCH 11/23] feat(nvim): switch rust-tools to rustaceanvim --- completion.lua | 12 ++++++++++++ default.nix | 2 +- rust.lua | 30 ++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/completion.lua b/completion.lua index 2d2d642..f94b568 100644 --- a/completion.lua +++ b/completion.lua @@ -20,6 +20,13 @@ autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) vim.opt.spell = true vim.opt.spelllang = {'en_us'} +vim.lsp.handlers["textDocument/publishDiagnostics"] = + vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, + { + virtual_text = true, + } +) -- Completion Plugin Setup local cmp = require 'cmp' cmp.setup({ @@ -82,3 +89,8 @@ cmp.setup({ end } }) +cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' }, + } +}) diff --git a/default.nix b/default.nix index b3e27b2..b304e5d 100644 --- a/default.nix +++ b/default.nix @@ -55,7 +55,7 @@ in cmp-spell cmp-conventionalcommits cmp-calc - rust-tools-nvim + rustaceanvim plenary-nvim crates-nvim nvim-lspconfig diff --git a/rust.lua b/rust.lua index 1f994f0..04167c5 100644 --- a/rust.lua +++ b/rust.lua @@ -1,9 +1,8 @@ -local rt = require("rust-tools") local nvim_lsp = require 'lspconfig' local c = vim.lsp.protocol.make_client_capabilities() local deps = require("nvim-deps") -rt.setup({ +vim.g.rustaceanvim = { tools = { -- rust-tools options -- how to execute terminal commands -- options right now: termopen / quickfix / toggleterm / vimux @@ -122,13 +121,28 @@ rt.setup({ local keymap_opts = {buffer = bufnr} -- Hover actions -- call twice to focus - vim.keymap.set("n", "h", rt.hover_actions.hover_actions, - keymap_opts) + vim.keymap.set("n", "K", + function() + vim.cmd.RustLsp { 'hover', 'actions' } + end, keymap_opts) -- Code action groups vim.keymap.set("n", "as", - rt.code_action_group.code_action_group, keymap_opts) - vim.keymap.set('n', 'c', rt.open_cargo_toml.open_cargo_toml) - vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) + function() + vim.cmd.RustLsp { 'hover', 'actions' } + end, keymap_opts) + vim.keymap.set('n', 'cc', + function() + vim.cmd.RustLsp('openCargo') + end, keymap_opts) + vim.keymap.set('n', 'cr', + function() + vim.cmd.RustLsp {'runnables', 'last' --[[ optional ]] } + end, keymap_opts) + vim.keymap.set('n', 'cd', + function() + vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] } + end, keymap_opts) +-- vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) local diag_float_grp = vim.api.nvim_create_augroup( "DiagnosticFloat", {clear = true}) vim.api.nvim_create_autocmd("CursorHold", { @@ -152,4 +166,4 @@ rt.setup({ name = "rt_lldb" } } -}) +} From 1fafc88bc707380e90c691308e892436968ce910 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 22:31:39 +0100 Subject: [PATCH 12/23] feat(nvim): enable inlay hints --- default.nix | 1 + init.lua | 1 + rust.lua | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index b304e5d..b06f9a4 100644 --- a/default.nix +++ b/default.nix @@ -56,6 +56,7 @@ in cmp-conventionalcommits cmp-calc rustaceanvim + lsp-inlayhints-nvim # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 plenary-nvim crates-nvim nvim-lspconfig diff --git a/init.lua b/init.lua index 439cd99..c828943 100644 --- a/init.lua +++ b/init.lua @@ -126,5 +126,6 @@ vim.api.nvim_create_autocmd('LspAttach', { function() vim.lsp.buf.format {async = true} end, opts) end }) +require("lsp-inlayhints").setup() require("completion") require("rust") diff --git a/rust.lua b/rust.lua index 04167c5..3b6e9c6 100644 --- a/rust.lua +++ b/rust.lua @@ -116,7 +116,8 @@ vim.g.rustaceanvim = { standalone = true, cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")}, capabilities = require("cmp_nvim_lsp").default_capabilities(c), - on_attach = function(_, bufnr) + on_attach = function(client, bufnr) + require("lsp-inlayhints").on_attach(client, bufnr) require('crates').setup() local keymap_opts = {buffer = bufnr} -- Hover actions From ab37924276e69558fc057de66fcaa25132b45698 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 22:49:38 +0100 Subject: [PATCH 13/23] feat(nvim): cmdline completions --- completion.lua | 36 ++++++++++++++++-------------------- default.nix | 1 + 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/completion.lua b/completion.lua index f94b568..7d142cb 100644 --- a/completion.lua +++ b/completion.lua @@ -21,12 +21,8 @@ autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) vim.opt.spell = true vim.opt.spelllang = {'en_us'} vim.lsp.handlers["textDocument/publishDiagnostics"] = - vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, - { - virtual_text = true, - } -) + vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, + {virtual_text = true}) -- Completion Plugin Setup local cmp = require 'cmp' cmp.setup({ @@ -56,7 +52,6 @@ cmp.setup({ {name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized {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 {name = 'calc'}, -- source for math calculation { name = 'spell', @@ -64,33 +59,34 @@ cmp.setup({ keep_all_entries = false, enable_in_context = function() return true end } - }, - {name = 'conventionalcommits', keyword_length = 1 }, - {name = 'crates'}, + }, {name = 'conventionalcommits', keyword_length = 1}, {name = 'crates'} }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered() }, formatting = { - fields = {'menu', 'abbr', 'kind'}, + fields = {'menu', 'abbr' --[[ 'kind' ]] }, format = function(entry, item) local menu_icon = { nvim_lsp = 'λ', vsnip = '⋗', - buffer = 'Ω', - path = '📁', - spell = '💬', - calc = '√', - crates = '📦', + buffer = '', + path = '', + spell = '¶', + calc = '√', + crates = '' } item.menu = menu_icon[entry.source.name] + if entry.source.name == "calc" then item.kind = "Math" end return item end } }) -cmp.setup.cmdline('/', { - sources = { - { name = 'buffer' }, - } +cmp.setup.cmdline('/', {sources = {{name = 'buffer'}}}) +cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({{name = 'path'}}, { + {name = 'cmdline', option = {ignore_cmds = {'Man', '!'}}} + }) }) diff --git a/default.nix b/default.nix index b06f9a4..b55e033 100644 --- a/default.nix +++ b/default.nix @@ -55,6 +55,7 @@ in cmp-spell cmp-conventionalcommits cmp-calc + cmp-cmdline rustaceanvim lsp-inlayhints-nvim # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 plenary-nvim From e33388e1e29816c325483eea7cd29062d0b13a61 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 22:49:57 +0100 Subject: [PATCH 14/23] style: nix run sys#luaformatter -- home/nvim/*.lua -i --- rust.lua | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/rust.lua b/rust.lua index 3b6e9c6..839ba0b 100644 --- a/rust.lua +++ b/rust.lua @@ -117,33 +117,30 @@ vim.g.rustaceanvim = { cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")}, capabilities = require("cmp_nvim_lsp").default_capabilities(c), on_attach = function(client, bufnr) - require("lsp-inlayhints").on_attach(client, bufnr) - require('crates').setup() + require("lsp-inlayhints").on_attach(client, bufnr) + require('crates').setup() local keymap_opts = {buffer = bufnr} -- Hover actions - -- call twice to focus + -- call twice to focus vim.keymap.set("n", "K", - function() - vim.cmd.RustLsp { 'hover', 'actions' } - end, keymap_opts) + function() + vim.cmd.RustLsp {'hover', 'actions'} + end, keymap_opts) -- Code action groups vim.keymap.set("n", "as", - function() - vim.cmd.RustLsp { 'hover', 'actions' } - end, keymap_opts) - vim.keymap.set('n', 'cc', - function() - vim.cmd.RustLsp('openCargo') - end, keymap_opts) - vim.keymap.set('n', 'cr', - function() - vim.cmd.RustLsp {'runnables', 'last' --[[ optional ]] } - end, keymap_opts) - vim.keymap.set('n', 'cd', - function() - vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] } - end, keymap_opts) --- vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) + function() + vim.cmd.RustLsp {'hover', 'actions'} + end, keymap_opts) + vim.keymap.set('n', 'cc', + function() vim.cmd.RustLsp('openCargo') end, + keymap_opts) + vim.keymap.set('n', 'cr', function() + vim.cmd.RustLsp {'runnables', 'last' --[[ optional ]] } + end, keymap_opts) + vim.keymap.set('n', 'cd', function() + vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] } + end, keymap_opts) + -- vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) local diag_float_grp = vim.api.nvim_create_augroup( "DiagnosticFloat", {clear = true}) vim.api.nvim_create_autocmd("CursorHold", { From 687270ea292f412a48aa0f7de595ed0420546852 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 22:56:38 +0100 Subject: [PATCH 15/23] feat(nvim/nix): break once neovim hits 0.10.0 --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.nix b/default.nix index b55e033..6a099c8 100644 --- a/default.nix +++ b/default.nix @@ -57,7 +57,7 @@ in cmp-calc cmp-cmdline rustaceanvim - lsp-inlayhints-nvim # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 + (if config.programs.neovim.package.version == "0.10.0" then throw "lsp-inlayhints-nvim may be removed" else lsp-inlayhints-nvim) # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 plenary-nvim crates-nvim nvim-lspconfig From 1cb41b2bd4a4045981570ca7ff1d3839fa07dfb5 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 23:23:46 +0100 Subject: [PATCH 16/23] fixup! wip: feat(nvim/rust-tools): begin migration --- default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/default.nix b/default.nix index 6a099c8..855b5db 100644 --- a/default.nix +++ b/default.nix @@ -43,6 +43,7 @@ in nvim-web-devicons fzf-vim editorconfig-nvim + vim-vsnip # tmuxline-vim nvim-dap nvim-dap-ui @@ -53,6 +54,7 @@ in cmp-buffer cmp-path cmp-spell + cmp-vsnip cmp-conventionalcommits cmp-calc cmp-cmdline From 79b18609dfef6740327768cd35f4bf1477ef572b Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 09:31:44 +0100 Subject: [PATCH 17/23] wip: feat(nvim/rust-tools): begin migration --- init.lua | 2 - rust.lua | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index c828943..17e71a2 100644 --- a/init.lua +++ b/init.lua @@ -87,7 +87,6 @@ dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end -- Setup language servers. local lspconfig = require('lspconfig') - -- Global mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions vim.keymap.set('n', 'e', vim.diagnostic.open_float) @@ -128,4 +127,3 @@ vim.api.nvim_create_autocmd('LspAttach', { }) require("lsp-inlayhints").setup() require("completion") -require("rust") diff --git a/rust.lua b/rust.lua index 839ba0b..96821a4 100644 --- a/rust.lua +++ b/rust.lua @@ -1,3 +1,4 @@ +<<<<<<< HEAD local nvim_lsp = require 'lspconfig' local c = vim.lsp.protocol.make_client_capabilities() local deps = require("nvim-deps") @@ -165,3 +166,185 @@ vim.g.rustaceanvim = { } } } +======= +local rt = require("rust-tools") +local deps = require("nvim-deps") + +rt.setup( +{ + tools = { -- rust-tools options + + -- how to execute terminal commands + -- options right now: termopen / quickfix / toggleterm / vimux + executor = require("rust-tools.executors").termopen, + + -- callback to execute once rust-analyzer is done initializing the workspace + -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" + on_initialized = nil, + + -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. + reload_workspace_from_cargo_toml = true, + + -- These apply to the default RustSetInlayHints command + inlay_hints = { + -- automatically set inlay hints (type hints) + -- default: true + auto = true, + + -- Only show inlay hints for the current line + only_current_line = false, + + -- whether to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = true, + + -- prefix for parameter hints + -- default: "<-" + parameter_hints_prefix = "<- ", + + -- prefix for all the other hints (type, chaining) + -- default: "=>" + other_hints_prefix = "=> ", + + -- whether to align to the length of the longest line in the file + max_len_align = false, + + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + + -- whether to align to the extreme right or not + right_align = false, + + -- padding from the right if right_align is true + right_align_padding = 7, + + -- The color of the hints + highlight = "Comment", + }, + + -- options same as lsp hover / vim.lsp.util.open_floating_preview() + hover_actions = { + + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, + }, + + -- Maximal width of the hover window. Nil means no max. + max_width = nil, + + -- Maximal height of the hover window. Nil means no max. + max_height = nil, + + -- whether the hover action window gets automatically focused + -- default: false + auto_focus = false, + }, + + -- settings for showing the crate graph based on graphviz and the dot + -- command + crate_graph = { + -- Backend used for displaying the graph + -- see: https://graphviz.org/docs/outputs/ + -- default: x11 + backend = "x11", + -- where to store the output, nil for no output stored (relative + -- path from pwd) + -- default: nil + output = nil, + -- true for all crates.io and external crates, false only the local + -- crates + -- default: true + full = true, + + -- List of backends found on: https://graphviz.org/docs/outputs/ + -- Is used for input validation and autocompletion + -- Last updated: 2021-08-26 + enabled_graphviz_backends = { + "bmp", + "cgimage", + "canon", + "dot", + "gv", + "xdot", + "xdot1.2", + "xdot1.4", + "eps", + "exr", + "fig", + "gd", + "gd2", + "gif", + "gtk", + "ico", + "cmap", + "ismap", + "imap", + "cmapx", + "imap_np", + "cmapx_np", + "jpg", + "jpeg", + "jpe", + "jp2", + "json", + "json0", + "dot_json", + "xdot_json", + "pdf", + "pic", + "pct", + "pict", + "plain", + "plain-ext", + "png", + "pov", + "ps", + "ps2", + "psd", + "sgi", + "svg", + "svgz", + "tga", + "tiff", + "tif", + "tk", + "vml", + "vmlz", + "wbmp", + "webp", + "xlib", + "x11", + }, + }, + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + -- standalone file support + -- setting it to false may improve startup time + standalone = true, + cmd = { (deps.rust_analyzer_path .. "/bin/rust-analyzer") }, + }, -- rust-analyzer options + + -- debugging stuff + dap = { + adapter = { + type = "executable", + command = deps.lldb_path .. "lldb-vscode", + name = "rt_lldb", + }, + }, +} +) +>>>>>>> 5df3a02 (wip: feat(nvim/rust-tools): begin migration) From 09559b017aa88967cb1fcc943bd0e2825f401ef1 Mon Sep 17 00:00:00 2001 From: u2515h Date: Wed, 27 Dec 2023 17:43:28 +0100 Subject: [PATCH 18/23] feat(nvim): removed coc --- completion.lua | 1 + default.nix | 3 +++ 2 files changed, 4 insertions(+) diff --git a/completion.lua b/completion.lua index 7d142cb..7528723 100644 --- a/completion.lua +++ b/completion.lua @@ -1,3 +1,4 @@ +<<<<<<< HEAD -- Set completeopt to have a better completion experience -- :help completeopt -- menuone: popup even when there's only one match diff --git a/default.nix b/default.nix index 855b5db..0511177 100644 --- a/default.nix +++ b/default.nix @@ -60,6 +60,9 @@ in cmp-cmdline rustaceanvim (if config.programs.neovim.package.version == "0.10.0" then throw "lsp-inlayhints-nvim may be removed" else lsp-inlayhints-nvim) # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 + cmp-conventionalcommits + cmp-calc + rust-tools-nvim plenary-nvim crates-nvim nvim-lspconfig From f25a55cfaddcd1d5b2f1b07f8f151803dc7c4b75 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 22:04:48 +0100 Subject: [PATCH 19/23] feat(nvim): switch rust-tools to rustaceanvim --- completion.lua | 8 ++++++-- default.nix | 2 +- rust.lua | 40 ++++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/completion.lua b/completion.lua index 7528723..ec4e811 100644 --- a/completion.lua +++ b/completion.lua @@ -22,8 +22,12 @@ autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) vim.opt.spell = true vim.opt.spelllang = {'en_us'} vim.lsp.handlers["textDocument/publishDiagnostics"] = - vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, - {virtual_text = true}) + vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, + { + virtual_text = true, + } +) -- Completion Plugin Setup local cmp = require 'cmp' cmp.setup({ diff --git a/default.nix b/default.nix index 0511177..c3265c2 100644 --- a/default.nix +++ b/default.nix @@ -62,7 +62,7 @@ in (if config.programs.neovim.package.version == "0.10.0" then throw "lsp-inlayhints-nvim may be removed" else lsp-inlayhints-nvim) # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 cmp-conventionalcommits cmp-calc - rust-tools-nvim + rustaceanvim plenary-nvim crates-nvim nvim-lspconfig diff --git a/rust.lua b/rust.lua index 96821a4..f8c3b06 100644 --- a/rust.lua +++ b/rust.lua @@ -1,4 +1,3 @@ -<<<<<<< HEAD local nvim_lsp = require 'lspconfig' local c = vim.lsp.protocol.make_client_capabilities() local deps = require("nvim-deps") @@ -122,26 +121,29 @@ vim.g.rustaceanvim = { require('crates').setup() local keymap_opts = {buffer = bufnr} -- Hover actions - -- call twice to focus + -- call twice to focus vim.keymap.set("n", "K", - function() - vim.cmd.RustLsp {'hover', 'actions'} - end, keymap_opts) + function() + vim.cmd.RustLsp { 'hover', 'actions' } + end, keymap_opts) -- Code action groups vim.keymap.set("n", "as", - function() - vim.cmd.RustLsp {'hover', 'actions'} - end, keymap_opts) - vim.keymap.set('n', 'cc', - function() vim.cmd.RustLsp('openCargo') end, - keymap_opts) - vim.keymap.set('n', 'cr', function() - vim.cmd.RustLsp {'runnables', 'last' --[[ optional ]] } - end, keymap_opts) - vim.keymap.set('n', 'cd', function() - vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] } - end, keymap_opts) - -- vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) + function() + vim.cmd.RustLsp { 'hover', 'actions' } + end, keymap_opts) + vim.keymap.set('n', 'cc', + function() + vim.cmd.RustLsp('openCargo') + end, keymap_opts) + vim.keymap.set('n', 'cr', + function() + vim.cmd.RustLsp {'runnables', 'last' --[[ optional ]] } + end, keymap_opts) + vim.keymap.set('n', 'cd', + function() + vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] } + end, keymap_opts) +-- vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) local diag_float_grp = vim.api.nvim_create_augroup( "DiagnosticFloat", {clear = true}) vim.api.nvim_create_autocmd("CursorHold", { @@ -166,7 +168,6 @@ vim.g.rustaceanvim = { } } } -======= local rt = require("rust-tools") local deps = require("nvim-deps") @@ -347,4 +348,3 @@ rt.setup( }, } ) ->>>>>>> 5df3a02 (wip: feat(nvim/rust-tools): begin migration) From 7da15546fc6f8c8e78cbb744ebcce4a516e7ba27 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sat, 6 Jan 2024 22:49:38 +0100 Subject: [PATCH 20/23] feat(nvim): cmdline completions --- completion.lua | 8 ++------ default.nix | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/completion.lua b/completion.lua index ec4e811..7528723 100644 --- a/completion.lua +++ b/completion.lua @@ -22,12 +22,8 @@ autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) vim.opt.spell = true vim.opt.spelllang = {'en_us'} vim.lsp.handlers["textDocument/publishDiagnostics"] = - vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, - { - virtual_text = true, - } -) + vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, + {virtual_text = true}) -- Completion Plugin Setup local cmp = require 'cmp' cmp.setup({ diff --git a/default.nix b/default.nix index c3265c2..6be9a51 100644 --- a/default.nix +++ b/default.nix @@ -62,6 +62,7 @@ in (if config.programs.neovim.package.version == "0.10.0" then throw "lsp-inlayhints-nvim may be removed" else lsp-inlayhints-nvim) # https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7620822 cmp-conventionalcommits cmp-calc + cmp-cmdline rustaceanvim plenary-nvim crates-nvim From ca84d264c30cb3ffe0f58005d760926b07f83efe Mon Sep 17 00:00:00 2001 From: u2515h Date: Sun, 14 Jan 2024 14:35:02 +0100 Subject: [PATCH 21/23] fixup! feat(nvim): switch rust-tools to rustaceanvim --- completion.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/completion.lua b/completion.lua index 7528723..7d142cb 100644 --- a/completion.lua +++ b/completion.lua @@ -1,4 +1,3 @@ -<<<<<<< HEAD -- Set completeopt to have a better completion experience -- :help completeopt -- menuone: popup even when there's only one match From 274c74b03acaf3f214e87b52c5fa8fe58c19a892 Mon Sep 17 00:00:00 2001 From: u2515h Date: Sun, 14 Jan 2024 14:35:51 +0100 Subject: [PATCH 22/23] style: fmt --- rust.lua | 307 +++++++++++++++++++++++-------------------------------- 1 file changed, 126 insertions(+), 181 deletions(-) diff --git a/rust.lua b/rust.lua index f8c3b06..6f39037 100644 --- a/rust.lua +++ b/rust.lua @@ -121,29 +121,26 @@ vim.g.rustaceanvim = { require('crates').setup() local keymap_opts = {buffer = bufnr} -- Hover actions - -- call twice to focus + -- call twice to focus vim.keymap.set("n", "K", - function() - vim.cmd.RustLsp { 'hover', 'actions' } - end, keymap_opts) + function() + vim.cmd.RustLsp {'hover', 'actions'} + end, keymap_opts) -- Code action groups vim.keymap.set("n", "as", - function() - vim.cmd.RustLsp { 'hover', 'actions' } - end, keymap_opts) - vim.keymap.set('n', 'cc', - function() - vim.cmd.RustLsp('openCargo') - end, keymap_opts) - vim.keymap.set('n', 'cr', - function() - vim.cmd.RustLsp {'runnables', 'last' --[[ optional ]] } - end, keymap_opts) - vim.keymap.set('n', 'cd', - function() - vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] } - end, keymap_opts) --- vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) + function() + vim.cmd.RustLsp {'hover', 'actions'} + end, keymap_opts) + vim.keymap.set('n', 'cc', + function() vim.cmd.RustLsp('openCargo') end, + keymap_opts) + vim.keymap.set('n', 'cr', function() + vim.cmd.RustLsp {'runnables', 'last' --[[ optional ]] } + end, keymap_opts) + vim.keymap.set('n', 'cd', function() + vim.cmd.RustLsp {'debuggables', 'last' --[[ optional ]] } + end, keymap_opts) + -- vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts) local diag_float_grp = vim.api.nvim_create_augroup( "DiagnosticFloat", {clear = true}) vim.api.nvim_create_autocmd("CursorHold", { @@ -171,180 +168,128 @@ vim.g.rustaceanvim = { local rt = require("rust-tools") local deps = require("nvim-deps") -rt.setup( -{ - tools = { -- rust-tools options +rt.setup({ + tools = { -- rust-tools options - -- how to execute terminal commands - -- options right now: termopen / quickfix / toggleterm / vimux - executor = require("rust-tools.executors").termopen, + -- how to execute terminal commands + -- options right now: termopen / quickfix / toggleterm / vimux + executor = require("rust-tools.executors").termopen, - -- callback to execute once rust-analyzer is done initializing the workspace - -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" - on_initialized = nil, + -- callback to execute once rust-analyzer is done initializing the workspace + -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" + on_initialized = nil, - -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. - reload_workspace_from_cargo_toml = true, + -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. + reload_workspace_from_cargo_toml = true, - -- These apply to the default RustSetInlayHints command - inlay_hints = { - -- automatically set inlay hints (type hints) - -- default: true - auto = true, + -- These apply to the default RustSetInlayHints command + inlay_hints = { + -- automatically set inlay hints (type hints) + -- default: true + auto = true, - -- Only show inlay hints for the current line - only_current_line = false, + -- Only show inlay hints for the current line + only_current_line = false, - -- whether to show parameter hints with the inlay hints or not - -- default: true - show_parameter_hints = true, + -- whether to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = true, - -- prefix for parameter hints - -- default: "<-" - parameter_hints_prefix = "<- ", + -- prefix for parameter hints + -- default: "<-" + parameter_hints_prefix = "<- ", - -- prefix for all the other hints (type, chaining) - -- default: "=>" - other_hints_prefix = "=> ", + -- prefix for all the other hints (type, chaining) + -- default: "=>" + other_hints_prefix = "=> ", - -- whether to align to the length of the longest line in the file - max_len_align = false, + -- whether to align to the length of the longest line in the file + max_len_align = false, - -- padding from the left if max_len_align is true - max_len_align_padding = 1, + -- padding from the left if max_len_align is true + max_len_align_padding = 1, - -- whether to align to the extreme right or not - right_align = false, + -- whether to align to the extreme right or not + right_align = false, - -- padding from the right if right_align is true - right_align_padding = 7, + -- padding from the right if right_align is true + right_align_padding = 7, - -- The color of the hints - highlight = "Comment", + -- The color of the hints + highlight = "Comment" + }, + + -- options same as lsp hover / vim.lsp.util.open_floating_preview() + hover_actions = { + + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + {"╭", "FloatBorder"}, {"─", "FloatBorder"}, + {"╮", "FloatBorder"}, {"│", "FloatBorder"}, + {"╯", "FloatBorder"}, {"─", "FloatBorder"}, + {"╰", "FloatBorder"}, {"│", "FloatBorder"} + }, + + -- Maximal width of the hover window. Nil means no max. + max_width = nil, + + -- Maximal height of the hover window. Nil means no max. + max_height = nil, + + -- whether the hover action window gets automatically focused + -- default: false + auto_focus = false + }, + + -- settings for showing the crate graph based on graphviz and the dot + -- command + crate_graph = { + -- Backend used for displaying the graph + -- see: https://graphviz.org/docs/outputs/ + -- default: x11 + backend = "x11", + -- where to store the output, nil for no output stored (relative + -- path from pwd) + -- default: nil + output = nil, + -- true for all crates.io and external crates, false only the local + -- crates + -- default: true + full = true, + + -- List of backends found on: https://graphviz.org/docs/outputs/ + -- Is used for input validation and autocompletion + -- Last updated: 2021-08-26 + enabled_graphviz_backends = { + "bmp", "cgimage", "canon", "dot", "gv", "xdot", "xdot1.2", + "xdot1.4", "eps", "exr", "fig", "gd", "gd2", "gif", "gtk", + "ico", "cmap", "ismap", "imap", "cmapx", "imap_np", "cmapx_np", + "jpg", "jpeg", "jpe", "jp2", "json", "json0", "dot_json", + "xdot_json", "pdf", "pic", "pct", "pict", "plain", "plain-ext", + "png", "pov", "ps", "ps2", "psd", "sgi", "svg", "svgz", "tga", + "tiff", "tif", "tk", "vml", "vmlz", "wbmp", "webp", "xlib", + "x11" + } + } }, - -- options same as lsp hover / vim.lsp.util.open_floating_preview() - hover_actions = { + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + -- standalone file support + -- setting it to false may improve startup time + standalone = true, + cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")} + }, -- rust-analyzer options - -- the border that is used for the hover window - -- see vim.api.nvim_open_win() - border = { - { "╭", "FloatBorder" }, - { "─", "FloatBorder" }, - { "╮", "FloatBorder" }, - { "│", "FloatBorder" }, - { "╯", "FloatBorder" }, - { "─", "FloatBorder" }, - { "╰", "FloatBorder" }, - { "│", "FloatBorder" }, - }, - - -- Maximal width of the hover window. Nil means no max. - max_width = nil, - - -- Maximal height of the hover window. Nil means no max. - max_height = nil, - - -- whether the hover action window gets automatically focused - -- default: false - auto_focus = false, - }, - - -- settings for showing the crate graph based on graphviz and the dot - -- command - crate_graph = { - -- Backend used for displaying the graph - -- see: https://graphviz.org/docs/outputs/ - -- default: x11 - backend = "x11", - -- where to store the output, nil for no output stored (relative - -- path from pwd) - -- default: nil - output = nil, - -- true for all crates.io and external crates, false only the local - -- crates - -- default: true - full = true, - - -- List of backends found on: https://graphviz.org/docs/outputs/ - -- Is used for input validation and autocompletion - -- Last updated: 2021-08-26 - enabled_graphviz_backends = { - "bmp", - "cgimage", - "canon", - "dot", - "gv", - "xdot", - "xdot1.2", - "xdot1.4", - "eps", - "exr", - "fig", - "gd", - "gd2", - "gif", - "gtk", - "ico", - "cmap", - "ismap", - "imap", - "cmapx", - "imap_np", - "cmapx_np", - "jpg", - "jpeg", - "jpe", - "jp2", - "json", - "json0", - "dot_json", - "xdot_json", - "pdf", - "pic", - "pct", - "pict", - "plain", - "plain-ext", - "png", - "pov", - "ps", - "ps2", - "psd", - "sgi", - "svg", - "svgz", - "tga", - "tiff", - "tif", - "tk", - "vml", - "vmlz", - "wbmp", - "webp", - "xlib", - "x11", - }, - }, - }, - - -- all the opts to send to nvim-lspconfig - -- these override the defaults set by rust-tools.nvim - -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer - server = { - -- standalone file support - -- setting it to false may improve startup time - standalone = true, - cmd = { (deps.rust_analyzer_path .. "/bin/rust-analyzer") }, - }, -- rust-analyzer options - - -- debugging stuff - dap = { - adapter = { - type = "executable", - command = deps.lldb_path .. "lldb-vscode", - name = "rt_lldb", - }, - }, -} -) + -- debugging stuff + dap = { + adapter = { + type = "executable", + command = deps.lldb_path .. "lldb-vscode", + name = "rt_lldb" + } + } +}) From 9fadb931686d2ace51dc4804f49d2846910775ef Mon Sep 17 00:00:00 2001 From: u2515h Date: Sun, 14 Jan 2024 16:34:26 +0100 Subject: [PATCH 23/23] feat(typst-lsp): added --- default.nix | 20 ++++++++++++++++---- init.lua | 23 +++++++++++++++++++++++ rust.lua | 4 ++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/default.nix b/default.nix index 6be9a51..dd03999 100644 --- a/default.nix +++ b/default.nix @@ -74,16 +74,28 @@ in ]; extraLuaConfig = let - paths = { + # tries to compute a package set required to make package resolution in lua + # via deps["pkg"] work + packages = file: + let + out = builtins.readFile (pkgs.runCommandLocal "extract-deps" + { nativeBuildInputs = [ pkgs.gnused ]; __contentAddressed = true; } '' + sed -nr 's/.*(deps\.(.*)_path|deps\["(.*)"\]).*/\2/p' ${file} | uniq > $out + ''); + names = lib.splitString "\n" (lib.traceVal out); + in + filter (name: name != "") names; + paths = (listToAttrs (map (name: { inherit name; value = builtins.getAttr name pkgs; }) (packages "${confDir}/*.lua"))) // { lldb = pkgs.lldb; rust_analyzer = rust-analyzer; + typst_lsp = pkgs.typst-lsp; }; pathsLua = pkgs.writeTextFile { name = "nvim-deps.lua"; text = '' - return { - ${concatStringsSep ",\n " (mapAttrsToList (name: path: ''${name}_path = "${path}"'') paths)} - } + deps = {} + ${concatStringsSep "\n " (mapAttrsToList (name: path: ''deps["${name}_path"] = "${path}"'') paths)} + return deps ''; }; confDir = lib.sourceFilesBySuffices ./. [ "lua" "vim" ]; diff --git a/init.lua b/init.lua index 17e71a2..813d7b4 100644 --- a/init.lua +++ b/init.lua @@ -125,5 +125,28 @@ vim.api.nvim_create_autocmd('LspAttach', { function() vim.lsp.buf.format {async = true} end, opts) end }) + +-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md +-- deps.typst-lsp_path +lspconfig.typst_lsp.setup { + cmd = {(deps["typst-lsp_path"] .. "/bin/typst-lsp")}, + settings = { + exportPdf = "onType", -- Choose onType, onSave or never. + serverPath = (deps["typst-lsp_path"] .. "/bin/typst-lsp"), -- Normally, there is no need to uncomment it. + } +} +lspconfig.nil_ls.setup { + cmd = {(deps.nil_path .. "/bin/nil")}, + -- https://github.com/oxalica/nil/blob/main/docs/configuration.md + settings = { + command = { + formatting = "nixpkgs-fmt", }, + }, + flake = { + autoArchive = true, + autoEvalInputs = true, + }, +} + require("lsp-inlayhints").setup() require("completion") diff --git a/rust.lua b/rust.lua index 6f39037..0f83298 100644 --- a/rust.lua +++ b/rust.lua @@ -114,7 +114,7 @@ vim.g.rustaceanvim = { -- standalone file support -- setting it to false may improve startup time standalone = true, - cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")}, + cmd = {(deps.rust-analyzer_path .. "/bin/rust-analyzer")}, capabilities = require("cmp_nvim_lsp").default_capabilities(c), on_attach = function(client, bufnr) require("lsp-inlayhints").on_attach(client, bufnr) @@ -281,7 +281,7 @@ rt.setup({ -- standalone file support -- setting it to false may improve startup time standalone = true, - cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")} + cmd = {(deps.rust-analyzer_path .. "/bin/rust-analyzer")} }, -- rust-analyzer options -- debugging stuff