L3MON4D3 / LuaSnip

Snippet Engine for Neovim written in Lua.
Apache License 2.0
3.46k stars 245 forks source link

TexLab Language Server: snippet not working properly #56

Closed saadparwaiz1 closed 3 years ago

saadparwaiz1 commented 3 years ago

I'm not sure if this is an issue with the texlab language server or LuaSnip. Let me know and I'll close this issue and create one on their repo.

Here's the v:completed_item dictionary if that might be helpful

{'word': 'begin{', 'menu': '[LSP]', 'user_data': {'compe': {'completion_item': {'label': 'begin', 'data': 
'commandSnippet', 'preselect': v:false, 'sortText': '00', 'kind': 15, 'detail': 'built-in', 'insertText': 
'begin{$1}^@^I$0^@\end{$1}', 'insertTextFormat': 2}, 'request_position': {'character': 1, 'line': 4}}}, 'info': '', 'kind': '', 'abbr': 'begin~'}   
L3MON4D3 commented 3 years ago

I also used to have issues with the texlab lsp, however it works for me right now. What versions of nvim, compe, texlab are you on? I have NVIM v0.5.0-dev+1459-g384f9870f, most recent compe and texlab 2.2.2.

saadparwaiz1 commented 3 years ago

Currently on stable neovim v0.5.0 (stable) and texlab 3.2.0; I'll try downgrading texlab to see if the issue gets fixed.

edit: tried downgrading texlab still doesn't work. Here's a video of what happens:

https://user-images.githubusercontent.com/73385353/124324163-6f04a300-db7a-11eb-9400-a5c4706c2b4b.mov

L3MON4D3 commented 3 years ago

Could you show the output of :lua Luasnip_current_nodes[vim.api.nvim_get_current_buf()].parent:dump() directly after expanding? I haven't seen anything like that before, but maybe the extmarks get messed up in some spectacular way

L3MON4D3 commented 3 years ago

Another possibility could be some lsp-weirdness (and maybe compe?). My texlab-config:

nvim_lsp.texlab.setup{
    cmd = { "texlab" },
    filetypes = { "tex", "bib" },
    settings = {
      bibtex = {
        formatting = {
          lineLength = 120
        }
      },
      latex = {
        build = {
          args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f" },
          executable = "latexmk",
          onSave = true,
          onChange = true
        },
        forwardSearch = {
          args = {},
          onSave = false
        },
        lint = {
          onChange = false,
          onSave = true
        }
      }
    },
    on_attach = lsp_attach,
    capabilities = capabilities
}
maybe try setting it to the same?
saadparwaiz1 commented 3 years ago

Here's my lspconfig which is pretty similar to yours:

local lspconfig = require('lspconfig')
local util = require('s.util')

lspconfig.texlab.setup {
  on_attach = util.lsp.on_attach,
  capabilities = util.lsp.capabilities,
  texlab = {
    latexFormatter = 'latexindent',
    latexindent = {
      ['local'] = nil,
      modifyLineBreaks = false;
    }
  },
  settings = {
    latex = {
      forwardSearch = {
        args = {"%l", "%p", "%f"},
        executable = "/Applications/Skim.app/Contents/SharedSupport/displayline",
        onSave = false,
      },
      build = {
        args = {
          "-pdf",
          "-interaction=nonstopmode",
          "-synctex=1",
          "-shell-escape",
          "-pvc",
          "%f"
        },
        executable = "latexmk";
        onSave = false;
      },
    }
  }
}

Here's the output for :lua Luasnip_current_nodes[vim.api.nvim_get_current_buf()].parent:dump()

Screenshot 2021-07-02 at 22 21 57
L3MON4D3 commented 3 years ago

Extmarks look fine, maybe the latex-formatter messes something up? Try :lua ls.snippets = {all = {ls.parser.parse_snippet({trig = 'beg'}, "\\begin{$1}\n\t$0\n\\end{$1}")}} and then expand that using beg. That should tell us whether it's the formatter or something else.

saadparwaiz1 commented 3 years ago

The above snippet works fine I also tried disabling the formatter and the issue still persists. Thank you so much for helping out with this issue!

L3MON4D3 commented 3 years ago

Yeah, of course. If you do figure out what went wrong, please update here :D

saadparwaiz1 commented 3 years ago

will do!

saadparwaiz1 commented 3 years ago

The issues doesn't seem to occur with snippets.nvim; Is there any way I can test this without compe? I just want to rule out it's not compe causing the issue. Thanks again for a great plugin and all the help!

L3MON4D3 commented 3 years ago

Apart from just parsing and expanding the snippet manually, no :/

L3MON4D3 commented 3 years ago

Nevermind that, I think it's possible to expand lsp-snippets using omnifunc, I think I saw a PR on the neovim-github, maybe check that out.

saadparwaiz1 commented 3 years ago

Ah thanks will try it out. Thank you so much!

saadparwaiz1 commented 3 years ago

This issue is fixed in latest master now!

L3MON4D3 commented 3 years ago

Hah, nice!