neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
10.74k stars 2.08k forks source link

:TexlabForward throws error executing vim.schedule #1333

Closed SirLukeSchande closed 3 years ago

SirLukeSchande commented 3 years ago

Description

When running :TexlabForward I get the follwing error: Error executing vim.schedule lua callback: ...ack/packer/start/nvim-lspconfig/lua/lspconfig/texlab.lua:51: attempt to index local 'result' (a nil value)

I use Skim as previewer. The rest of the language server works flawlessly.

Neovim version

NVIM v0.6.0-dev+b9a35ec7a Build type: Release LuaJIT 2.1.0-beta3

Nvim-lspconfig version

7f902f952944aa708c78138f6536c0dc55aec3a2

Operating system and version

macOS 11.6

Affected language servers

texlab

Steps to reproduce

  1. Open a .tex file and run :TexlabForward

Actual behavior

Error executing vim.schedule lua callback: ...ack/packer/start/nvim-lspconfig/lua/lspconfig/texlab.lua:51: attempt to index local 'result' (a nil value)

Expected behavior

Skim should open at the position the cursor is at.

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]

local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'

local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      'neovim/nvim-lspconfig',
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
    },
  }
end

_G.load_config = function()
  vim.lsp.set_log_level 'trace'
  if vim.fn.has 'nvim-0.5.1' == 1 then
    require('vim.lsp.log').set_format_func(vim.inspect)
  end
  local nvim_lsp = require 'lspconfig'
  local on_attach = function(_, bufnr)
    local function buf_set_keymap(...)
      vim.api.nvim_buf_set_keymap(bufnr, ...)
    end
    local function buf_set_option(...)
      vim.api.nvim_buf_set_option(bufnr, ...)
    end

    buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

    -- Mappings.
    local opts = { noremap = true, silent = true }
    buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
    buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
    buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
    buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
    buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
    buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
    buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
    buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
    buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
    buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
    buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
    buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
    buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
    buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
    buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
  end

  -- Add the server that troubles you here
  local name = 'texlab'
  local cmd = { "texlab" }
  local capabilities = vim.lsp.protocol.make_client_capabilities()
  --capabilities = require'cmp_nvim_lsp'.update_capabilities(capabilities)
  if not name then
    print 'You have not defined a server name, please edit minimal_init.lua'
  end
  if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
    print [[You have not defined a server default cmd for a server
      that requires it please edit minimal_init.lua]]
  end

  nvim_lsp[name].setup {
    cmd = cmd,
    on_attach = on_attach,
    capabilities = capabilities,
    settings = {
        texlab = {
            build = {
                args = {
                    "-interaction=nonstopmode",
                    "-synctex=1",
                    "%f",
                    "-outdir=./out"
                },
                executable = "latexmk",
            },
            forwardSearch = {
                executable = "/Applications/Skim.app/Contents/SharedSupport/displayline",
                args = {"-g", "%l", "%p", "%f"}
            }
        }
    }
  }

  print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
  load_plugins()
  require('packer').sync()
  vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
else
  load_plugins()
  require('packer').sync()
  _G.load_config()
end

Health check

lspconfig: require("lspconfig.health").check()

LSP log

https://gist.github.com/SirLukeSchande/0396ef03dcdba655d3cfc01f77d9d6f9

clason commented 3 years ago

What's your texlab version? The command works for me as advertised (on macOS).

SirLukeSchande commented 3 years ago

I am currently on texlab 3.3.0.

clason commented 3 years ago

Then the usual suspicion is that you have an older version of lspconfig lying around somewhere that is being used instead of the one you are looking at.

clason commented 3 years ago

It shouldn't play a role, but there are always problems with changing the outdir. Try removing that. (In fact, remove all build settings.)

SirLukeSchande commented 3 years ago

The nvim-lsp version I stated above is the one i got from PlugSnapshot. That should be the current version, right?

SirLukeSchande commented 3 years ago

The Error persists even without the outdir

clason commented 3 years ago

Try moving the -g argument:

      forwardSearch = {
        executable = '/Applications/Skim.app/Contents/SharedSupport/displayline',
        args = { '%l', '%p', '%f', '-g' },
      },
SirLukeSchande commented 3 years ago

This doesn't change anything.

clason commented 3 years ago

OK, last guess: Are you sure that the PDF is actually built?

SirLukeSchande commented 3 years ago

Yes, I use the :TexlabBuild all the time.

clason commented 3 years ago

I cannot reproduce your problem at all, so I'll close the issue for now -- feel free to reopen when you have found a minimal reproducible example (including TeX files and a full and explicit set of steps).

The only actual issue here that I can see is when you're trying to forward-search into a PDF that does not exist yet (because it's not built) -- then you get the above error because Texlab does not return an error code when the search fails. There's nothing we can do about it; that is something the server needs to change.

SirLukeSchande commented 3 years ago

So I just found something that could narrow down the source of the error. When i first cd into the directory the .tex file is in and then open the file directly, i.e. not over startify or with the :e command inside neovim, the forward search works perfectly. But if I leave out either of the two I still get the error.

Does that help to narrow down what the error is?