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, | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| @@ -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,14 +183,24 @@ 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 = { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Oliver
					Oliver