inlay hints

This commit is contained in:
Christoph J. Scherr 2024-01-20 16:05:24 +01:00
parent 5057bd35b5
commit 16b7a39465
Signed by: PlexSheep
GPG Key ID: 7CDD0B14851A08EF
6 changed files with 104 additions and 73 deletions

View File

@ -53,6 +53,10 @@ M.mason = {
-- python
"pyright",
-- english??
"write-good"
},
}

View File

@ -2,15 +2,12 @@ local opt = vim.opt
local g = vim.g
g.maplocalleader = ";"
opt.foldmethod = "indent"
opt.foldnestmax = 10
opt.foldlevel = 4
opt.signcolumn = "yes"
opt.spelllang = "en,de"
opt.clipboard = "" -- don't just use the system clipboard
opt.wrap = false
opt.breakindent = false
opt.spell = false
opt.spell = true
opt.list = true
opt.conceallevel = 2
opt.undofile = true
@ -62,6 +59,11 @@ opt.formatoptions = "qnlmBjp" -- see :h fo-table & :h formatoptions
opt.diffopt:append { "iwhite", "indent-heuristic", "algorithm:patience" }
opt.wildmode = "longest:full,full" -- Command-line completion mode
-- Folds
-- ===
opt.foldlevel = 10000 -- start with all folds open
-- Editor UI
-- ===

View File

@ -397,6 +397,12 @@ M.ui = {
["<leader>tn"] = { "<cmd>setlocal nonumber!<cr>", "toggle line numbers" },
["<leader>trn"] = { "<cmd>setlocal nornu!<cr>", "toggle relative line numbers" },
["<leader>ts"] = { "<cmd>setlocal spell!<cr>", "toggle spell check" },
["<leader>ti"] = {
function()
require("lsp-inlayhints").toggle()
end,
"toggle inlay hints",
},
-- open windows
['<leader>"'] = { "<cmd>vsplit<cr>", "open a new window to the side" },

View File

@ -511,82 +511,97 @@ local plugins = {
"neovim/nvim-lspconfig",
},
opts = function()
-- lsp->treesitter->indent
---@param bufnr number
---@return table
local function customizeSelector(bufnr)
local function handleFallbackException(err, providerName)
if type(err) == "string" and err:match "UfoFallbackException" then
return require("ufo").getFolds(bufnr, providerName)
-- fancy display function for folds (stolen from nvim-ufo readme)
local handler = function(virtText, lnum, endLnum, width, truncate)
local newVirtText = {}
local suffix = (" 󰁂 %d "):format(endLnum - lnum)
local sufWidth = vim.fn.strdisplaywidth(suffix)
local targetWidth = width - sufWidth
local curWidth = 0
for _, chunk in ipairs(virtText) do
local chunkText = chunk[1]
local chunkWidth = vim.fn.strdisplaywidth(chunkText)
if targetWidth > curWidth + chunkWidth then
table.insert(newVirtText, chunk)
else
return require("promise").reject(err)
chunkText = truncate(chunkText, targetWidth - curWidth)
local hlGroup = chunk[2]
table.insert(newVirtText, { chunkText, hlGroup })
chunkWidth = vim.fn.strdisplaywidth(chunkText)
-- str width returned from truncate() may less than 2nd argument, need padding
if curWidth + chunkWidth < targetWidth then
suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
end
break
end
curWidth = curWidth + chunkWidth
end
return require("ufo")
.getFolds(bufnr, "lsp")
:catch(function(err)
return handleFallbackException(err, "treesitter")
end)
:catch(function(err)
return handleFallbackException(err, "indent")
end)
table.insert(newVirtText, { suffix, "MoreMsg" })
return newVirtText
end
local ft_providers = {
vim = "indent",
python = { "indent" },
git = "",
help = "",
qf = "",
fugitive = "",
fugitiveblame = "",
["neo-tree"] = "",
}
return {
open_fold_hl_timeout = 0,
preview = {
win_config = {
border = { "", "", "", "", "", "", "", "" },
winhighlight = "Normal:Folded",
winblend = 10,
},
mappings = {
scrollU = "<C-u>",
scrollD = "<C-d>",
jumpTop = "[",
jumpBot = "]",
},
},
-- Select the fold provider.
provider_selector = function(_, filetype, _)
return ft_providers[filetype] or customizeSelector
require("ufo").setup {
-- use treesitter to get the folds
provider_selector = function(bufnr, filetype, buftype)
return { "treesitter", "indent" }
end,
-- Display text for folded lines.
---@param text table
---@param lnum integer
---@param endLnum integer
---@param width integer
---@return table
fold_virt_text_handler = function(text, lnum, endLnum, width)
local suffix = " 󰇘 "
local lines = (" 󰁂 %d "):format(endLnum - lnum)
local cur_width = 0
for _, section in ipairs(text) do
cur_width = cur_width + vim.fn.strdisplaywidth(section[1])
-- apply out fancy fold display
fold_virt_text_handler = handler,
}
end,
},
{
-- enables UNIX specific stuff in vim,
-- specifically:
-- :SudoWrite
-- :SudoRead
-- :Chmod
-- and also some more, but those are easy done with shell
"tpope/vim-eunuch",
enabled = false,
lazy = false,
},
{
"nvimtools/none-ls.nvim",
optional = true,
opts = function(_, opts)
local nls = require "null-ls"
local source = nls.builtins.diagnostics.write_good.with {
diagnostics_postprocess = function(diagnostic)
diagnostic.severity = vim.diagnostic.severity.HINT
end,
}
table.insert(opts.sources, source)
end,
},
{
"lvimuser/lsp-inlayhints.nvim",
event = "LspAttach",
opts = {
inlay_hints = {
parameter_hints = { show = true },
type_hints = { show = true },
only_current_line = false,
-- highlight group
highlight = "LspInlayHint",
-- virt_text priority
priority = 0,
},
},
config = function(_, opts)
require("lsp-inlayhints").setup(opts)
vim.api.nvim_create_augroup("LspAttach_inlayhints", {})
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("LspAttach_inlayhints", {}),
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
suffix = suffix .. (" "):rep(width - cur_width - vim.fn.strdisplaywidth(lines) - 3)
table.insert(text, { suffix, "UfoFoldedEllipsis" })
table.insert(text, { lines, "Folded" })
return text
local client = vim.lsp.get_client_by_id(args.data.client_id)
require("lsp-inlayhints").on_attach(client, args.buf)
end,
}
})
-- change how the highlighting looks
vim.cmd("hi LspInlayHint guibg=bg guifg=#804d66")
end,
},
}

View File

@ -236,3 +236,7 @@ hypervisors
QEMU
virt
filetypes
Parth
Narula
wordpress
PlexSheep's

Binary file not shown.