update to lua config

This commit is contained in:
2025-02-14 01:48:45 -08:00
parent 0f860cf709
commit a95aab0e51
65 changed files with 254 additions and 930 deletions

View File

@@ -0,0 +1,8 @@
require("copilot_cmp").setup({
suggestion = { enabled = false },
panel = { enabled = false }
-- method = "getCompletionsCycling",
-- formatters = {
-- insert_text = require("copilot_cmp.format").remove_existing
-- }
})

10
lua/plugins/lsp/init.lua Normal file
View File

@@ -0,0 +1,10 @@
require('plugins.lsp.copilot-cmp')
require('plugins.lsp.lsp-format')
require('plugins.lsp.lsp-kind')
require('plugins.lsp.lspconfig')
-- require('plugins.lsp.lspfuzzy')
require('plugins.lsp.lsplines')
require('plugins.lsp.luasnip')
require('plugins.lsp.null-ls')
require('plugins.lsp.nvim-cmp')
require('plugins.lsp.nvim-lint')

View File

@@ -0,0 +1 @@
-- require("lsp-format").setup {}

View File

@@ -0,0 +1,33 @@
-- lspkind.lua
local lspkind = require("lspkind")
lspkind.init({
preset = 'default',
symbol_map = {
Copilot = "",
Function = "󰊕",
Text = "󰊄",
Method = "󰆧",
Operator = "󰆕",
Keyword = "󰌋",
Variable = "󰂡",
Field = "󰇽",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "",
Value = "󰎠",
Enum = "",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "",
Event = "",
TypeParameter = "󰅲",
},
})
vim.api.nvim_set_hl(0, "CmpItemKindCopilot", {fg ="#6CC644"})

View File

@@ -0,0 +1,203 @@
-- local opts = { noremap = true, silent = true }
-- vim.api.nvim_set_keymap('n', '<space>e',
-- '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
-- vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>',
-- opts)
-- vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>',
-- opts)
-- vim.api.nvim_set_keymap('n', '<space>q',
-- '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
-- set in ~/.config/nvim/keybindings.vim
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-s>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
-- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
-- highlighting things under cursor
-- if client.resolved_capabilities.document_highlight then
-- vim.cmd [[
-- hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
-- hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
-- hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
-- augroup lsp_document_highlight
-- autocmd! * <buffer>
-- autocmd! CursorHold <buffer> lua vim.lsp.buf.document_highlight()
-- autocmd! CursorMoved <buffer> lua vim.lsp.buf.clear_references()
-- augroup END
-- ]]
-- end
end
-- vim.cmd [[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]]
-- vim.cmd [[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]]
-- squared corners
-- local border = {
-- {"┌", "FloatBorder"},
-- {"─", "FloatBorder"},
-- {"┐", "FloatBorder"},
-- {"|", "FloatBorder"},
-- {"┘", "FloatBorder"},
-- {"─", "FloatBorder"},
-- {"└", "FloatBorder"},
-- {"|", "FloatBorder"},
-- }
-- rounded
local border = {
{ "", "FloatBorder" }, { "", "FloatBorder" }, { "", "FloatBorder" },
{ "", "FloatBorder" }, { "", "FloatBorder" }, { "", "FloatBorder" },
{ "", "FloatBorder" }, { "", "FloatBorder" }
}
local handlers = {
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover,
{ border = border }),
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers
.signature_help,
{ border = border })
}
-- local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
-- function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
-- opts = {
-- { "border", border },
-- }
-- opts.border = opts.border or border
-- return orig_util_open_floating_preview(contents, syntax, opts, ...)
-- end
local DEFAULT_SETTINGS = {
ui = {
icons = {
-- The list icon to use for installed servers.
server_installed = "",
-- The list icon to use for servers that are pending installation.
server_pending = "",
-- The list icon to use for servers that are not installed.
server_uninstalled = ""
},
keymaps = {
-- Keymap to expand a server in the UI
toggle_server_expand = "<CR>",
-- Keymap to install a server
install_server = "i",
-- Keymap to reinstall/update a server
update_server = "u",
-- Keymap to update all installed servers
update_all_servers = "U",
-- Keymap to uninstall a server
uninstall_server = "X"
}
},
-- The directory in which to install all servers.
-- install_root_dir = "/home/sudacode/.vim/lsp",
pip = {
-- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior
-- and is not recommended.
--
-- Example: { "--proxy", "https://proxyserver" }
install_args = {}
},
on_attach = on_attach,
handlers = handlers,
-- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when
-- debugging issues with server installations.
log_level = vim.log.levels.INFO,
-- Limit for the maximum amount of servers to be installed at the same time. Once this limit is reached, any further
-- servers that are requested to be installed will be put in a queue.
max_concurrent_installers = 4
}
vim.diagnostic.config({
virtual_text = true,
signs = true,
underline = false,
update_in_insert = false,
severity_sort = true
})
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
function PrintDiagnostics(opts, bufnr, line_nr, client_id)
bufnr = bufnr or 0
line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1)
opts = opts or { ['lnum'] = line_nr }
local line_diagnostics = vim.diagnostic.get(bufnr, opts)
if vim.tbl_isempty(line_diagnostics) then return end
local diagnostic_message = ""
for i, diagnostic in ipairs(line_diagnostics) do
diagnostic_message = diagnostic_message ..
string.format("%d: %s", i,
diagnostic.message or "")
print(diagnostic_message)
if i ~= #line_diagnostics then
diagnostic_message = diagnostic_message .. "\n"
end
end
vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {})
end
-- vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]]
-- Register a handler that will be called for each installed server when it's ready (i.e. when installation is finished
-- or if the server is already installed).
-- local servers = { 'jedi_language_server', 'bashls', 'vimls', 'yamlls', 'dockerls', 'rust_analyzer', 'clangd', 'ansiblels' }
-- for _, lsp in pairs(servers) do
-- require('lspconfig')[lsp].setup {
-- on_attach = on_attach,
-- handlers = handlers,
-- flags = {
-- -- This will be the default in neovim 0.7+
-- debounce_text_changes = 150,
-- }
-- }
-- end
-- local plugins_path = vim.fn.stdpath("data") .. "site/autoload/plug.vim"
-- local dir_list = vim.fn.glob(plugins_path .. "/*", true, true)
-- local library_table = {}
-- for _, v in ipairs(dir_list) do
-- library_table[v .. "/lua"] = true
-- end
-- library_table[vim.fn.expand("$VIMRUNTIME/lua")] = true
-- library_table[vim.fn.stdpath("config") .. "/lua"] = true
-- require('lspconfig').sumneko_lua.setup({
-- settings = {
-- Lua = {
-- diagnostics = { globals = { "vim" } },
-- workspace = { library = library_table },
-- },
-- },
-- })
-- -- require 'lspconfig'.bashls.setup {}

View File

@@ -0,0 +1,16 @@
require('lspfuzzy').setup {
methods = 'all', -- either 'all' or a list of LSP methods (see below)
jump_one = true, -- jump immediately if there is only one location
save_last = false, -- save last location results for the :LspFuzzyLast command
callback = nil, -- callback called after jumping to a location
fzf_preview = { -- arguments to the FZF '--preview-window' option
'right:+{2}-/2' -- preview on the right and centered on entry
},
fzf_action = { -- FZF actions
['ctrl-t'] = 'tab split', -- go to location in a new tab
['ctrl-v'] = 'vsplit', -- go to location in a vertical split
['ctrl-x'] = 'split', -- go to location in a horizontal split
},
fzf_modifier = ':~:.', -- format FZF entries, see |filename-modifiers|
fzf_trim = false, -- trim FZF entries
}

View File

@@ -0,0 +1,6 @@
require("lsp_lines").setup()
-- Disable virtual_text since it's redundant due to lsp_lines.
vim.diagnostic.config({ virtual_text = false })
vim.keymap.set("", "<Leader>tl", require("lsp_lines").toggle,
{ desc = "Toggle lsp_lines" })

View File

@@ -0,0 +1 @@
require("luasnip.loaders.from_vscode").lazy_load()

View File

@@ -0,0 +1,58 @@
local null_ls = require("null-ls")
local helpers = require("null-ls.helpers")
-- syncronous formatting
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
require("null-ls").setup({
-- you can reuse a shared lspconfig on_attach callback here
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()
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
-- on later neovim version, you should use vim.lsp.buf.format({ async = false }) instead
-- vim.lsp.buf.formatting_sync()
vim.lsp.buf.format({
async = false,
bufnr = bufnr,
filter = function(client)
return client.name == "null-ls"
end
})
end,
})
end
end,
sources = {
null_ls.builtins.completion.luasnip,
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.isort,
null_ls.builtins.diagnostics.mypy,
null_ls.builtins.diagnostics.markdownlint,
null_ls.builtins.diagnostics.pylint,
null_ls.builtins.diagnostics.pycodestyle,
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.diagnostics.actionlint,
}
})
-- null_ls.setup({
-- on_attach = function(client)
-- if client.supports_method "textDocument/formatting" then
-- vim.cmd([[
-- augroup LspFormatting
-- autocmd! * <buffer>
-- autocmd BufWritePre <buffer> lua vim.lsp.buf.format()
-- augroup END
-- ]])
-- end
-- end,
-- })

View File

@@ -0,0 +1,275 @@
-- Setup nvim-cmp.
local cmp = require 'cmp'
local lspkind = require('lspkind')
local lspconfig = require('lspconfig')
-- luasnip setup
local luasnip = require 'luasnip'
local highlight = require('cmp.utils.highlight')
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match(
"^%s*$") == nil
end
lspkind.init({ symbol_map = { Copilot = "" } })
vim.api.nvim_set_hl(0, "CmpItemKindCopilot", { fg = "#6CC644" })
cmp.setup({
snippet = {
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end
},
capabilities = capabilities,
mapping = {
['<C-p>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { 'i', 's' }),
['<C-n>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { 'i', 's' }),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = false
},
-- ["<Tab>"] = cmp.mapping(function(fallback)
-- if cmp.visible() then
-- cmp.select_next_item()
-- elseif luasnip.expand_or_jumpable() then
-- luasnip.expand_or_jump()
-- else
-- fallback()
-- end
-- end, { "i", "s" }),
["<Tab>"] = vim.schedule_wrap(function(fallback)
if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end),
['<S-Tab>'] = cmp.mapping(function()
if cmp.visible() then cmp.select_prev_item() end
end, { "i", "s" })
},
window = {
completion = {
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
col_offset = -3,
side_padding = 0,
border = "rounded",
borderchars = {
"", "", "", "", "", "", "", ""
}
},
documentation = {
border = "rounded",
borderchars = {
"", "", "", "", "", "", "", ""
}
-- padding = 15,
}
},
formatting = {
-- options: 'text', 'text_symbol', 'symbol_text', 'symbol'
-- mode = 'symbol_text',
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
local kind = require("lspkind").cmp_format({
mode = "symbol_text",
maxwidth = 75,
symbol_map = {
Copilot = "",
Function = "󰊕",
Text = "󰊄",
Method = "󰆧",
Operator = "󰆕",
Keyword = "󰌋",
Variable = "󰂡",
Field = "󰇽",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "",
Value = "󰎠",
Enum = "",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "",
Event = "",
TypeParameter = "󰅲"
}
})(entry, vim_item)
local strings = vim.split(kind.kind, "%s", { trimempty = true })
kind.kind = " " .. strings[1] .. " "
kind.menu = " (" .. strings[2] .. ")"
return kind
end
-- format = lspkind.cmp_format({
-- mode = 'symbol_text', -- show only symbol annotations
-- menu = ({
-- buffer = "[Buffer]",
-- nvim_lsp = "[LSP]",
-- luasnip = "[LuaSnip]",
-- nvim_lua = "[Lua]",
-- latex_symbols = "[Latex]",
-- })
-- })
},
sources = cmp.config.sources({
{ name = "copilot", group_index = 2 },
{ name = "codecompanion", group_index = 2 },
{ name = "path", group_index = 2 },
{ name = 'nvim_lsp', group_index = 2 },
{ name = 'nvim_lsp_signature_help', group_index = 2 },
{ name = 'nvim_lsp_document_symbol', group_index = 2 },
{ name = 'vim-dadbod-completion', group_index = 2 },
{ name = 'neorg', group_index = 2 }, -- For luasnip users.
{ name = 'luasnip', group_index = 2 }, -- For luasnip users.
{
name = 'buffer',
option = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
}
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, { { name = 'buffer' } }),
sorting = {
priority_weight = 2,
comparators = {
require("copilot_cmp.comparators").prioritize,
cmp.config.compare.offset,
cmp.config.compare.exact,
require("copilot_cmp.comparators").score,
require("copilot_cmp.comparators").recently_used,
cmp.config.compare.locality,
require("copilot_cmp.comparators").kind,
require("copilot_cmp.comparators").sort_text,
require("copilot_cmp.comparators").length,
require("copilot_cmp.comparators").order,
-- Below is the default comparitor list and order for nvim-cmp
cmp.config.compare.offset,
-- cmp.config.compare.scopes, --this is commented in nvim-cmp too
cmp.config.compare.exact, cmp.config.compare.score,
cmp.config.compare.recently_used, cmp.config.compare.locality,
cmp.config.compare.kind, cmp.config.compare.sort_text,
cmp.config.compare.length, cmp.config.compare.order
}
}
})
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = { { name = 'buffer' } }
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ { name = 'path' } }, {
{ name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } }
})
})
local servers = {
'bashls', 'jedi_language_server', 'jsonls', 'yamlls', 'vimls', 'dotls', 'dockerls',
'html', 'cssls', 'lua_ls', 'eslint', 'ts_ls', 'angularls', 'ansiblels'
}
for _, lsp in ipairs(servers) do
if lsp == 'lua_ls' then
require("lsp-format").setup {}
lspconfig[lsp].setup {
on_attach = require("lsp-format").on_attach,
on_init = function(client)
if client.workspace_folders then
local path = client.workspace_folders[1].name
if path ~= vim.fn.stdpath('config') and (vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc')) then
return
end
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower and will cause issues when working on your own configuration (see https://github.com/neovim/nvim-lspconfig/issues/3189)
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
capabilities = capabilities,
callSnippet = "Replace",
settings = {
Lua = {}
}
}
else
lspconfig[lsp].setup {
-- on_attach = require("lsp-format").on_attach,
capabilities = capabilities
}
end
end
-- cmp.event:on("menu_opened",
-- function() vim.b.copilot_suggestion_hidden = true end)
-- cmp.event:on("menu_closed",
-- function() vim.b.copilot_suggestion_hidden = false end)

View File

@@ -0,0 +1,21 @@
require('lint').linters_by_ft = {
markdown = { 'markdownlint' },
lua = { 'luacheck', 'luac' },
vim = { 'vint' },
sh = { 'shellcheck' },
pyton = { 'pycodestyle', 'black', 'pydocstyle', 'pylint' },
json = { 'jsonlint' },
yaml = { 'yamllint' }
}
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
callback = function()
-- try_lint without arguments runs the linters defined in `linters_by_ft`
-- for the current filetype
require("lint").try_lint()
-- You can call `try_lint` with a linter name or a list of names to always
-- run specific linters, independent of the `linters_by_ft` configuration
-- require("lint").try_lint("cspell")
end,
})