Fix autocomplete not working
This commit is contained in:
parent
bb0a48dafb
commit
7cefecceed
@ -36,28 +36,27 @@ cmp.setup({
|
||||
}),
|
||||
|
||||
sources = cmp.config.sources({
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp', priority = 1000 },
|
||||
{ name = 'luasnip', priority = 750 },
|
||||
}, {
|
||||
{ name = 'buffer', priority = 500 },
|
||||
{ name = 'path', priority = 250 },
|
||||
}),
|
||||
sorting = {
|
||||
comparators = {
|
||||
cmp.config.compare.offset,
|
||||
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,
|
||||
},
|
||||
},
|
||||
{ name = 'nvim_lsp', priority = 1000 },
|
||||
{ name = 'luasnip', priority = 750 },
|
||||
}, {
|
||||
{ name = 'buffer', priority = 500 },
|
||||
{ name = 'path', priority = 250 },
|
||||
}),
|
||||
|
||||
sorting = {
|
||||
comparators = {
|
||||
cmp.config.compare.offset,
|
||||
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,
|
||||
},
|
||||
},
|
||||
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
vim_item.menu = ({
|
||||
|
||||
@ -14,5 +14,7 @@ require("config.plugin.rainbow-delimiters")
|
||||
require("config.plugin.indent-blankline")
|
||||
require("config.plugin.scrollbar")
|
||||
require("config.plugin.lspsaga")
|
||||
require("config.plugin.lsp")
|
||||
require("config.plugin.luasnip")
|
||||
require("config.plugin.gruvbox")
|
||||
require("config.plugin.cmp")
|
||||
|
||||
108
lua/config/plugin/lsp.lua
Normal file
108
lua/config/plugin/lsp.lua
Normal file
@ -0,0 +1,108 @@
|
||||
-- LSP Configuration
|
||||
local lspconfig = require('lspconfig')
|
||||
|
||||
-- Setup Mason (already done via lazy.nvim, but ensure it's initialized)
|
||||
require('mason').setup()
|
||||
|
||||
-- Setup LSP capabilities for nvim-cmp
|
||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||
|
||||
-- Function to attach LSP to buffers
|
||||
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 for LSP actions
|
||||
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
|
||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
|
||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
|
||||
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
|
||||
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
|
||||
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
|
||||
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
|
||||
vim.keymap.set('n', '<space>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, bufopts)
|
||||
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
|
||||
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
|
||||
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
|
||||
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
|
||||
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
|
||||
end
|
||||
|
||||
-- Try to use mason-lspconfig if available, otherwise setup servers manually
|
||||
local mason_lspconfig_ok, mason_lspconfig = pcall(require, 'mason-lspconfig')
|
||||
if mason_lspconfig_ok then
|
||||
-- Setup mason-lspconfig
|
||||
mason_lspconfig.setup({
|
||||
ensure_installed = {}, -- Add LSP servers here as needed
|
||||
automatic_installation = false,
|
||||
})
|
||||
|
||||
-- Setup handlers if the API is available
|
||||
if mason_lspconfig.setup_handlers then
|
||||
mason_lspconfig.setup_handlers({
|
||||
-- Default handler for all servers
|
||||
function(server_name)
|
||||
lspconfig[server_name].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- Setup LSP servers manually (uncomment as needed)
|
||||
-- Install servers via :Mason command in Neovim first
|
||||
|
||||
-- Lua LSP
|
||||
-- lspconfig.lua_ls.setup({
|
||||
-- capabilities = capabilities,
|
||||
-- on_attach = on_attach,
|
||||
-- settings = {
|
||||
-- Lua = {
|
||||
-- runtime = { version = 'LuaJIT' },
|
||||
-- diagnostics = { globals = { 'vim' } },
|
||||
-- workspace = { library = vim.api.nvim_get_runtime_file("", true) },
|
||||
-- telemetry = { enable = false },
|
||||
-- },
|
||||
-- },
|
||||
-- })
|
||||
|
||||
-- Python LSP (uncomment when pyright is installed)
|
||||
-- lspconfig.pyright.setup({
|
||||
-- capabilities = capabilities,
|
||||
-- on_attach = on_attach,
|
||||
-- })
|
||||
|
||||
-- Rust LSP (uncomment when rust_analyzer is installed)
|
||||
-- lspconfig.rust_analyzer.setup({
|
||||
-- capabilities = capabilities,
|
||||
-- on_attach = on_attach,
|
||||
-- })
|
||||
|
||||
-- Diagnostic configuration
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
signs = true,
|
||||
update_in_insert = false,
|
||||
underline = true,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
focusable = false,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
source = "always",
|
||||
header = "",
|
||||
prefix = "",
|
||||
},
|
||||
})
|
||||
|
||||
-- Show diagnostic signs
|
||||
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 = "" })
|
||||
end
|
||||
2
lua/config/plugin/luasnip.lua
Normal file
2
lua/config/plugin/luasnip.lua
Normal file
@ -0,0 +1,2 @@
|
||||
-- LuaSnip configuration
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
Loading…
Reference in New Issue
Block a user