Seperate flutter and lsp but has log color issue

This commit is contained in:
2026-04-17 14:33:42 +02:00
parent 0372e79b79
commit c8d4ea3cd1
4 changed files with 164 additions and 62 deletions

View File

@@ -8,10 +8,12 @@ return {
},
config = function()
require("mason").setup()
local mason_lspconfig = require("mason-lspconfig")
-- We no longer need: local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Register global capabilities for all servers
vim.lsp.config("*", {
capabilities = require("cmp_nvim_lsp").default_capabilities(),
})
local servers = {
"lua_ls",
@@ -31,41 +33,36 @@ return {
ensure_installed = servers,
})
-- Neovim 0.11+ approach: Use vim.lsp.config
-- Neovim 0.11+ approach: Configure and Enable
for _, server_name in ipairs(servers) do
local config = {
capabilities = capabilities,
}
if server_name == "lua_ls" then
config.settings = {
Lua = {
diagnostics = { globals = { "vim" } },
vim.lsp.config("lua_ls", {
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
},
},
}
})
end
-- Enable the server configuration natively
vim.lsp.config(server_name, config)
-- Activate the server
vim.lsp.enable(server_name)
end
-- Diagnostic display config
vim.diagnostic.config({
virtual_text = true, -- show error inline at end of line
virtual_text = true,
signs = true,
underline = true,
update_in_insert = false, -- only update after leaving insert mode
float = {
border = "rounded",
source = true, -- shows which LSP reported the error
},
update_in_insert = false,
float = { border = "rounded", source = true },
})
-- Keybindings (unchanged)
-- Keybindings & Formatting
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local opts = { buffer = ev.buf }
-- Neovim 0.11+ provides some defaults like 'grn' (rename),
-- but keeping your custom ones is fine.
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
@@ -78,8 +75,7 @@ return {
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next error
vim.keymap.set("n", "<leader>el", vim.diagnostic.setloclist, opts) -- all errors in quickfix list
vim.keymap.set("n", "<leader>af", vim.lsp.buf.format, { desc = "Format file" }) -- manual format
-- Format on save
-- Format on save (with filter to prevent multi-client conflicts)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = ev.buf,
callback = function()
@@ -90,34 +86,13 @@ return {
})
end,
},
{
"nvim-flutter/flutter-tools.nvim",
lazy = false, -- Load on startup to ensure it handles dartls correctly
dependencies = {
"nvim-lua/plenary.nvim",
"stevearc/dressing.nvim", -- Optional but highly recommended for better UI
},
config = function()
require("flutter-tools").setup({
lsp = {
-- Pass your existing capabilities to the flutter-tools LSP config
capabilities = require("cmp_nvim_lsp").default_capabilities(),
-- You can add specific dartls settings here if needed
settings = {
showTodos = true,
completeFunctionCalls = true,
},
},
})
end,
},
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip", -- Snippet engine is usually required by cmp configs
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
},
config = function()
@@ -129,11 +104,9 @@ return {
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback) -- add this
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.confirm({ select = true })
else
@@ -146,6 +119,7 @@ return {
{ name = "luasnip" },
}, {
{ name = "buffer" },
{ name = "path" },
}),
})
end,