mirror of
https://github.com/ksyasuda/dotfiles.git
synced 2025-12-05 02:53:38 -08:00
update to use conform
This commit is contained in:
@@ -4,9 +4,7 @@ require("core.keymaps")
|
||||
-- require("core.lsp-notifications")
|
||||
require("utils.extensions")
|
||||
require("utils.telescope_extra").setup()
|
||||
require("utils.git_paste").setup({
|
||||
telescope_key = "<leader>pg",
|
||||
})
|
||||
require("utils.git_paste").setup({ telescope_key = "<leader>pg" })
|
||||
require("utils.treesitter.parsers.hyprlang")
|
||||
require("utils.hyprland.lsp")
|
||||
-- vim.notify = function(msg, level, opts)
|
||||
|
||||
@@ -17,7 +17,7 @@ end
|
||||
|
||||
local spinner_frames = { "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷" }
|
||||
|
||||
local function update_spinner(client_id, token)
|
||||
local function update_spinner(client_id, token, title)
|
||||
local notif_data = get_notif_data(client_id, token)
|
||||
|
||||
if notif_data.spinner then
|
||||
@@ -28,16 +28,17 @@ local function update_spinner(client_id, token)
|
||||
hide_from_history = true,
|
||||
icon = spinner_frames[new_spinner],
|
||||
replace = notif_data.notification,
|
||||
title = title,
|
||||
})
|
||||
|
||||
vim.defer_fn(function()
|
||||
update_spinner(client_id, token)
|
||||
update_spinner(client_id, token, title)
|
||||
end, 100)
|
||||
end
|
||||
end
|
||||
|
||||
local function format_title(title, client_name)
|
||||
return client_name .. (#title > 0 and ": " .. title or "")
|
||||
return client_name .. (title and #title > 0 and ": " .. title or "")
|
||||
end
|
||||
|
||||
local function format_message(message, percentage)
|
||||
@@ -62,23 +63,25 @@ vim.lsp.handlers["$/progress"] = function(_, result, ctx)
|
||||
local message = format_message(val.message, val.percentage)
|
||||
|
||||
notif_data.notification = vim.notify(message, "info", {
|
||||
title = format_title(val.title, vim.lsp.get_client_by_id(client_id).name),
|
||||
title = format_title("", vim.lsp.get_client_by_id(client_id).name),
|
||||
icon = spinner_frames[1],
|
||||
timeout = false,
|
||||
hide_from_history = false,
|
||||
})
|
||||
|
||||
notif_data.spinner = 1
|
||||
update_spinner(client_id, result.token)
|
||||
update_spinner(client_id, result.token, val.title)
|
||||
elseif val.kind == "report" and notif_data then
|
||||
notif_data.notification = vim.notify(format_message(val.message, val.percentage), "info", {
|
||||
replace = notif_data.notification,
|
||||
title = format_title("", vim.lsp.get_client_by_id(client_id).name),
|
||||
hide_from_history = false,
|
||||
})
|
||||
elseif val.kind == "end" and notif_data then
|
||||
notif_data.notification = vim.notify(val.message and format_message(val.message) or "Complete", "info", {
|
||||
icon = "",
|
||||
replace = notif_data.notification,
|
||||
title = format_title("", vim.lsp.get_client_by_id(client_id).name),
|
||||
timeout = 3000,
|
||||
})
|
||||
|
||||
@@ -95,7 +98,7 @@ vim.lsp.handlers["window/showMessage"] = function(err, result, ctx)
|
||||
"DEBUG",
|
||||
})[result.type]
|
||||
vim.notify("LSP Message: " .. result.message, lvl, {
|
||||
title = "LSP | " .. client.name,
|
||||
title = client.name,
|
||||
timeout = 5000,
|
||||
keep = function()
|
||||
return lvl == "ERROR" or lvl == "WARN"
|
||||
|
||||
@@ -1,4 +1,38 @@
|
||||
return {
|
||||
"stevearc/conform.nvim",
|
||||
opts = {},
|
||||
opts = {
|
||||
on_init = function(client)
|
||||
require("conform").formatters.shfmt = {
|
||||
append_args = { "-i", "0", "-ci", "-sr" },
|
||||
}
|
||||
end,
|
||||
formatters_by_ft = {
|
||||
python = function(bufnr)
|
||||
if require("conform").get_formatter_info("ruff_format", bufnr).available then
|
||||
return {
|
||||
"ruff_fix",
|
||||
"ruff_format",
|
||||
"ruff_organize_imports",
|
||||
}
|
||||
else
|
||||
return { "isort", "black" }
|
||||
end
|
||||
end,
|
||||
sh = { "shfmt" },
|
||||
lua = { "stylua" },
|
||||
go = { "goimports", "gofmt" },
|
||||
javascript = { "prettier" },
|
||||
javascriptreact = { "prettier" },
|
||||
typescript = { "prettier" },
|
||||
typescriptreact = { "prettier" },
|
||||
md = { "markdownlint" },
|
||||
["*"] = { "codespell" },
|
||||
["_"] = { "trim_whitespace" },
|
||||
},
|
||||
format_on_save = {
|
||||
-- These options will be passed to conform.format()
|
||||
timeout_ms = 500,
|
||||
-- lsp_format = "fallback",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,19 +1,3 @@
|
||||
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()
|
||||
@@ -37,6 +21,7 @@ return {
|
||||
"docker_compose_language_service",
|
||||
"golangci_lint_ls",
|
||||
"gopls",
|
||||
"ruff",
|
||||
}
|
||||
-- Define the highlight color for float border
|
||||
vim.api.nvim_set_hl(0, "FloatBorder", { fg = "#89b4fa", bold = true })
|
||||
@@ -93,9 +78,8 @@ return {
|
||||
vim.lsp.enable(lsp)
|
||||
elseif lsp == "basedpyright" then
|
||||
vim.lsp.config(lsp, {
|
||||
on_init = function(client)
|
||||
client.config.settings.basedpyright =
|
||||
vim.tbl_deep_extend("force", client.config.settings.basedpyright, {
|
||||
settings = {
|
||||
basedpyright = {
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
diagnosticMode = "openFilesOnly",
|
||||
@@ -110,23 +94,39 @@ return {
|
||||
reportMissingTypeStubs = true,
|
||||
reportImportCycles = true,
|
||||
reportUnusedImport = true,
|
||||
})
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
analysis = {
|
||||
ignore = { "*" },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
vim.lsp.enable(lsp)
|
||||
else
|
||||
vim.lsp.enable(lsp)
|
||||
-- vim.lsp.config(lsp, {
|
||||
-- handlers = {
|
||||
-- UNNSUUPPORTED
|
||||
-- ["textDocument/signatureHelp"] = vim.lsp.with(
|
||||
-- vim.lsp.handlers.signature_help,
|
||||
-- { border = border }
|
||||
-- ),
|
||||
-- ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }),
|
||||
-- },
|
||||
-- })
|
||||
elseif lsp == "ruff" then
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("lsp_attach_disable_ruff_hover", { clear = true }),
|
||||
callback = function(args)
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
if client == nil then
|
||||
return
|
||||
end
|
||||
if client.name == "ruff" then
|
||||
-- Disable hover in favor of Pyright
|
||||
client.server_capabilities.hoverProvider = false
|
||||
end
|
||||
end,
|
||||
desc = "LSP: Disable hover capability from Ruff",
|
||||
})
|
||||
vim.lsp.config(lsp, {
|
||||
init_options = {
|
||||
settings = {
|
||||
configuration = vim.fn.stdpath("config") .. "lua/utils/ruff.toml",
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
vim.lsp.enable(lsp)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
return {
|
||||
"nvimtools/none-ls.nvim",
|
||||
config = function()
|
||||
local null_ls = require("null-ls")
|
||||
local helpers = require("null-ls.helpers")
|
||||
-- syncronous formatting
|
||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||
|
||||
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 })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format({
|
||||
async = false,
|
||||
bufnr = bufnr,
|
||||
filter = function(client)
|
||||
return client.name == "null-ls"
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
@@ -5,7 +5,7 @@ return {
|
||||
lint.linters_by_ft = {
|
||||
markdown = { "markdownlint" },
|
||||
lua = { "luacheck" },
|
||||
py = { "flake8", "pylint", "pydocstyle", "pycodestyle", "mypy" },
|
||||
python = { "ruff" },
|
||||
sh = { "shellcheck" },
|
||||
json = { "jsonlint" },
|
||||
yaml = { "yamllint" },
|
||||
|
||||
Reference in New Issue
Block a user