diff --git a/dotfiles/neovim/init.lua b/dotfiles/neovim/init.lua index 7fff03f..7cb9c24 100644 --- a/dotfiles/neovim/init.lua +++ b/dotfiles/neovim/init.lua @@ -75,10 +75,11 @@ if vim.fn.has('win32') == 1 then end - ----------------------------------------------------------- -- LSP config +local lspconfig = require 'lspconfig' + -- Mapping for language server -- See `:help vim.diagnostic.* for documentation on any of the below functions local opts = { noremap = true, silent = true } @@ -91,7 +92,7 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + --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 function @@ -113,14 +114,15 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) end -local lsp_flags = { -} +-- cmp_nvim_lsp supports additional LSP completion capabilities +local capabilities = require("cmp_nvim_lsp").default_capabilities() + -- Lua -require'lspconfig'.lua_ls.setup { +lspconfig.lua_ls.setup { on_attach = on_attach, - flags = lsp_flags, + capabilities = capabilities, settings = { Lua = { runtime = { @@ -139,10 +141,55 @@ require'lspconfig'.lua_ls.setup { }, } +-- Julia +lspconfig.julials.setup { + on_attach = on_attach, + capabilities = capabilities, +} +-- nvim-cmp setup +local cmp = require 'cmp' +local luasnip = require 'luasnip' +luasnip.config.setup {} - - +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), -- Up + [''] = cmp.mapping.scroll_docs(4), -- Down + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = 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' }), + [''] = 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 = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} -----------------------------------------------------------