mirror of
https://github.com/chenasraf/dotfiles.git
synced 2026-05-18 01:29:06 +00:00
fix(lsp): fix lua vim global + add notification to lua executes
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
|
||||
vim.g.mapleader = ' '
|
||||
vim.g.maplocalleader = ' '
|
||||
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
table.unpack = table.unpack or unpack
|
||||
-- [[ Install `lazy.nvim` plugin manager ]]
|
||||
-- https://github.com/folke/lazy.nvim
|
||||
-- `:help lazy.nvim.txt` for more info
|
||||
|
||||
@@ -170,9 +170,20 @@ return {
|
||||
capabilities = mason_capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = { checkThirdParty = false },
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
library = {
|
||||
vim.env.VIMRUNTIME, -- helps recognize `vim` global
|
||||
'${3rd}/luv/library',
|
||||
'${3rd}/busted/library',
|
||||
},
|
||||
},
|
||||
telemetry = { enable = false },
|
||||
diagnostics = { disable = { 'missing-fields' } },
|
||||
diagnostics = {
|
||||
disable = { 'missing-fields' },
|
||||
globals = { 'vim' },
|
||||
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -187,6 +198,22 @@ return {
|
||||
},
|
||||
})
|
||||
|
||||
lsp.config('vue_ls', {
|
||||
filetypes = { 'vue', 'typescript', 'javascript' },
|
||||
init_options = {
|
||||
typescript = {
|
||||
tsdk = (function()
|
||||
local project_ts = vim.fn.getcwd() .. '/node_modules/typescript/lib'
|
||||
if vim.fn.isdirectory(project_ts) == 1 then
|
||||
return project_ts
|
||||
else
|
||||
return '' -- fallback: Volar will try global TS
|
||||
end
|
||||
end)(),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
-- Example: generic ones without custom settings
|
||||
for _, server in ipairs({ 'ast_grep', 'bashls', 'cssls', 'eslint', 'html', 'jsonls', 'rust_analyzer', 'tailwindcss' }) do
|
||||
lsp.config(server, {
|
||||
|
||||
@@ -151,9 +151,34 @@ local function copy_wrapped(before, after)
|
||||
end
|
||||
end
|
||||
|
||||
vim.keymap.set('n', '<leader><leader>x', ":%source<CR>", { desc = "Source current file", silent = true })
|
||||
vim.keymap.set('n', '<leader>x', "<Cmd>.lua<CR>", { desc = "Execute current line", silent = true })
|
||||
vim.keymap.set('v', '<leader>x', ":lua<CR>", { desc = "Execute selection", silent = true })
|
||||
vim.keymap.set('n', '<leader><leader>x', function()
|
||||
vim.cmd('%source')
|
||||
vim.notify('Sourced current file: ' .. vim.fn.expand('%'), vim.log.levels.INFO)
|
||||
end, { desc = "Source current file", silent = true })
|
||||
|
||||
vim.keymap.set('n', '<leader>x', function()
|
||||
vim.cmd('.lua')
|
||||
vim.notify('Executed current line as Lua', vim.log.levels.INFO)
|
||||
end, { desc = "Execute current line", silent = true })
|
||||
|
||||
vim.keymap.set('v', '<leader>x', function()
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local start_row, start_col = table.unpack(vim.api.nvim_buf_get_mark(bufnr, '<'))
|
||||
local end_row, end_col = table.unpack(vim.api.nvim_buf_get_mark(bufnr, '>'))
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, start_row - 1, end_row, false)
|
||||
lines[1] = string.sub(lines[1], start_col)
|
||||
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
||||
|
||||
local chunk = table.concat(lines, '\n')
|
||||
vim.notify('Executed Lua selection', vim.log.levels.INFO)
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local ok, err = pcall(load(chunk))
|
||||
if not ok then
|
||||
vim.notify('Lua error: ' .. err, vim.log.levels.ERROR)
|
||||
end
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'n', false)
|
||||
end, { desc = 'Execute selection', silent = true })
|
||||
|
||||
vim.keymap.set("n", "<leader>jc", function()
|
||||
copy_wrapped(nil, nil)
|
||||
|
||||
Reference in New Issue
Block a user