update to use conform

This commit is contained in:
kyasuda
2025-08-21 13:51:34 -07:00
parent 714e0ee2ad
commit 9fa25eaf5a
6 changed files with 92 additions and 132 deletions

View File

@@ -4,9 +4,7 @@ require("core.keymaps")
-- require("core.lsp-notifications") -- require("core.lsp-notifications")
require("utils.extensions") require("utils.extensions")
require("utils.telescope_extra").setup() require("utils.telescope_extra").setup()
require("utils.git_paste").setup({ require("utils.git_paste").setup({ telescope_key = "<leader>pg" })
telescope_key = "<leader>pg",
})
require("utils.treesitter.parsers.hyprlang") require("utils.treesitter.parsers.hyprlang")
require("utils.hyprland.lsp") require("utils.hyprland.lsp")
-- vim.notify = function(msg, level, opts) -- vim.notify = function(msg, level, opts)

View File

@@ -17,7 +17,7 @@ end
local spinner_frames = { "", "", "", "", "", "", "", "" } 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) local notif_data = get_notif_data(client_id, token)
if notif_data.spinner then if notif_data.spinner then
@@ -28,16 +28,17 @@ local function update_spinner(client_id, token)
hide_from_history = true, hide_from_history = true,
icon = spinner_frames[new_spinner], icon = spinner_frames[new_spinner],
replace = notif_data.notification, replace = notif_data.notification,
title = title,
}) })
vim.defer_fn(function() vim.defer_fn(function()
update_spinner(client_id, token) update_spinner(client_id, token, title)
end, 100) end, 100)
end end
end end
local function format_title(title, client_name) 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 end
local function format_message(message, percentage) 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) local message = format_message(val.message, val.percentage)
notif_data.notification = vim.notify(message, "info", { 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], icon = spinner_frames[1],
timeout = false, timeout = false,
hide_from_history = false, hide_from_history = false,
}) })
notif_data.spinner = 1 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 elseif val.kind == "report" and notif_data then
notif_data.notification = vim.notify(format_message(val.message, val.percentage), "info", { notif_data.notification = vim.notify(format_message(val.message, val.percentage), "info", {
replace = notif_data.notification, replace = notif_data.notification,
title = format_title("", vim.lsp.get_client_by_id(client_id).name),
hide_from_history = false, hide_from_history = false,
}) })
elseif val.kind == "end" and notif_data then elseif val.kind == "end" and notif_data then
notif_data.notification = vim.notify(val.message and format_message(val.message) or "Complete", "info", { notif_data.notification = vim.notify(val.message and format_message(val.message) or "Complete", "info", {
icon = "", icon = "",
replace = notif_data.notification, replace = notif_data.notification,
title = format_title("", vim.lsp.get_client_by_id(client_id).name),
timeout = 3000, timeout = 3000,
}) })
@@ -95,7 +98,7 @@ vim.lsp.handlers["window/showMessage"] = function(err, result, ctx)
"DEBUG", "DEBUG",
})[result.type] })[result.type]
vim.notify("LSP Message: " .. result.message, lvl, { vim.notify("LSP Message: " .. result.message, lvl, {
title = "LSP | " .. client.name, title = client.name,
timeout = 5000, timeout = 5000,
keep = function() keep = function()
return lvl == "ERROR" or lvl == "WARN" return lvl == "ERROR" or lvl == "WARN"

View File

@@ -1,4 +1,38 @@
return { return {
"stevearc/conform.nvim", "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",
},
},
} }

View File

@@ -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 { return {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
config = function() config = function()
@@ -37,6 +21,7 @@ return {
"docker_compose_language_service", "docker_compose_language_service",
"golangci_lint_ls", "golangci_lint_ls",
"gopls", "gopls",
"ruff",
} }
-- Define the highlight color for float border -- Define the highlight color for float border
vim.api.nvim_set_hl(0, "FloatBorder", { fg = "#89b4fa", bold = true }) vim.api.nvim_set_hl(0, "FloatBorder", { fg = "#89b4fa", bold = true })
@@ -93,40 +78,55 @@ return {
vim.lsp.enable(lsp) vim.lsp.enable(lsp)
elseif lsp == "basedpyright" then elseif lsp == "basedpyright" then
vim.lsp.config(lsp, { vim.lsp.config(lsp, {
on_init = function(client) settings = {
client.config.settings.basedpyright = basedpyright = {
vim.tbl_deep_extend("force", client.config.settings.basedpyright, { analysis = {
analysis = { autoSearchPaths = true,
autoSearchPaths = true,
diagnosticMode = "openFilesOnly",
useLibraryCodeForTypes = true,
autoFormatStrings = true,
},
diagnosticMode = "openFilesOnly", diagnosticMode = "openFilesOnly",
inlayHints = { useLibraryCodeForTypes = true,
callArgumentNames = true, autoFormatStrings = true,
}, },
allowedUntypedLibraries = true, diagnosticMode = "openFilesOnly",
reportMissingTypeStubs = true, inlayHints = {
reportImportCycles = true, callArgumentNames = true,
reportUnusedImport = true, },
}) allowedUntypedLibraries = true,
end, reportMissingTypeStubs = true,
reportImportCycles = true,
reportUnusedImport = true,
},
python = {
analysis = {
ignore = { "*" },
},
},
},
}) })
vim.lsp.enable(lsp) vim.lsp.enable(lsp)
else elseif lsp == "ruff" then
vim.lsp.enable(lsp) vim.api.nvim_create_autocmd("LspAttach", {
-- vim.lsp.config(lsp, { group = vim.api.nvim_create_augroup("lsp_attach_disable_ruff_hover", { clear = true }),
-- handlers = { callback = function(args)
-- UNNSUUPPORTED local client = vim.lsp.get_client_by_id(args.data.client_id)
-- ["textDocument/signatureHelp"] = vim.lsp.with( if client == nil then
-- vim.lsp.handlers.signature_help, return
-- { border = border } end
-- ), if client.name == "ruff" then
-- ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }), -- 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 end
vim.lsp.enable(lsp)
end end
end, end,
} }

View File

@@ -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,
}

View File

@@ -5,7 +5,7 @@ return {
lint.linters_by_ft = { lint.linters_by_ft = {
markdown = { "markdownlint" }, markdown = { "markdownlint" },
lua = { "luacheck" }, lua = { "luacheck" },
py = { "flake8", "pylint", "pydocstyle", "pycodestyle", "mypy" }, python = { "ruff" },
sh = { "shellcheck" }, sh = { "shellcheck" },
json = { "jsonlint" }, json = { "jsonlint" },
yaml = { "yamllint" }, yaml = { "yamllint" },