From c4b8190e2843fcd029e88359e262481e179694a8 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Wed, 29 Nov 2023 20:46:11 +0100 Subject: [PATCH] nvim: Nicer MD handler --- home/config/nvim/init.fnl | 2 +- home/config/nvim/plugins/cmp.fnl | 4 ++++ home/config/nvim/plugins/lsp.fnl | 39 ++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/home/config/nvim/init.fnl b/home/config/nvim/init.fnl index 927f94c..5acef5d 100644 --- a/home/config/nvim/init.fnl +++ b/home/config/nvim/init.fnl @@ -67,7 +67,7 @@ (theme.setup)) ;; Plugins (set g.mapleader " ") ; Some plugins need this, so set it before the keymap is loaded - (set o.timeoutlen 400) + (set o.timeoutlen 300) (set g.loaded_python_provider 0) ; Disable built-in providers (set g.loaded_python3_provider 0) (set g.loaded_ruby_provider 0) diff --git a/home/config/nvim/plugins/cmp.fnl b/home/config/nvim/plugins/cmp.fnl index 761a767..bc9c1e7 100644 --- a/home/config/nvim/plugins/cmp.fnl +++ b/home/config/nvim/plugins/cmp.fnl @@ -87,6 +87,10 @@ (do (set kind.kind " 󱜚 ") (set kind.menu " (TabNine)")) + (= entry.source.name :cmp_yanky) + (do + (set kind.kind " 󰅌 ") + (set kind.menu " (Clipboard)")) (do (set kind.kind (.. " " (or (. strings 1) "") diff --git a/home/config/nvim/plugins/lsp.fnl b/home/config/nvim/plugins/lsp.fnl index 3cf4024..920cb38 100644 --- a/home/config/nvim/plugins/lsp.fnl +++ b/home/config/nvim/plugins/lsp.fnl @@ -4,7 +4,8 @@ navic (require :nvim-navic) diagnostic (require :nifoc.diagnostic) augroup (vim.api.nvim_create_augroup :NifocLsp {:clear true}) - aucmd vim.api.nvim_create_autocmd] + aucmd vim.api.nvim_create_autocmd + ns (vim.api.nvim_create_namespace :nifoc_lsp_float)] (fn setup-inlay-hint-toggle [bufnr] (aucmd :InsertEnter {:callback #(vim.lsp.inlay_hint.enable bufnr false) :buffer bufnr @@ -94,4 +95,38 @@ (lsp.yamlls.setup (->> {:settings {:yaml {:schemaStore {:enable false :url ""} :schemas (schemastore.yaml.schemas)}}} - (vim.tbl_extend :force default-config))))) + (vim.tbl_extend :force default-config)))) + ;; Hacks + + (fn add-inline-highlights [bufnr] + (let [lines (vim.api.nvim_buf_get_lines bufnr 0 -1 false) + mapping {"@%S+" "@parameter" + "^%s*(Parameters:)" "@text.title" + "^%s*(Return:)" "@text.title" + "^%s*(See also:)" "@text.title" + "{%S-}" "@parameter" + "|%S-|" "@text.reference"}] + (each [l line (ipairs lines)] + (each [pattern hl_group (pairs mapping)] + (var from 1) + (while from + (var to nil) + (set (from to) (line:find pattern from)) + (when from + (vim.api.nvim_buf_set_extmark bufnr ns (- l 1) (- from 1) + {:end_col to : hl_group})) + (set from (if to (+ to 1) nil))))))) + + ;; https://github.com/MariaSolOs/dotfiles/blob/b4516aa30c2912011a7b9c9857f01dee1ba5b57f/.config/nvim/lua/lsp.lua#L260C1-L260C1 + (set vim.lsp.util.stylize_markdown + (fn [bufnr raw-contents opts] + (var contents raw-contents) + (set contents + (vim.lsp.util._normalize_markdown contents + {:width (vim.lsp.util._make_floating_popup_size contents + opts)})) + (tset vim :bo bufnr :filetype :markdown) + (vim.treesitter.start bufnr) + (vim.api.nvim_buf_set_lines bufnr 0 -1 false contents) + (add-inline-highlights bufnr) + contents)))