mirror of
https://github.com/ksyasuda/dotfiles.git
synced 2025-12-05 02:53:38 -08:00
update basedpyright and vim.diagnostic config
This commit is contained in:
@@ -73,9 +73,14 @@ local border = {
|
|||||||
o.winborder = "rounded"
|
o.winborder = "rounded"
|
||||||
|
|
||||||
vim.diagnostic.config({
|
vim.diagnostic.config({
|
||||||
virtual_text = false,
|
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,
|
signs = true,
|
||||||
underline = true,
|
underline = true,
|
||||||
float = { border = "rounded", source = true },
|
|
||||||
severity_sort = true,
|
severity_sort = true,
|
||||||
|
update_in_insert = false,
|
||||||
})
|
})
|
||||||
|
|||||||
17
.config/nvim/lua/plugins/better-diagnostic-virtual-text.lua
Normal file
17
.config/nvim/lua/plugins/better-diagnostic-virtual-text.lua
Normal 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,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -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 {
|
return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
config = function()
|
config = function()
|
||||||
local lspconfig = require("lspconfig")
|
|
||||||
vim.notify = require("notify")
|
vim.notify = require("notify")
|
||||||
local servers = {
|
local servers = {
|
||||||
"bashls",
|
"bashls",
|
||||||
@@ -82,11 +97,32 @@ return {
|
|||||||
autoSearchPaths = true,
|
autoSearchPaths = true,
|
||||||
diagnosticMode = "openFilesOnly",
|
diagnosticMode = "openFilesOnly",
|
||||||
useLibraryCodeForTypes = true,
|
useLibraryCodeForTypes = true,
|
||||||
|
autoFormatStrings = true,
|
||||||
},
|
},
|
||||||
diagnosticMode = "openFilesOnly",
|
diagnosticMode = "openFilesOnly",
|
||||||
inlayHints = {
|
inlayHints = {
|
||||||
callArgumentNames = true,
|
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)
|
vim.lsp.enable(lsp)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -6,21 +6,52 @@ return {
|
|||||||
-- syncronous formatting
|
-- syncronous formatting
|
||||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||||
|
|
||||||
-- null_ls.setup({
|
local sources = {
|
||||||
-- on_attach = function(client)
|
null_ls.builtins.completion.luasnip,
|
||||||
-- if client.supports_method "textDocument/formatting" then
|
-- null_ls.builtins.diagnostics.mypy,
|
||||||
-- vim.cmd([[
|
null_ls.builtins.diagnostics.pydoclint,
|
||||||
-- augroup LspFormatting
|
null_ls.builtins.diagnostics.markdownlint,
|
||||||
-- autocmd! * <buffer>
|
null_ls.builtins.formatting.black,
|
||||||
-- autocmd BufWritePre <buffer> lua vim.lsp.buf.format()
|
null_ls.builtins.formatting.isort,
|
||||||
-- augroup END
|
null_ls.builtins.formatting.stylua,
|
||||||
-- ]])
|
null_ls.builtins.formatting.markdownlint,
|
||||||
-- end
|
null_ls.builtins.formatting.prettier, -- handled by lsp server
|
||||||
-- end,
|
null_ls.builtins.formatting.shfmt.with({
|
||||||
-- })
|
filetypes = { "sh", "bash" },
|
||||||
-- you can reuse a shared lspconfig on_attach callback here
|
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({
|
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)
|
on_attach = function(client, bufnr)
|
||||||
if client.supports_method("textDocument/formatting") then
|
if client.supports_method("textDocument/formatting") then
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||||
@@ -28,9 +59,6 @@ return {
|
|||||||
group = augroup,
|
group = augroup,
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
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({
|
vim.lsp.buf.format({
|
||||||
async = false,
|
async = false,
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
@@ -42,32 +70,6 @@ return {
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
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,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ return {
|
|||||||
behavior = cmp.ConfirmBehavior.Replace,
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
select = false,
|
select = false,
|
||||||
}),
|
}),
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
["<Tab>"] = vim.schedule_wrap(function(fallback)
|
||||||
if cmp.visible() and has_words_before() then
|
if cmp.visible() and has_words_before() then
|
||||||
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
|
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
|
||||||
elseif luasnip.locally_jumpable(1) then
|
elseif luasnip.locally_jumpable(1) then
|
||||||
@@ -99,7 +99,16 @@ return {
|
|||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
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)
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_prev_item()
|
cmp.select_prev_item()
|
||||||
@@ -244,18 +253,6 @@ return {
|
|||||||
require("copilot_cmp.comparators").sort_text,
|
require("copilot_cmp.comparators").sort_text,
|
||||||
require("copilot_cmp.comparators").length,
|
require("copilot_cmp.comparators").length,
|
||||||
require("copilot_cmp.comparators").order,
|
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,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ return {
|
|||||||
vim = { "vint" },
|
vim = { "vint" },
|
||||||
go = { "golangcilint" },
|
go = { "golangcilint" },
|
||||||
}
|
}
|
||||||
local shellcheck = require("lint").linters.shellcheck
|
lint.linters.shellcheck.args = {
|
||||||
shellcheck.args = {
|
|
||||||
"-s",
|
"-s",
|
||||||
"bash",
|
"bash",
|
||||||
"-o",
|
"-o",
|
||||||
@@ -21,10 +20,8 @@ return {
|
|||||||
"-e",
|
"-e",
|
||||||
"2250",
|
"2250",
|
||||||
}
|
}
|
||||||
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
|
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
|
||||||
group = lint_augroup,
|
|
||||||
callback = function()
|
callback = function()
|
||||||
lint.try_lint()
|
lint.try_lint()
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user