lag-fix #9
6 changed files with 91 additions and 92 deletions
9
lsp/lsp_ls.lua
Normal file
9
lsp/lsp_ls.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
return {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -1,23 +1,19 @@
|
|||
return {
|
||||
{
|
||||
'windwp/nvim-autopairs',
|
||||
event = "InsertEnter",
|
||||
config = function()
|
||||
local autopairs = require("nvim-autopairs")
|
||||
autopairs.setup({
|
||||
check_ts = false,
|
||||
event = 'InsertEnter',
|
||||
opts = {
|
||||
fast_wrap = {},
|
||||
map_cr = false,
|
||||
ts_config = {
|
||||
lua = { "string" },
|
||||
dart = { "string_literal" }
|
||||
}
|
||||
})
|
||||
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
|
||||
local pcall_cmp, cmp = pcall(require, "cmp")
|
||||
if pcall_cmp then
|
||||
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done())
|
||||
end
|
||||
end
|
||||
},
|
||||
config = function(_, opts)
|
||||
-- Initialize autopairs with your choices
|
||||
require('nvim-autopairs').setup(opts)
|
||||
|
||||
-- Safely hook into cmp if it's already available
|
||||
local cmp_status, cmp = pcall(require, 'cmp')
|
||||
if cmp_status then
|
||||
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
||||
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
return {
|
||||
"github/copilot.vim",
|
||||
lazy = false,
|
||||
-- lazy = false,
|
||||
cmd = "Copilot",
|
||||
keys = {
|
||||
{
|
||||
"<C-l",
|
||||
'copilot#Accept("\\<CR>")',
|
||||
mode = "i",
|
||||
expr = true,
|
||||
replace_keycodes = false,
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
vim.g.copilot_enabled = false
|
||||
vim.g.copilot_no_tab_map = true
|
||||
vim.keymap.set('i', '<C-l>', 'copilot#Accept("\\<CR>")', {
|
||||
expr = true,
|
||||
replace_keycodes = false
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,34 +8,13 @@ return {
|
|||
},
|
||||
config = function()
|
||||
vim.opt.termguicolors = true
|
||||
-- vim.env.FLUTTER_FORCE_COLOR = "1"
|
||||
local project_root = vim.fn.getcwd()
|
||||
local analysis_excluded_folders = {
|
||||
project_root .. "/.dart_tool",
|
||||
project_root .. "/build",
|
||||
project_root .. "/ios/Pods",
|
||||
project_root .. "/android/.gradle",
|
||||
}
|
||||
local flutter_bin = vim.fn.exepath("flutter")
|
||||
if flutter_bin ~= "" then
|
||||
local flutter_sdk = vim.fn.fnamemodify(vim.fn.resolve(flutter_bin), ":h:h")
|
||||
table.insert(analysis_excluded_folders, flutter_sdk .. "/packages")
|
||||
table.insert(analysis_excluded_folders, flutter_sdk .. "/.pub-cache")
|
||||
end
|
||||
|
||||
-- Auto scroll & Color logs when new logs appear
|
||||
vim.api.nvim_create_autocmd({ "TextChanged", "BufWinEnter" }, {
|
||||
pattern = "*__FLUTTER_DEV_LOG__*",
|
||||
callback = function()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
|
||||
-- Auto-scroll logic
|
||||
if vim.bo[buf].filetype == "log" or vim.fn.bufname(buf):match("flutter%-dev%.log") then
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
local last_line = vim.api.nvim_buf_line_count(buf)
|
||||
if vim.api.nvim_get_mode().mode ~= 'i' then
|
||||
vim.api.nvim_win_set_cursor(win, { last_line, 0 })
|
||||
end
|
||||
vim.cmd("normal! G")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
@ -55,16 +34,22 @@ return {
|
|||
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
||||
on_attach = function(client, bufnr)
|
||||
client.server_capabilities.semanticTokensProvider = nil
|
||||
client.server_capabilities.documentOnTypeFormattingProvider = nil
|
||||
-- client.server_capabilities.diagnosticProvider = nil
|
||||
end,
|
||||
flags = {
|
||||
debounce_text_changes = 150, -- milliseconds
|
||||
},
|
||||
settings = {
|
||||
showTodos = true,
|
||||
completeFunctionCalls = false,
|
||||
renameFilesWithClasses = "prompt",
|
||||
enableSnippets = true,
|
||||
updateImportsOnRename = true,
|
||||
analysisExcludedFolders = analysis_excluded_folders,
|
||||
},
|
||||
},
|
||||
widget_guides = {
|
||||
enabled = false,
|
||||
enabled = true,
|
||||
},
|
||||
closing_tags = {
|
||||
enabled = false,
|
||||
|
|
|
|||
|
|
@ -10,11 +10,26 @@ return {
|
|||
require("mason").setup()
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
|
||||
-- Register global capabilities for all servers
|
||||
-- 1. Global capabilities registered natively for all servers
|
||||
vim.lsp.config("*", {
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities(),
|
||||
})
|
||||
|
||||
vim.lsp.config("lua_ls", {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
library = vim.env.VIMRUNTIME,
|
||||
checkThirdParty = false,
|
||||
},
|
||||
telemetry = { enable = false },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
local servers = {
|
||||
"lua_ls",
|
||||
"pyright",
|
||||
|
|
@ -33,51 +48,43 @@ return {
|
|||
ensure_installed = servers,
|
||||
})
|
||||
|
||||
-- Neovim 0.11+ approach: Configure and Enable
|
||||
for _, server_name in ipairs(servers) do
|
||||
if server_name == "lua_ls" then
|
||||
vim.lsp.config("lua_ls", {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = { globals = { "vim" } },
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
-- Activate the server
|
||||
if server_name ~= "dartls" then
|
||||
vim.lsp.enable(server_name)
|
||||
end
|
||||
end
|
||||
|
||||
-- Diagnostic display config
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
signs = true,
|
||||
underline = true,
|
||||
update_in_insert = false,
|
||||
float = { border = "rounded", source = true },
|
||||
severity_sort = true,
|
||||
})
|
||||
|
||||
-- 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)
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
vim.keymap.set({ "n", "v" }, "<C-.>", vim.lsp.buf.code_action, opts)
|
||||
-- Diagnostic keymaps
|
||||
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts) -- show error under cursor
|
||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous error
|
||||
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 (with filter to prevent multi-client conflicts)
|
||||
|
||||
-- Diagnostics
|
||||
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts)
|
||||
vim.keymap.set("n", "[d", function() vim.diagnostic.jump({ count = -1, float = true }) end, opts)
|
||||
vim.keymap.set("n", "]d", function() vim.diagnostic.jump({ count = 1, float = true }) end, opts)
|
||||
vim.keymap.set("n", "<leader>el", vim.diagnostic.setloclist, opts)
|
||||
|
||||
-- Explicit formatting configuration
|
||||
vim.keymap.set("n", "<leader>af", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, { buffer = ev.buf, desc = "Format file" })
|
||||
|
||||
-- Safe Format on Save scoped specifically to current buffer
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
buffer = ev.buf,
|
||||
callback = function()
|
||||
|
|
@ -130,13 +137,12 @@ return {
|
|||
{
|
||||
name = "buffer",
|
||||
keyword_length = 2,
|
||||
-- Limit indexing to only the active visible buffer to stop lag on Enter
|
||||
option = {
|
||||
get_bufnrs = function()
|
||||
return { vim.api.nvim_get_current_buf() }
|
||||
end
|
||||
}
|
||||
}, -- Triggers after typing 2 characters of a local word
|
||||
},
|
||||
{ name = "path" },
|
||||
}),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
return {
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
lazy = false, -- Treesitter must not be lazy-loaded in the new version
|
||||
lazy = false,
|
||||
build = ":TSUpdate",
|
||||
config = function()
|
||||
local ts = require("nvim-treesitter")
|
||||
|
|
@ -9,28 +9,26 @@ return {
|
|||
"dockerfile", "yaml", "bash", "json", "html",
|
||||
"css", "javascript", "sql", "markdown", "markdown_inline",
|
||||
}
|
||||
-- 1. Global Settings
|
||||
ts.setup({
|
||||
install_dir = vim.fn.stdpath("data") .. "/site",
|
||||
auto_install = true,
|
||||
highlight = {
|
||||
enable = true,
|
||||
},
|
||||
indent = {
|
||||
enable = true,
|
||||
disable = { "dart" },
|
||||
},
|
||||
})
|
||||
-- 2. Bulk Install Parsers (Asynchronous)
|
||||
ts.install(supported_languages)
|
||||
-- 3. Enable Highlighting
|
||||
local already_installed = require("nvim-treesitter.config").get_installed()
|
||||
local parsers_to_install = {}
|
||||
|
||||
for _, lang in ipairs(supported_languages) do
|
||||
if not vim.tbl_contains(already_installed, lang) then
|
||||
table.insert(parsers_to_install, lang)
|
||||
end
|
||||
end
|
||||
|
||||
if #parsers_to_install > 0 then
|
||||
ts.install(parsers_to_install)
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = supported_languages,
|
||||
callback = function()
|
||||
local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
|
||||
if lang then
|
||||
vim.treesitter.start()
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue