From 4742d5b88e1aa119d8271a5752167c1045ceefb1 Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Wed, 28 May 2025 17:30:44 +0200 Subject: [PATCH] misc settings --- after/ftplugin/typescript.lua | 6 +++++- lua/common.lua | 18 ++++++++++++++---- lua/plugins/lspconfig.lua | 5 +---- lua/plugins/telescope.lua | 3 ++- plugin/on-attach.lua | 16 +++++++++------- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/after/ftplugin/typescript.lua b/after/ftplugin/typescript.lua index 3a77af2..bc3858d 100644 --- a/after/ftplugin/typescript.lua +++ b/after/ftplugin/typescript.lua @@ -41,7 +41,11 @@ local function goToCSSClassDefinition() if className then require("nvim-quick-switcher").toggle("tsx", "scss", { only_existing = true }) local query = vim.treesitter.query.parse("scss", '((class_name) @cn (#eq? @cn "' .. className .. '"))') - local tree = vim.treesitter.get_node():tree() + local node = vim.treesitter.get_node() + if not node then + return false + end + local tree = node:tree() vim.fn.setqflist({}) local start, _, stop, _ = tree:root():range() local anyMatch = false diff --git a/lua/common.lua b/lua/common.lua index 97b43ca..fa3fed7 100644 --- a/lua/common.lua +++ b/lua/common.lua @@ -10,10 +10,20 @@ return { LogPoint = ".>", }, diagnostics = { - Error = " ", - Warn = " ", - Hint = " ", - Info = " ", + signs = { + text = { + [vim.diagnostic.severity.ERROR] = " ", + [vim.diagnostic.severity.WARN] = " ", + [vim.diagnostic.severity.HINT] = " ", + [vim.diagnostic.severity.INFO] = " ", + }, + numhl = { + [vim.diagnostic.severity.ERROR] = "DiagnosticSignError", + [vim.diagnostic.severity.WARN] = "DiagnosticSignWarn", + [vim.diagnostic.severity.INFO] = "DiagnosticSignInfo", + [vim.diagnostic.severity.HINT] = "DiagnosticSignHint", + }, + }, }, git = { added = " ", diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index 453fcb3..0d66208 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -88,10 +88,7 @@ return { ---@param opts PluginLspOpts config = function(_, opts) -- diagnostics - for name, icon in pairs(require("common").icons.diagnostics) do - name = "DiagnosticSign" .. name - vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" }) - end + vim.diagnostic.config(require("common").icons.diagnostics) if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and "●" diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 3e2f04f..7998fe4 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -14,7 +14,8 @@ return { local utils = require("telescope.utils") -- stylua: ignore start return { - { ',,', + { + ',,', function() builtin.fd { cwd = require("findroot")(utils.buffer_dir()) } end, diff --git a/plugin/on-attach.lua b/plugin/on-attach.lua index 69c82c6..3d52187 100644 --- a/plugin/on-attach.lua +++ b/plugin/on-attach.lua @@ -9,6 +9,12 @@ local on_attach = function(args) end -- + local function diag_jump(count) + return function() + vim.diagnostic.jump({ count = count, float = true }) + end + end + -- Mappings. -- stylua: ignore start for _, mapping in ipairs({ @@ -22,8 +28,9 @@ local on_attach = function(args) { '', vim.lsp.codelens.run, "Run code lens" }, { 'gr', function() require('telescope.builtin').lsp_references() end,"Go to references" }, { '', vim.diagnostic.open_float, "Open diagnostics" }, - { '[d', vim.diagnostic.goto_prev, "Go to previous diagnostic" }, - { ']d', vim.diagnostic.goto_next, "Go to next diagnostic" }, + { '[d', diag_jump(-1), "Go to previous diagnostic" }, + { ']d', diag_jump(1), "Go to next diagnostic" }, + { '', diag_jump(1), "Go to next diagnostic" }, { '', vim.diagnostic.setloclist, "Add buffer diagnostics to location list" }, { "dc", function() require("dap").continue() end, "Debug: Continue" }, { "dK", function() require("dap.ui.widgets").hover() end, "Debug: Hover" }, @@ -47,11 +54,6 @@ local on_attach = function(args) require("dap").repl.toggle() end, { silent = true, desc = "Toogle debug REPL" }) - if client.server_capabilities.signatureHelpProvider then - vim.cmd([[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]]) - vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float({max_width = 100, focusable = false})]]) - end - if client.server_capabilities.documentHighlightingProvider then vim.cmd([[autocmd CursorHold lua vim.lsp.buf.document_highlight()]]) vim.cmd([[autocmd CursorHoldI lua vim.lsp.buf.document_highlight()]])