diff --git a/nvim/after/ftplugin/rust.lua b/nvim/after/ftplugin/rust.lua new file mode 100644 index 0000000..b067092 --- /dev/null +++ b/nvim/after/ftplugin/rust.lua @@ -0,0 +1,9 @@ +local opt = vim.opt_local + +opt.commentstring = '// %s' +opt.shiftwidth = 4 +opt.softtabstop = 4 +opt.smartindent = true +opt.tabstop = 4 +opt.cindent = false +opt.expandtab = false diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 9df9365..882fa3c 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -4,28 +4,28 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, - "dropbar.nvim": { "branch": "master", "commit": "fd917b70535371d45285bc94f9eb6387677c6dce" }, - "gitsigns.nvim": { "branch": "main", "commit": "47c8e3e571376b24de62408fd0c9d12f0a9fc0a3" }, + "dropbar.nvim": { "branch": "master", "commit": "79847a78ec0c58f5e5c0360192b03d0cee803e95" }, + "gitsigns.nvim": { "branch": "main", "commit": "220446c8c86a280180d852efac60991eaf1a21d4" }, "haskell-tools.nvim": { "branch": "master", "commit": "65d6993eba1a56bbd5211ef13a100d26ce3e644a" }, - "kanagawa.nvim": { "branch": "master", "commit": "fe5b2c9e2549862c3dc3f3c8e9cf7ddece0f40c2" }, - "lazy.nvim": { "branch": "main", "commit": "eb4957442e3182f051b0ae11da32e06d22c190e3" }, - "lazydev.nvim": { "branch": "main", "commit": "7cbb524c85f87017df9c1ea2377a1d840ad8ed51" }, - "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, + "kanagawa.nvim": { "branch": "master", "commit": "e5f7b8a804360f0a48e40d0083a97193ee4fcc87" }, + "lazy.nvim": { "branch": "main", "commit": "1870238cf9c579c5d7eb8ea8b296f10b81978d34" }, + "lazydev.nvim": { "branch": "main", "commit": "cea5d0fb556cdc35122d9cae772e7e0ed65b4505" }, + "lualine.nvim": { "branch": "master", "commit": "6a40b530539d2209f7dc0492f3681c8c126647ad" }, "nvim-cmp": { "branch": "main", "commit": "a110e12d0b58eefcf5b771f533fc2cf3050680ac" }, "nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" }, "nvim-dap": { "branch": "master", "commit": "6f79b822997f2e8a789c6034e147d42bc6706770" }, "nvim-dap-ui": { "branch": "master", "commit": "b7267003ba4dd860350be86f75b9d9ea287cedca" }, - "nvim-lspconfig": { "branch": "master", "commit": "4d38bece98300e3e5cd24a9aa0d0ebfea4951c16" }, + "nvim-lspconfig": { "branch": "master", "commit": "cf97d2485fc3f6d4df1b79a3ea183e24c272215e" }, "nvim-nio": { "branch": "master", "commit": "7969e0a8ffabdf210edd7978ec954a47a737bbcc" }, "nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" }, - "nvim-treesitter": { "branch": "master", "commit": "cdc613c630598779dc9f975bae12a4dc7c001950" }, + "nvim-treesitter": { "branch": "master", "commit": "ebdffa78bdb16af84fb76ff6a75978496d4dcbec" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" }, "nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" }, "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, - "precognition.nvim": { "branch": "main", "commit": "9e6087fcd27dd5d2fc71b9d9471a101666c39f73" }, - "rustaceanvim": { "branch": "master", "commit": "2fa45427c01ded4d3ecca72e357f8a60fd8e46d4" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, + "precognition.nvim": { "branch": "main", "commit": "2a566f03eb06859298eff837f3a6686dfa5304a5" }, + "rustaceanvim": { "branch": "master", "commit": "f16c6eacfb7556c69ffc229e220b8555378245f0" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "trouble.nvim": { "branch": "main", "commit": "e0b35a273df58b03612255783cf475a782ede7e0" }, - "which-key.nvim": { "branch": "main", "commit": "0099511294f16b81c696004fa6a403b0ae61f7a0" } + "trouble.nvim": { "branch": "main", "commit": "4453fea6bb597830fbd58d2c484612f37b97bd8c" }, + "which-key.nvim": { "branch": "main", "commit": "af4ded85542d40e190014c732fa051bdbf88be3d" } } \ No newline at end of file diff --git a/nvim/lua/config/autocmd.lua b/nvim/lua/config/autocmd.lua index 67e595e..39368e2 100644 --- a/nvim/lua/config/autocmd.lua +++ b/nvim/lua/config/autocmd.lua @@ -33,13 +33,3 @@ vim.api.nvim_create_autocmd('BufReadPost', { end end }) - --- Set indentation for Rust -vim.api.nvim_create_autocmd('FileType', { - pattern = 'rust', - callback = function() - vim.opt_local.tabstop = 4 - vim.opt_local.shiftwidth = 4 - vim.opt_local.listchars:append { leadmultispace = '│ ' } - end -}) diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua index 939625c..b57e725 100644 --- a/nvim/lua/config/keymaps.lua +++ b/nvim/lua/config/keymaps.lua @@ -11,8 +11,8 @@ local nv = map { 'n', 'v' } n 'j' 'gj' 'Move: down by line' n 'k' 'gk' 'Move: up by line' -n 'bn' ':bn' 'Buffer: next' -n 'bp' ':bp' 'Buffer: previous' +n '' ':bn' 'Buffer: next' +n '' ':bp' 'Buffer: previous' n 'bd' ':bd' 'Buffer: delete' t '' [[]] 'Exit from terminal mode' @@ -23,7 +23,7 @@ n '' 'k' 'Window: move up' n '' 'l' 'Window: move right' -- Indentation -i '' (indent.smart_tab) { 'Indent', expr = true } +i '' (indent.smarttab) { 'Indent', expr = true } v '>' '>gv' 'Indent right' v '<' 'xd' (insert_date) 'Execute: full date' -v 'xs' ':sort' 'Execute: sort' +n 'xd' (insert_date) 'Execute: full date' +v 'xs' [[:sort]] 'Sort: by first word' -- Meta @@ -54,7 +54,6 @@ end n 'mn' (open_config) 'Meta: neovim config' n 'ml' ':Lazy' 'Meta: lazy' -n 'mm' ':Mason' 'Meta: mason' -- LSP @@ -83,7 +82,12 @@ do print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end + local function toggle_inlay_hints() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({})) + end + local buffer = ev.buf + n ',' (toggle_inlay_hints) {'LSP: show inlay hints', buffer} n 'K' (vim.lsp.buf.hover) {'LSP: show hover help', buffer} n '' (vim.lsp.buf.signature_help) {'LSP: signature help', buffer} n 'ld' (vim.lsp.buf.definition) {'LSP: definition', buffer} diff --git a/nvim/lua/config/options.lua b/nvim/lua/config/options.lua index e3fb25e..862e913 100644 --- a/nvim/lua/config/options.lua +++ b/nvim/lua/config/options.lua @@ -17,10 +17,10 @@ opt.completeopt = 'menuone,noinsert,noselect' -- Completion behavior opt.termguicolors = true -- Indentation +opt.tabstop = 2 -- 1 tab = 2 spaces opt.shiftwidth = 2 -- shift 2 spaces when tab opt.smartindent = true -- autoindent new lines opt.expandtab = false -- use spaces instead of tabs -opt.tabstop = 2 -- 1 tab = 2 spaces -- UI opt.number = true -- Show current line number @@ -45,3 +45,23 @@ vim.filetype.add { nu = 'nu', } } + +-- vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( +-- vim.lsp.handlers.hover, +-- { +-- border = 'rounded' +-- } +-- ) +-- +-- vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( +-- vim.lsp.handlers.signature_help, +-- { +-- border = 'rounded' +-- } +-- ) +-- +-- vim.diagnostic.config { +-- float = { +-- border = 'rounded' +-- } +-- } diff --git a/nvim/lua/config/plugins.lua b/nvim/lua/config/plugins.lua index 5971690..bb67132 100644 --- a/nvim/lua/config/plugins.lua +++ b/nvim/lua/config/plugins.lua @@ -53,11 +53,11 @@ return { } n 'ff' (builtin.find_files) 'Telescope: files' - n 'fb' (builtin.buffers) 'Telescope: buffers' - n 'fg' (builtin.live_grep) 'Telescope: grep' - n 'fh' (builtin.help_tags) 'Telescope: docs' - n 'fk' (builtin.keymaps) 'Telescope: keymaps' - n 'fn' (ext.notify.notify) 'Telescope: notifications' + n 'fb' (builtin.buffers) 'Telescope: buffers' + n 'fg' (builtin.live_grep) 'Telescope: grep' + n 'fh' (builtin.help_tags) 'Telescope: docs' + n 'fk' (builtin.keymaps) 'Telescope: keymaps' + n 'fn' (ext.notify.notify) 'Telescope: notifications' end, }, @@ -111,6 +111,8 @@ return { 'html', 'css', 'scss', 'javascript', 'jsdoc', 'typescript', 'tsx', 'astro', 'svelte', -- haskell 'haskell', + -- ocaml + 'ocaml', }, highlight = { enable = true }, indent = { enable = true }, @@ -157,22 +159,32 @@ return { config = function() local lsp = require 'lspconfig' local cmp = require 'cmp_nvim_lsp' + local cap = cmp.default_capabilities() - lsp.nixd.setup { - single_file_support = true, - capabilities = cmp.default_capabilities(), + local servers = { + 'clangd', + 'cssls', + 'html', + 'jsonls', + 'lua_ls', + 'nixd', + 'ocamllsp', + 'svelte', + 'tsserver', } - lsp.lua_ls.setup { - single_file_support = true, - capabilities = cmp.default_capabilities(), - } + for _, name in ipairs(servers) do + lsp[name].setup { + single_file_support = true, + capabilities = cap, + } + end local signs = { Error = "", Warn = "", - Hint = "", - Info = "󰙎", + Hint = "󱠡", + Info = "󰋼", } for sign, text in pairs(signs) do @@ -196,9 +208,9 @@ return { config = function() local trouble = require 'trouble' - n 'tt' 'Trouble diagnostics toggle' 'Trouble: Diagnostics' + n 'tt' 'Trouble diagnostics toggle' 'Trouble: Diagnostics' n 'tT' 'Trouble diagnostics toggle filter.buf=0' 'Trouble: Diagnostics (buffer)' - n 'ts' 'Trouble symbols toggle focus=false' 'Trouble: Symbols' + n 'ts' 'Trouble symbols toggle focus=false' 'Trouble: Symbols' -- n 'cl' 'Trouble lsp toggle focus=false win.position=right' 'LSP Definitions / references / ... (Trouble)' -- n 'xL' 'Trouble loclist toggle' 'Location List (Trouble)' -- n 'xQ' 'Trouble qflist toggle' 'Quickfix List (Trouble)' @@ -236,13 +248,13 @@ return { gs.setup { on_attach = function() - n 'hp' (gs.preview_hunk) 'Hunk: preview' - n 'hs' (gs.stage_hunk) 'Hunk: stage' + n 'hp' (gs.preview_hunk) 'Hunk: preview' + n 'hs' (gs.stage_hunk) 'Hunk: stage' n 'hu' (gs.undo_stage_hunk) 'Hunk: unstage' - n 'hr' (gs.reset_hunk) 'Hunk: reset' - n 'hS' (gs.stage_buffer) 'Hunk: buffer stage' - n 'hR' (gs.reset_buffer) 'Hunk: buffer reset' - n 'hd' (gs.toggle_deleted) 'Hunk: show deleted' + n 'hr' (gs.reset_hunk) 'Hunk: reset' + n 'hS' (gs.stage_buffer) 'Hunk: buffer stage' + n 'hR' (gs.reset_buffer) 'Hunk: buffer reset' + n 'hd' (gs.toggle_deleted) 'Hunk: show deleted' end } end, @@ -268,7 +280,7 @@ return { end end - n 'gd' (toggle 'DiffviewOpen') 'Git: Diff' + n 'gd' (toggle 'DiffviewOpen') 'Git: Diff' n 'gh' (toggle 'DiffviewFileHistory') 'Git: History' end }, @@ -318,14 +330,14 @@ return { local dap = require 'dap' local ui = require 'dapui' - n '' (dap.continue) 'Debugger: continue' - n '' (dap.step_over) 'Debugger: step over' - n '' (dap.step_into) 'Debugger: step into' - n '' (dap.step_out) 'Debugger: step out' - n 'db' (dap.toggle_breakpoint) 'Debugger: toggle breakpoint' + n '' (dap.continue) 'Debugger: continue' + n '' (dap.step_over) 'Debugger: step over' + n '' (dap.step_into) 'Debugger: step into' + n '' (dap.step_out) 'Debugger: step out' + n 'db' (dap.toggle_breakpoint) 'Debugger: toggle breakpoint' - n 'du' (ui.toggle) 'Debugger: toggle UI' - nv 'de' (ui.eval) 'Debugger: eval' + n 'du' (ui.toggle) 'Debugger: toggle UI' + nv 'de' (ui.eval) 'Debugger: eval' -- vim.api.nvim_set_hl(0, 'DapBreakpoint', { ctermbg = 0, fg = '#993939', bg = '#31353f' }) -- vim.api.nvim_set_hl(0, 'DapLogPoint', { ctermbg = 0, fg = '#61afef', bg = '#31353f' }) diff --git a/nvim/lua/config/plugins/nvim-cmp.lua b/nvim/lua/config/plugins/nvim-cmp.lua index 8ba88f1..911a7c0 100644 --- a/nvim/lua/config/plugins/nvim-cmp.lua +++ b/nvim/lua/config/plugins/nvim-cmp.lua @@ -1,13 +1,97 @@ +local kind_icon = { + Text = '', + Method = '󰆧', + Function = '󰊕', + Constructor = '', + Field = '󰇽', + Variable = '󰂡', + Class = '󰠱', + Interface = '', + Module = '', + Property = '󰜢', + Unit = '', + Value = '󰎠', + Enum = '', + Keyword = '󰌋', + Snippet = '', + Color = '󰏘', + File = '󰈙', + Reference = '', + Folder = '󰉋', + EnumMember = '', + Constant = '󰏿', + Struct = '', + Event = '', + Operator = '󰆕', + TypeParameter = '󰅲', +} + +local menu_icon = { + -- name + buffer = '', + -- lsp + ['rust-analyzer'] = '', + clangd = '', + cssls = '', + hls = '', + html = '', + jsonls = '', + lua_ls = '', + nixd = '󱄅', + ocamllsp = '', + svelte = '', + tsserver = '', +} + +---@param source cmp.Source +---@return string +local function get_menu_icon(source) + local name = source.name + local lsp = ( + source.source.client and + source.source.client.config and + source.source.client.config.name + ) + + return menu_icon[lsp] or menu_icon[name] or lsp or name +end + -- Reference: https://github.com/hrsh7th/nvim-cmp#recommended-configuration return function() - local cmp = require "cmp" + local cmp = require 'cmp' cmp.setup { + -- Expand snippet in buffer snippet = { expand = function(args) vim.snippet.expand(args.body) end, }, + -- Completion menu appearance + -- https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance + formatting = { + expandable_indicator = true, + fields = { 'kind', 'abbr', 'menu' }, + format = function(entry, item) + item.kind = kind_icon[item.kind] or ' ' + item.menu = get_menu_icon(entry.source) + + -- Get the completion entry text shown in the completion window. + local content = item.abbr + + -- Get the width of the current window. + local win_width = vim.api.nvim_win_get_width(0) + local max_width = math.floor(win_width * 0.2) + + if #content > max_width then + item.abbr = vim.fn.strcharpart(content, 0, max_width - 3) .. "..." + else + item.abbr = content .. (" "):rep(max_width - #content) + end + + return item + end, + }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), @@ -19,7 +103,14 @@ return function() [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }, - sources = cmp.config.sources({ { name = 'nvim_lsp' } }, { { name = 'buffer' } }) + sources = cmp.config.sources( + { + { name = 'nvim_lsp' } + }, + { + { name = 'buffer' } + } + ) } -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).