fix(nvim): fix autocompletion
This commit is contained in:
58
nvim/lua/olinpin/plugins/completion.lua
Normal file
58
nvim/lua/olinpin/plugins/completion.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
return {
|
||||
{
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
"L3MON4D3/LuaSnip",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
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(),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||
["<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" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
}, {
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ local PACKAGES = {
|
||||
-- Lint
|
||||
"eslint-lsp",
|
||||
"pylint",
|
||||
"jq",
|
||||
"php-cs-fixer",
|
||||
"intelephense",
|
||||
"prettier",
|
||||
"jq",
|
||||
"php-cs-fixer",
|
||||
"intelephense",
|
||||
"prettier",
|
||||
}
|
||||
|
||||
local function install(pack, version)
|
||||
@@ -117,30 +117,30 @@ end
|
||||
return {
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
init = function()
|
||||
-- Do not crowd home directory with NPM cache folder
|
||||
vim.env.npm_config_cache = vim.env.HOME .. "/.cache/npm"
|
||||
end,
|
||||
opts = {
|
||||
ui = {
|
||||
border = "rounded",
|
||||
height = 0.85,
|
||||
width = 0.8,
|
||||
init = function()
|
||||
-- Do not crowd home directory with NPM cache folder
|
||||
vim.env.npm_config_cache = vim.env.HOME .. "/.cache/npm"
|
||||
end,
|
||||
opts = {
|
||||
ui = {
|
||||
border = "rounded",
|
||||
height = 0.85,
|
||||
width = 0.8,
|
||||
},
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("mason").setup(opts)
|
||||
config = function(_, opts)
|
||||
require("mason").setup(opts)
|
||||
|
||||
-- Filter out disabled packages
|
||||
local packages = {}
|
||||
for _, package in ipairs(PACKAGES) do
|
||||
table.insert(packages, package)
|
||||
end
|
||||
-- Filter out disabled packages
|
||||
local packages = {}
|
||||
for _, package in ipairs(PACKAGES) do
|
||||
table.insert(packages, package)
|
||||
end
|
||||
|
||||
vim.defer_fn(function()
|
||||
syncPackages(packages)
|
||||
end, 3000)
|
||||
end,
|
||||
vim.defer_fn(function()
|
||||
syncPackages(packages)
|
||||
end, 3000)
|
||||
end,
|
||||
|
||||
event = { "VeryLazy" },
|
||||
},
|
||||
@@ -148,6 +148,8 @@ return {
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
dependencies = { "williamboman/mason.nvim" },
|
||||
config = function()
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
local opts = { buffer = bufnr, silent = true }
|
||||
|
||||
@@ -165,12 +167,13 @@ return {
|
||||
end
|
||||
|
||||
-- Configure LSP servers using new vim.lsp.config API
|
||||
vim.lsp.config('lua_ls', {
|
||||
vim.lsp.config("lua_ls", {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = { version = 'LuaJIT' },
|
||||
diagnostics = { globals = { 'vim' } },
|
||||
runtime = { version = "LuaJIT" },
|
||||
diagnostics = { globals = { "vim" } },
|
||||
workspace = {
|
||||
library = vim.api.nvim_get_runtime_file("", true),
|
||||
checkThirdParty = false,
|
||||
@@ -180,19 +183,29 @@ return {
|
||||
},
|
||||
})
|
||||
|
||||
vim.lsp.config('ts_ls', { on_attach = on_attach })
|
||||
vim.lsp.config('pyright', { on_attach = on_attach })
|
||||
vim.lsp.config('html', { on_attach = on_attach })
|
||||
vim.lsp.config('cssls', { on_attach = on_attach })
|
||||
vim.lsp.config('jsonls', { on_attach = on_attach })
|
||||
vim.lsp.config('yamlls', { on_attach = on_attach })
|
||||
vim.lsp.config('intelephense', { on_attach = on_attach })
|
||||
vim.lsp.config('eslint', { on_attach = on_attach })
|
||||
|
||||
vim.lsp.config("ts_ls", { on_attach = on_attach, capabilities = capabilities })
|
||||
vim.lsp.config("pyright", { on_attach = on_attach, capabilities = capabilities })
|
||||
vim.lsp.config("html", { on_attach = on_attach, capabilities = capabilities })
|
||||
vim.lsp.config("cssls", { on_attach = on_attach, capabilities = capabilities })
|
||||
vim.lsp.config("jsonls", { on_attach = on_attach, capabilities = capabilities })
|
||||
vim.lsp.config("yamlls", { on_attach = on_attach, capabilities = capabilities })
|
||||
vim.lsp.config("intelephense", {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
intelephense = {
|
||||
format = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
vim.lsp.config("eslint", { on_attach = on_attach, capabilities = capabilities })
|
||||
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"lua_ls",
|
||||
"ts_ls",
|
||||
"ts_ls",
|
||||
"pyright",
|
||||
"html",
|
||||
"cssls",
|
||||
|
||||
Reference in New Issue
Block a user