This commit is contained in:
2026-08-05 14:37:24 +02:00
parent 6a1753b021
commit 43a703eb26
3 changed files with 43 additions and 0 deletions
@@ -0,0 +1,18 @@
local M = {}
-- This function returns project local dart, or fallsback to global
function M.executable(path)
local directory = vim.fn.isdirectory(path) == 1 and path or vim.fs.dirname(path)
local root = vim.fs.root(directory, { "pubspec.yaml" })
if root then
local fvm_dart = root .. "/.fvm/flutter_sdk/bin/dart"
if vim.fn.executable(fvm_dart) == 1 then
return fvm_dart
end
end
return "dart"
end
return M
@@ -5,8 +5,11 @@ vim.pack.add({
},
})
local dart = require("romanzy.custom.dart")
require("conform").setup({
formatters_by_ft = {
dart = { "dart_format" },
javascript = { "prettier" },
javascriptreact = { "prettier" },
typescript = { "prettier" },
@@ -16,6 +19,13 @@ require("conform").setup({
cpp = { filter = function() return false end },
h = { filter = function() return false end }
},
formatters = {
dart_format = {
command = function(_, ctx)
return dart.executable(ctx.filename)
end,
},
},
format_on_save = {
lsp_format = "fallback",
timeout_ms = 2000,
@@ -44,6 +44,7 @@ end
configure_diagnostics()
local capabilities = require("mini.completion").get_lsp_capabilities()
local dart = require("romanzy.custom.dart")
local managed_servers = {
"bashls",
"clangd",
@@ -87,6 +88,18 @@ local servers = {
tailwindcss = {},
eslint = {},
tinymist = {},
dartls = {
cmd = function(dispatchers, config)
return vim.lsp.rpc.start({
dart.executable(config.root_dir),
"language-server",
"--protocol=lsp",
}, dispatchers, {
cwd = config.root_dir,
detached = config.detached,
})
end,
},
}
for server_name, config in pairs(servers) do
@@ -101,6 +114,8 @@ mason_lspconfig.setup({
automatic_enable = managed_servers,
})
vim.lsp.enable("dartls")
local mason_registry = require("mason-registry")
mason_registry.refresh(vim.schedule_wrap(function()
for _, tool_name in ipairs(managed_tools) do