diff --git a/init.lua b/init.lua index 6f9be84..0beb9e2 100644 --- a/init.lua +++ b/init.lua @@ -14,11 +14,5 @@ vim.g.loaded_netrwPlugin = 1 require("hans") --- Diagnostic keymaps -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) -vim.keymap.set('n', 'df', vim.diagnostic.open_float, { desc = 'Open [D]iagnostic [F]loating message' }) -vim.keymap.set('n', 'dl', vim.diagnostic.setloclist, { desc = 'Open [D]iagnostics [L]ist' }) - -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/lua/hans/diagnostics.lua b/lua/hans/diagnostics.lua new file mode 100644 index 0000000..1f3ba7e --- /dev/null +++ b/lua/hans/diagnostics.lua @@ -0,0 +1,50 @@ +local M = {} + +local serverity_map = { + "DiagnosticError", + "DiagnosticWarn", + "DiagnosticInfo", + "DiagnosticHint", +} +local icon_map = { + "  ", + "  ", + "  ", + "  ", +} + +local function source_string(source) + return string.format(" [%s]", source) +end + +M.line_diagnostics = function() + local bufnr, lnum = unpack(vim.fn.getcurpos()) + local diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr, lnum - 1, {}) + if vim.tbl_isempty(diagnostics) then + return + end + + local lines = {} + + for _, diagnostic in ipairs(diagnostics) do + table.insert( + lines, + icon_map[diagnostic.severity] + .. " " + .. diagnostic.message:gsub("\n", " ") + .. source_string(diagnostic.source) + ) + end + + local floating_bufnr, _ = vim.lsp.util.open_floating_preview(lines, "plaintext", { + border = vim.g.floating_window_border_dark, + }) + + for i, diagnostic in ipairs(diagnostics) do + local message_length = #lines[i] - #source_string(diagnostic.source) + vim.api.nvim_buf_add_highlight(floating_bufnr, -1, serverity_map[diagnostic.severity], i - 1, 0, message_length) + vim.api.nvim_buf_add_highlight(floating_bufnr, -1, "DiagnosticSource", i - 1, message_length, -1) + end +end + +return M diff --git a/lua/hans/keymaps.lua b/lua/hans/keymaps.lua index 5e580ac..4d76f99 100644 --- a/lua/hans/keymaps.lua +++ b/lua/hans/keymaps.lua @@ -48,3 +48,11 @@ vim.keymap.set('n', 'bn', [[bnext]]) -- save with C-s vim.keymap.set({ 'n', 'i' }, '', [[wa!]]) + +-- Diagnostic keymaps +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) +vim.keymap.set('n', 'df', vim.diagnostic.open_float, { desc = 'Open [D]iagnostic [F]loating message' }) +vim.keymap.set("n", "dv", require("hans.diagnostics").line_diagnostics, + { buffer = bufnr, desc = 'Open [D]iagnostic [S]ource Floating message' }) +vim.keymap.set('n', 'dl', vim.diagnostic.setloclist, { desc = 'Open [D]iagnostics [L]ist' }) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index c00e9a8..6495709 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -57,7 +57,7 @@ local setup_autoformat = function() end vim.lsp.buf.format { - async = false, + async = true, -- black takes forever... we'll see filter = function(c) return c.id == client.id end, @@ -94,8 +94,8 @@ local setup_lsp = function() nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + nmap('sd', require('telescope.builtin').lsp_document_symbols, '[S]ymbols in [D]ocument') + nmap('sw', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[S]ymbols in [W]orkspace') -- See `:help K` for why this keymap nmap('K', vim.lsp.buf.hover, 'Hover Documentation') @@ -136,28 +136,30 @@ local setup_lsp = function() local venv_path = os.getenv('VIRTUAL_ENV') if venv_path ~= nil then - servers['pylsp'] = { - settings = { - pylsp = { - plugins = { - -- formatter options - black = { enabled = true }, - autopep8 = { enabled = false }, - yapf = { enabled = false }, - -- linter options - runn = { enabled = true }, - pylint = { enabled = false, executable = "pylint" }, - pyflakes = { enabled = false }, - pycodestyle = { enabled = false }, - -- type checker - pylsp_mypy = { enabled = true }, - -- auto-completion options - jedi_completion = { fuzzy = true }, - -- import sorting - pyls_isort = { enabled = true }, - }, + servers.pylsp = { + pylsp = { + plugins = { + -- formatter options + black = { enabled = true }, + autopep8 = { enabled = false }, + yapf = { enabled = false }, + -- linter options + ruff = { enabled = true }, + pylint = { enabled = false, executable = "pylint" }, + pyflakes = { enabled = false }, + pycodestyle = { enabled = false }, + mccabe = { enabled = false }, + flake8 = { enabled = false }, + -- type checker + pylsp_mypy = { enabled = false }, + -- auto-completion options + jedi_completion = { fuzzy = true }, + -- import sorting + isort = { enabled = true }, + -- code actions + rope_autoimport = { enabled = true }, }, - } + }, } end diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index b161661..e41054c 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -1,8 +1,8 @@ return { -- Useful plugin to show you pending keybinds. { 'folke/which-key.nvim', opts = {} }, + -- Set lualine as statusline { - -- Set lualine as statusline 'nvim-lualine/lualine.nvim', -- See `:help lualine.txt` opts = { @@ -14,7 +14,8 @@ return { }, }, }, - { -- File tree sidebar *chef's kiss + -- File tree sidebar *chef's kiss + { "nvim-tree/nvim-tree.lua", version = "*", dependencies = { @@ -34,6 +35,7 @@ return { vim.keymap.set('n', 'e', ":NvimTreeToggle", { desc = 'Toggle [E]xplorer' }) end }, + -- Tab bar at the top like GUI editors { 'akinsho/bufferline.nvim', version = "*", @@ -78,6 +80,7 @@ return { end) end }, + -- Pretty commandline, messages, and notifications { "folke/noice.nvim", event = "VeryLazy", @@ -102,11 +105,22 @@ return { ["cmp.entry.get_documentation"] = true, }, }, + routes = { + { + filter = { event = "msg_showmode" }, + view = "notify", + }, + }, -- you can enable a preset for easier configuration presets = { command_palette = true, -- position the cmdline and popupmenu together }, }) end + }, + -- Better vim.ui.select and vim.ui.input + { + "stevearc/dressing.nvim", + opts = {}, } }