Compare commits

...

3 Commits

Author SHA1 Message Date
kyasuda
8f49547f85 update docstrings 2025-08-19 15:21:21 -07:00
kyasuda
a53991c53d update basedpyright and vim.diagnostic config 2025-08-19 14:14:57 -07:00
kyasuda
180160fee1 add better diagnostics plugin 2025-08-19 09:45:05 -07:00
10 changed files with 134 additions and 78 deletions

View File

@@ -13,6 +13,10 @@ vim.g.mapleader = " "
vim.g.maplocalleader = ","
-- Create a custom command with the given trigger, command, and description
--- @param trigger string The command trigger
--- @param command string The command to execute
--- @param description string Description of the command
--- @return nil
function create_custom_command(trigger, command, description)
vim.api.nvim_create_user_command(trigger, command, { desc = description })
end
@@ -21,6 +25,10 @@ create_custom_command("Config", "edit ~/.config/nvim", "Edit nvim configuration"
create_custom_command("Keymaps", "edit ~/.config/nvim/lua/core/keymaps.lua", "Edit Hyprland keybindings")
create_custom_command("Hypr", "edit ~/.config/hypr/hyprland.conf", "Edit Hyprland configuration")
vim.keymap.set("", "<Leader>tl", function()
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
end, { desc = "Toggle diagnostics virtual text" })
-- {{{ Basic Mappings
local basic_mappings = {
{ key = "<C-u>", cmd = "<C-u>zz", desc = "Scroll up and center", mode = "n" },

View File

@@ -73,13 +73,14 @@ local border = {
o.winborder = "rounded"
vim.diagnostic.config({
virtual_text = true,
virtual_text = {
format = function(diagnostic)
-- You can customize the display text per diagnostic
return string.format("[%s]: %s", diagnostic.code, diagnostic.message)
end,
},
signs = true,
underline = true,
float = { border = "rounded", source = true },
severity_sort = true,
update_in_insert = false,
})
vim.keymap.set("", "<Leader>tl", function()
local current = vim.diagnostic.config().virtual_text
vim.diagnostic.config({ virtual_text = not current })
end, { desc = "Toggle diagnostics virtual text" })

View File

@@ -0,0 +1,17 @@
return {
"sontungexpt/better-diagnostic-virtual-text",
event = "LspAttach",
opts = {
ui = {
wrap_line_after = 150, -- wrap the line after this length to avoid the virtual text is too long
left_kept_space = 3, --- the number of spaces kept on the left side of the virtual text, make sure it enough to custom for each line
right_kept_space = 3, --- the number of spaces kept on the right side of the virtual text, make sure it enough to custom for each line
arrow = "",
up_arrow = "",
down_arrow = "",
above = false, -- the virtual text will be displayed above the line
},
priority = 2003, -- the priority of virtual text
inline = true,
},
}

View File

@@ -1,9 +0,0 @@
return {
"https://git.sr.ht/~whynothugo/lsp_lines.nvim",
config = function()
-- lsp_lines
vim.diagnostic.config({ virtual_text = false })
-- --
vim.keymap.set("", "<Leader>tl", require("lsp_lines").toggle, { desc = "Toggle lsp_lines" })
end,
}

View File

@@ -1,7 +1,22 @@
local function set_python_path(path)
local clients = vim.lsp.get_clients({
bufnr = vim.api.nvim_get_current_buf(),
name = "basedpyright",
})
for _, client in ipairs(clients) do
if client.settings then
client.settings.python = vim.tbl_deep_extend("force", client.settings.python or {}, { pythonPath = path })
else
client.config.settings =
vim.tbl_deep_extend("force", client.config.settings, { python = { pythonPath = path } })
end
client:notify("workspace/didChangeConfiguration", { settings = nil })
end
end
return {
"neovim/nvim-lspconfig",
config = function()
local lspconfig = require("lspconfig")
vim.notify = require("notify")
local servers = {
"bashls",
@@ -82,11 +97,32 @@ return {
autoSearchPaths = true,
diagnosticMode = "openFilesOnly",
useLibraryCodeForTypes = true,
autoFormatStrings = true,
},
diagnosticMode = "openFilesOnly",
inlayHints = {
callArgumentNames = true,
},
allowedUntypedLibraries = true,
reportMissingTypeStubs = false,
reportImportCycles = true,
reportUnusedImport = true,
on_attach = function(client, bufnr)
vim.api.nvim_buf_create_user_command(bufnr, "LspPyrightOrganizeImports", function()
client:exec_cmd({
command = "basedpyright.organizeimports",
arguments = { vim.uri_from_bufnr(bufnr) },
})
end, {
desc = "Organize Imports",
})
vim.api.nvim_buf_create_user_command(bufnr, "LspPyrightSetPythonPath", set_python_path, {
desc = "Reconfigure basedpyright with the provided python path",
nargs = 1,
complete = "file",
})
end,
})
vim.lsp.enable(lsp)
else

View File

@@ -6,21 +6,52 @@ return {
-- syncronous formatting
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
-- null_ls.setup({
-- on_attach = function(client)
-- if client.supports_method "textDocument/formatting" then
-- vim.cmd([[
-- augroup LspFormatting
-- autocmd! * <buffer>
-- autocmd BufWritePre <buffer> lua vim.lsp.buf.format()
-- augroup END
-- ]])
-- end
-- end,
-- })
-- you can reuse a shared lspconfig on_attach callback here
local sources = {
null_ls.builtins.completion.luasnip,
-- null_ls.builtins.diagnostics.mypy,
null_ls.builtins.diagnostics.pydoclint,
null_ls.builtins.diagnostics.markdownlint,
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.isort,
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.markdownlint,
null_ls.builtins.formatting.prettier, -- handled by lsp server
null_ls.builtins.formatting.shfmt.with({
filetypes = { "sh", "bash" },
extra_args = { "-i", "0", "-ci", "-sr" },
}),
null_ls.builtins.formatting.gofmt,
null_ls.builtins.formatting.goimports,
null_ls.builtins.formatting.goimports_reviser,
null_ls.builtins.hover.printenv,
}
require("null-ls").setup({
border = "rounded",
cmd = { "nvim" },
debounce = 250,
debug = false,
default_timeout = 5000,
diagnostic_config = {
virtual_text = false,
signs = true,
underline = true,
float = { border = "rounded", source = true },
severity_sort = true,
},
-- diagnostics_format = "#{m}",
diagnostics_format = "[#{c}] #{m} (#{s})",
fallback_severity = vim.diagnostic.severity.ERROR,
log_level = "warn",
notify_format = "[null-ls] %s",
on_init = nil,
on_exit = nil,
root_dir = require("null-ls.utils").root_pattern(".null-ls-root", "Makefile", ".git"),
root_dir_async = nil,
should_attach = nil,
sources = sources,
temp_dir = nil,
update_in_insert = false,
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
@@ -28,9 +59,6 @@ return {
group = augroup,
buffer = bufnr,
callback = function()
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
-- on later neovim version, you should use vim.lsp.buf.format({ async = false }) instead
-- vim.lsp.buf.formatting_sync()
vim.lsp.buf.format({
async = false,
bufnr = bufnr,
@@ -42,32 +70,6 @@ return {
})
end
end,
sources = {
null_ls.builtins.completion.luasnip,
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.isort,
null_ls.builtins.diagnostics.mypy,
null_ls.builtins.diagnostics.markdownlint,
null_ls.builtins.diagnostics.pylint,
-- null_ls.builtins.diagnostics.pydocstyle.with({
-- extra_arags = { "--config=$ROOT/setup.cfg" },
-- }),
-- null_ls.builtins.diagnostics.pydoclint,
null_ls.builtins.formatting.stylua,
-- null_ls.builtins.formatting.stylua.with({
-- extra_args = { '--config-path', vim.fn.expand('~/.config/stylua.toml') },
-- }),
null_ls.builtins.formatting.markdownlint,
null_ls.builtins.formatting.prettier, -- handled by lsp server
null_ls.builtins.formatting.shfmt.with({
filetypes = { "sh", "bash" },
extra_args = { "-i", "0", "-ci", "-sr" },
}),
null_ls.builtins.formatting.gofmt,
null_ls.builtins.formatting.goimports,
null_ls.builtins.formatting.goimports_reviser,
-- null_ls.builtins.diagnostics.actionlint,
},
})
end,
}

View File

@@ -91,7 +91,7 @@ return {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
}),
["<Tab>"] = cmp.mapping(function(fallback)
["<Tab>"] = vim.schedule_wrap(function(fallback)
if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.locally_jumpable(1) then
@@ -99,7 +99,16 @@ return {
else
fallback()
end
end, { "i", "s" }),
end),
-- ["<Tab>"] = cmp.mapping(function(fallback)
-- if cmp.visible() and has_words_before() then
-- cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
-- elseif luasnip.locally_jumpable(1) then
-- luasnip.jump(1)
-- else
-- fallback()
-- end
-- end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
@@ -244,18 +253,6 @@ return {
require("copilot_cmp.comparators").sort_text,
require("copilot_cmp.comparators").length,
require("copilot_cmp.comparators").order,
-- Below is the default comparitor list and order for nvim-cmp
cmp.config.compare.offset,
-- cmp.config.compare.scopes, --this is commented in nvim-cmp too
cmp.config.compare.exact,
cmp.config.compare.score,
cmp.config.compare.recently_used,
cmp.config.compare.locality,
cmp.config.compare.kind,
cmp.config.compare.sort_text,
cmp.config.compare.length,
cmp.config.compare.order,
},
},
})

View File

@@ -12,8 +12,7 @@ return {
vim = { "vint" },
go = { "golangcilint" },
}
local shellcheck = require("lint").linters.shellcheck
shellcheck.args = {
lint.linters.shellcheck.args = {
"-s",
"bash",
"-o",
@@ -21,10 +20,8 @@ return {
"-e",
"2250",
}
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,

View File

@@ -2,6 +2,13 @@ local M = {}
local map = vim.keymap.set
local opts = { noremap = true, silent = true }
--- Set keybindings from a table of mappings.
--- @param bindings table A list of keybinding mappings.
--- Each mapping should be a table with the following keys:
--- - mode: string, the mode in which the keybinding applies (e.g., 'n', 'i', 'v').
--- - key: string, the key to bind.
--- - cmd: string, the command to execute when the key is pressed.
--- - opts: table, optional, additional options for the keybinding (default:
function M.set_keybindings(bindings)
for _, binding in ipairs(bindings) do
map(binding.mode, binding.key, binding.cmd, binding.opts or opts)

View File

@@ -4,8 +4,8 @@ local whichkey = require("which-key")
vim.notify = require("notify")
---Helper function to add mappings to which-key
---@parm mappings table : List of mappings to add to which-key
---@parm group table : Group to add mappings to (optional)
---@param mappings table List of mappings to add
---@param group table Group to add mappings to (optional)
---@return nil
---@usage addToWhichKey(mappings, group)
---@example addToWhichKey({{key = "n", cmd = "next", mode = "n", desc = "Next Line", group = "Navigation"}, {key = "t", group = "example"})