0
0
Просмотр исходного кода

feat(neovim): use `virtual_lines` for diagnostics

Joe 10 месяцев назад
Родитель
Сommit
5fe58af2df

+ 5 - 3
.config/nvim/custom/bit-browser/lua/bit-browser/init.lua

@@ -7,12 +7,14 @@ local entry_display = require("telescope.pickers.entry_display")
 
 -- Utility function: navigate diagnostics
 local diagnostic = function(next, severity)
-    local opts = {}
+    local opts = { float = false }
     if severity then opts.severity = { min = severity } end
     if next then
-        return vim.diagnostic.goto_next(opts)
+        opts.count = 1
+        return vim.diagnostic.jump(opts)
     else
-        return vim.diagnostic.goto_prev(opts)
+        opts.count = -1
+        return vim.diagnostic.jump(opts)
     end
 end
 

+ 16 - 2
.config/nvim/lua/plugins/lsp.lua

@@ -17,8 +17,22 @@ return {
                     vim.keymap.set("n", "SR", vim.lsp.buf.rename)
                     vim.keymap.set("n", "Sx", vim.lsp.buf.code_action)
                     vim.keymap.set("n", "SI", function()
-                        vim.lsp.inlay_hint.enable(
-                            not vim.lsp.inlay_hint.is_enabled())
+                        local diagnostic_config = vim.diagnostic.config()
+                        if (vim.lsp.inlay_hint.is_enabled()) then
+                            vim.lsp.inlay_hint.enable(false)
+                            vim.diagnostic.config({
+                                virtual_lines = {
+                                    current_line = true,
+                                    format = diagnostic_config.format
+                                }
+                            })
+                        else
+                            vim.lsp.inlay_hint.enable(true)
+                            vim.diagnostic.config({
+                                virtual_lines = true,
+                                format = diagnostic_config.format
+                            })
+                        end
                     end)
                     vim.keymap.set("n", "<Space>", vim.lsp.buf.hover)
                 end

+ 7 - 1
.config/nvim/lua/plugins/style.lua

@@ -37,7 +37,13 @@ return {
                     require("status-beast").setup
             })
         vim.diagnostic.config({
-            float = { source = 'always', },
+            virtual_lines = {
+                current_line = true,
+                format = function(d)
+                    return "[" .. d.source .. "] " .. d.message
+                end
+            },
+            float = false,
             virtual_text = false,
             update_in_insert = true
         })