Advertisement
Guest User

minimal lua config to produce the error

a guest
May 6th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.96 KB | None | 0 0
  1. local packer = require("packer")
  2. packer.init({
  3.   enable = true,
  4.   threshold = 0,
  5. })
  6. local use = packer.use
  7. packer.reset()
  8.  
  9. use 'wbthomason/packer.nvim'
  10.  
  11. use({ 'hrsh7th/nvim-cmp', config = function()
  12.   local cmp = require('cmp')
  13.   local sources = require('cmp.config.sources')
  14.   local g = vim.g
  15.   local o = vim.opt
  16.  
  17.   o.completeopt = 'menu,menuone,noselect'
  18.   g.vsnip_snippet_dir = vim.fn.stdpath('config') .. '/vsnip'
  19.   g.vsnip_filetypes = {
  20.     javascriptreact = { 'javascript', 'html' },
  21.     typescriptreact = { 'typescript', 'html' },
  22.     svelte = { 'javascript' },
  23.     vue = { 'html' },
  24.   }
  25.  
  26.   local has_words_before = function()
  27.     local line, col = unpack(vim.api.nvim_win_get_cursor(0))
  28.     return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil
  29.   end
  30.  
  31.   local feedkey = function(key, mode)
  32.     vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
  33.   end
  34.  
  35.   cmp.setup({
  36.     snippet = {
  37.       expand = function(args)
  38.         vim.fn['vsnip#anonymous'](args.body) -- For `vsnip` user.
  39.       end,
  40.     },
  41.     mapping = {
  42.       ['<Down>'] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), { 'i' }),
  43.       ['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), { 'i' }),
  44.       ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
  45.       ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
  46.       ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
  47.       ['<Tab>'] = cmp.mapping(function(fallback)
  48.         if cmp.visible() then
  49.           cmp.select_next_item()
  50.         elseif vim.fn['vsnip#available']() == 1 then
  51.           feedkey('<Plug>(vsnip-expand-or-jump)', '')
  52.         elseif has_words_before() then
  53.           cmp.complete()
  54.         else
  55.           fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
  56.         end
  57.       end, { 'i', 's' }),
  58.  
  59.       ['<S-Tab>'] = cmp.mapping(function()
  60.         if cmp.visible() then
  61.           cmp.select_prev_item()
  62.         elseif vim.fn['vsnip#jumpable'](-1) == 1 then
  63.           feedkey('<Plug>(vsnip-jump-prev)', '')
  64.         end
  65.       end, { 'i', 's' }),
  66.       ['<C-e>'] = cmp.mapping({
  67.         i = cmp.mapping.abort(),
  68.         c = cmp.mapping.close(),
  69.       }),
  70.       ['<CR>'] = cmp.mapping.confirm({
  71.         behavior = cmp.ConfirmBehavior.Replace,
  72.         select = true,
  73.       }),
  74.     },
  75.     sources = sources({
  76.       { name = 'nvim_lsp' },
  77.       { name = 'nvim_lua' },
  78.       { name = 'vsnip' },
  79.       {
  80.         name = 'buffer',
  81.         option = {
  82.           keyword_length = 3,
  83.           get_bufnrs = function()
  84.             return vim.api.nvim_list_bufs()
  85.           end,
  86.         },
  87.       },
  88.     }),
  89.   })
  90.  
  91. end })
  92. use('hrsh7th/cmp-nvim-lua')
  93. use('hrsh7th/cmp-nvim-lsp')
  94. use('hrsh7th/cmp-buffer')
  95. use('hrsh7th/vim-vsnip')
  96. use('hrsh7th/cmp-vsnip')
  97.  
  98. use('williamboman/nvim-lsp-installer')
  99. use('b0o/schemastore.nvim')
  100. use({
  101.   'neovim/nvim-lspconfig', config = function()
  102.     require("nvim-lsp-installer").setup({
  103.       ensure_installed = {"cssls", "html", "jsonls", "sumneko_lua", "volar"},
  104.       ui = {
  105.         icons = {
  106.           server_installed = "✓",
  107.           server_pending = "➜",
  108.           server_uninstalled = "✗",
  109.         },
  110.       },
  111.     })
  112.     local lspconfig = require('lspconfig')
  113.     local util = require('lspconfig.util')
  114.     local capabilities = vim.lsp.protocol.make_client_capabilities()
  115.  
  116.     local cmp_capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
  117.     local map = function(lhs, rhs, bufnr)
  118.       vim.keymap.set('n', lhs, rhs, { silent = true, buffer = bufnr })
  119.     end
  120.     local on_attach_common = function(client, bufnr)
  121.       map('gd', ':LspDefination<CR>', bufnr)
  122.       map('gD', ':LspDeclaration<CR>', bufnr)
  123.       map('K', vim.lsp.buf.hover, bufnr)
  124.       map('gi', vim.lsp.buf.implementation, bufnr)
  125.       map('gt', vim.lsp.buf.type_definition, bufnr)
  126.       map('gw', vim.lsp.buf.document_symbol, bufnr)
  127.       map('gW', vim.lsp.buf.workspace_symbol, bufnr)
  128.       map('gac', ':LspCodeAction<CR>', bufnr)
  129.       map('<F2>', ':LspRename<CR>', bufnr)
  130.       map('gQ', vim.lsp.diagnostic.set_loclist, bufnr)
  131.  
  132.       map('<Space>=', function()
  133.         vim.lsp.buf.format({ async = true })
  134.       end, bufnr)
  135.       print(string.format('LSP attached (%s)', client.name))
  136.     end
  137.     -- sumneko_lua {{{
  138.     local runtime_path = vim.split(package.path, ';')
  139.     local table = require('table')
  140.     table.insert(runtime_path, 'lua/?.lua')
  141.     table.insert(runtime_path, 'lua/?/init.lua')
  142.     lspconfig.sumneko_lua.setup({
  143.       capabilties = cmp_capabilities,
  144.       on_attach = on_attach_common,
  145.       flags = { debounce_text_changes = 150 },
  146.       settings = {
  147.         Lua = {
  148.           runtime = { version = 'LuaJIT', path = runtime_path },
  149.           completion = { enable = true, callSnippet = 'Both' },
  150.           diagnostics = {
  151.             enable = true,
  152.             globals = { 'vim', 'describe' },
  153.             disable = { 'lowercase-global' },
  154.           },
  155.           workspace = {
  156.             library = vim.api.nvim_get_runtime_file('', true),
  157.             maxPreload = 2000,
  158.             preloadFileSize = 1000,
  159.           },
  160.           hint = { enable = true },
  161.           telemetry = { enable = false },
  162.         },
  163.       },
  164.     }) -- }}}
  165.     lspconfig.jsonls.setup({ -- {{{
  166.       capabilties = cmp_capabilities,
  167.       on_attach = on_attach_common,
  168.       flags = { debounce_text_changes = 150 },
  169.       settings = {
  170.         json = {
  171.           schemas = require('schemastore').json.schemas(),
  172.         },
  173.       },
  174.     }) -- }}}
  175.     lspconfig.html.setup({ -- {{{
  176.       capabilties = cmp_capabilities,
  177.       on_attach = on_attach_common,
  178.       flags = { debounce_text_changes = 150 },
  179.     }) -- }}}
  180.     lspconfig.cssls.setup({ -- {{{
  181.       capabilties = cmp_capabilities,
  182.       on_attach = on_attach_common,
  183.       flags = { debounce_text_changes = 150 },
  184.     }) -- }}}
  185.     local function get_typescript_server_path(root_dir)
  186.       local project_root = util.find_node_modules_ancestor(root_dir)
  187.  
  188.       local local_tsserverlib = project_root ~= nil
  189.           and util.path.join(project_root, 'node_modules', 'typescript', 'lib', 'tsserverlibrary.js')
  190.       local global_tsserverlib = os.getenv('NVM_DIR')
  191.           .. '/versions/node/v18.0.0/lib/node_modules/typescript/lib/tsserverlibrary.js'
  192.  
  193.       if local_tsserverlib and util.path.exists(local_tsserverlib) then
  194.         return local_tsserverlib
  195.       else
  196.         return global_tsserverlib
  197.       end
  198.     end
  199.  
  200.     lspconfig.volar.setup({
  201.       capabilties = cmp_capabilities,
  202.       on_attach = on_attach_common,
  203.       flags = { debounce_text_changes = 150 },
  204.       on_new_config = function(new_config, new_root_dir)
  205.         new_config.init_options.typescript.serverPath = get_typescript_server_path(new_root_dir)
  206.       end,
  207.     })
  208.   end
  209. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement