nvim: nice lsp icons

This commit is contained in:
Maciej Jur 2024-07-08 20:40:10 +02:00
parent 72b99a4f8e
commit 5431ef4556
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
7 changed files with 188 additions and 62 deletions

View file

@ -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

View file

@ -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" }
}

View file

@ -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
})

View file

@ -11,8 +11,8 @@ local nv = map { 'n', 'v' }
n 'j' 'gj' 'Move: down by line'
n 'k' 'gk' 'Move: up by line'
n '<Leader>bn' ':bn<CR>' 'Buffer: next'
n '<Leader>bp' ':bp<CR>' 'Buffer: previous'
n '<Tab>' ':bn<CR>' 'Buffer: next'
n '<S-Tab>' ':bp<CR>' 'Buffer: previous'
n '<Leader>bd' ':bd<CR>' 'Buffer: delete'
t '<Esc><Esc>' [[<C-\><C-n>]] 'Exit from terminal mode'
@ -23,7 +23,7 @@ n '<C-k>' '<C-w>k' 'Window: move up'
n '<C-l>' '<C-w>l' 'Window: move right'
-- Indentation
i '<Tab>' (indent.smart_tab) { 'Indent', expr = true }
i '<Tab>' (indent.smarttab) { 'Indent', expr = true }
v '>' '>gv' 'Indent right'
v '<' '<gv' 'Indent left'
v '|' (indent.normalize) 'Indent normalize'
@ -42,8 +42,8 @@ local function insert_date()
vim.api.nvim_buf_set_text(0, row - 1, col, row - 1, col, { text })
end
n '<Leader>xd' (insert_date) 'Execute: full date'
v '<Leader>xs' ':sort<CR>' 'Execute: sort'
n '<Leader>xd' (insert_date) 'Execute: full date'
v '<Leader>xs' [[:sort<CR>]] 'Sort: by first word'
-- Meta
@ -54,7 +54,6 @@ end
n '<leader>mn' (open_config) 'Meta: neovim config'
n '<leader>ml' ':Lazy<CR>' 'Meta: lazy'
n '<leader>mm' ':Mason<CR>' '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 '<C-k>' (vim.lsp.buf.signature_help) {'LSP: signature help', buffer}
n '<Leader>ld' (vim.lsp.buf.definition) {'LSP: definition', buffer}

View file

@ -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'
-- }
-- }

View file

@ -53,11 +53,11 @@ return {
}
n '<leader>ff' (builtin.find_files) 'Telescope: files'
n '<leader>fb' (builtin.buffers) 'Telescope: buffers'
n '<leader>fg' (builtin.live_grep) 'Telescope: grep'
n '<leader>fh' (builtin.help_tags) 'Telescope: docs'
n '<Leader>fk' (builtin.keymaps) 'Telescope: keymaps'
n '<leader>fn' (ext.notify.notify) 'Telescope: notifications'
n '<leader>fb' (builtin.buffers) 'Telescope: buffers'
n '<leader>fg' (builtin.live_grep) 'Telescope: grep'
n '<leader>fh' (builtin.help_tags) 'Telescope: docs'
n '<Leader>fk' (builtin.keymaps) 'Telescope: keymaps'
n '<leader>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 '<leader>tt' '<cmd>Trouble diagnostics toggle<cr>' 'Trouble: Diagnostics'
n '<leader>tt' '<cmd>Trouble diagnostics toggle<cr>' 'Trouble: Diagnostics'
n '<leader>tT' '<cmd>Trouble diagnostics toggle filter.buf=0<cr>' 'Trouble: Diagnostics (buffer)'
n '<leader>ts' '<cmd>Trouble symbols toggle focus=false<cr>' 'Trouble: Symbols'
n '<leader>ts' '<cmd>Trouble symbols toggle focus=false<cr>' 'Trouble: Symbols'
-- n '<leader>cl' '<cmd>Trouble lsp toggle focus=false win.position=right<cr>' 'LSP Definitions / references / ... (Trouble)'
-- n '<leader>xL' '<cmd>Trouble loclist toggle<cr>' 'Location List (Trouble)'
-- n '<leader>xQ' '<cmd>Trouble qflist toggle<cr>' 'Quickfix List (Trouble)'
@ -236,13 +248,13 @@ return {
gs.setup {
on_attach = function()
n '<Leader>hp' (gs.preview_hunk) 'Hunk: preview'
n '<Leader>hs' (gs.stage_hunk) 'Hunk: stage'
n '<Leader>hp' (gs.preview_hunk) 'Hunk: preview'
n '<Leader>hs' (gs.stage_hunk) 'Hunk: stage'
n '<Leader>hu' (gs.undo_stage_hunk) 'Hunk: unstage'
n '<Leader>hr' (gs.reset_hunk) 'Hunk: reset'
n '<leader>hS' (gs.stage_buffer) 'Hunk: buffer stage'
n '<leader>hR' (gs.reset_buffer) 'Hunk: buffer reset'
n '<leader>hd' (gs.toggle_deleted) 'Hunk: show deleted'
n '<Leader>hr' (gs.reset_hunk) 'Hunk: reset'
n '<leader>hS' (gs.stage_buffer) 'Hunk: buffer stage'
n '<leader>hR' (gs.reset_buffer) 'Hunk: buffer reset'
n '<leader>hd' (gs.toggle_deleted) 'Hunk: show deleted'
end
}
end,
@ -268,7 +280,7 @@ return {
end
end
n '<Leader>gd' (toggle 'DiffviewOpen') 'Git: Diff'
n '<Leader>gd' (toggle 'DiffviewOpen') 'Git: Diff'
n '<Leader>gh' (toggle 'DiffviewFileHistory') 'Git: History'
end
},
@ -318,14 +330,14 @@ return {
local dap = require 'dap'
local ui = require 'dapui'
n '<F5>' (dap.continue) 'Debugger: continue'
n '<F10>' (dap.step_over) 'Debugger: step over'
n '<F11>' (dap.step_into) 'Debugger: step into'
n '<F12>' (dap.step_out) 'Debugger: step out'
n '<leader>db' (dap.toggle_breakpoint) 'Debugger: toggle breakpoint'
n '<F5>' (dap.continue) 'Debugger: continue'
n '<F10>' (dap.step_over) 'Debugger: step over'
n '<F11>' (dap.step_into) 'Debugger: step into'
n '<F12>' (dap.step_out) 'Debugger: step out'
n '<leader>db' (dap.toggle_breakpoint) 'Debugger: toggle breakpoint'
n '<leader>du' (ui.toggle) 'Debugger: toggle UI'
nv '<leader>de' (ui.eval) 'Debugger: eval'
n '<leader>du' (ui.toggle) 'Debugger: toggle UI'
nv '<leader>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' })

View file

@ -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()
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
},
sources = cmp.config.sources({ { name = 'nvim_lsp' } }, { { name = '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).