-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Luasnip + texlab not working properly #503
Comments
Thanks for the detailed report. At the moment, I have two suspects:
To find out the cause I have added an additional log statement, which should clear things up. |
Completion works, yeah. In fact I only noticed this behavior after I was editing a ~200 line file and after a while it had 15k lines. I tested Log |
Thanks for the log file. That's a bit odd. If the completion is working correctly, then a text synchronization issue (in which the text shown in the editor and the text calculated inside Looking at the log, the text edit calculated by This line (211) however seems a bit odd:
It re-inserts a lot of text between the first line and the second line after saving. I am not sure if this is intended but it is an incoming notification so it must be something the client did send. Before that,
The response looks good and the following
Immediately after, the client strips the trailing line break:
which yields the same document as before when applied. |
Neovim just merged a big rewrite of the incremental sync logic. Can you try again with latest |
I just tested it and the bug is still there. I coded a dockerfile to reproduce the problem, not sure if this might help. Everything is built from source. DockerDockerfile FROM ubuntu:20.04 AS builder
ARG BUILD_APT_DEPS="ninja-build gettext cargo libtool libtool-bin autoconf automake cmake g++ pkg-config unzip git binutils"
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update && apt upgrade -y && \
apt install -y ${BUILD_APT_DEPS} && \
git clone https://github.com/neovim/neovim.git /tmp/neovim && \
cd /tmp/neovim && \
make CMAKE_BUILD_TYPE=Release && \
make CMAKE_INSTALL_PREFIX=/usr/local install && \
strip /usr/local/bin/nvim && \
git clone https://github.com/latex-lsp/texlab.git /tmp/texlab && \
cd /tmp/texlab && \
git checkout bug/#503-debugging && \
cargo build --release
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update && apt upgrade -y && apt install -y git cpanminus make gcc
RUN git clone https://github.com/cmhughes/latexindent.pl.git /latexindent
RUN cpanm YAML::Tiny && cpanm File::HomeDir && cpanm Unicode::GCString
RUN ln -s /latexindent/latexindent.pl /bin/latexindent
COPY --from=builder /usr/local /usr/local/
COPY --from=builder /tmp/texlab/target/release/texlab /usr/bin/texlab
COPY init.lua /root/.config/nvim/
RUN nvim --headless +'autocmd User PackerComplete sleep 100m | qall' +PackerSync
COPY test.tex /
CMD ["/usr/local/bin/nvim"] init.lua vim.lsp.set_log_level "debug"
local fn = vim.fn
local function ensure_installed()
local install_path = fn.stdpath "data" .. "/site/pack/packer/opt/packer.nvim"
local install = false
if fn.empty(fn.glob(install_path)) > 0 then
print "Installing Packer..."
fn.delete(vim.fn.stdpath "config" .. "/lua/packer_compiled.lua")
fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }
install = true
end
vim.cmd "packadd packer.nvim"
return install
end
ensure_installed()
require("packer").startup(function()
use { "wbthomason/packer.nvim", opt = true }
use { "hrsh7th/cmp-path" }
use { "rafamadriz/friendly-snippets" }
use {
"L3MON4D3/LuaSnip",
config = function()
require("luasnip/loaders/from_vscode").lazy_load()
end,
}
use {
"hrsh7th/nvim-cmp",
config = function()
local cmp = require "cmp"
local mapping = {
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
}
cmp.setup {
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = mapping,
completion = { completeopt = "menu,menuone,noinsert" },
sources = {
{ name = "luasnip" },
{ name = "path" },
},
}
end,
}
use {
"neovim/nvim-lspconfig",
config = function()
require("lspconfig").texlab.setup {
cmd = { "texlab", "-vvvv", "--log-file", "/tmp/texlab.log" },
log_level = vim.lsp.protocol.MessageType.Log,
message_level = vim.lsp.protocol.MessageType.Log,
settings = {
texlab = {
diagnosticsDelay = 50,
build = {
executable = "latexmk",
args = {
"-pdf",
"-interaction=nonstopmode",
"-pvc",
"-synctex=1",
"-shell-escape",
"%f",
},
},
forwardSearch = {
args = { "--synctex-forward", "%l:1:%f", "%p" },
executable = "zathura",
},
chktex = { onOpenAndSave = false, onEdit = false },
formatterLineLength = 120,
},
},
}
end,
}
use { "saadparwaiz1/cmp_luasnip" }
end)
vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.formatting_sync(nil, 1000)]] test.tex \documentclass{article}
\begin{document}
\end{document} Instructionsdocker build -t bug .
docker run --rm -it bug
:e test.tex |
Yes, there still are issues with Neovim's incremental sync logic (which I never hit with texlab+luasnip but you might have) that are actively being worked on atm. Can you try adding the flag |
I did try to set |
I am almost certain |
@mjlbach How exactly should I format it instead? Removing that autocmd and manually using I also opened the issue here because it doesn't happen with efm, and it seems to be related to |
We need to minimally reproduce what is happening. Luasnip should have nothing to do with our formatting request. If you use a minimal config (such as the one from lspconfig), and directly call |
Obviously it does not happen. |
Ok, so we've confirmed there is nothing wrong with the built-in client or texlab no? https://github.com/mjlbach/user_questions/tree/main/texlab_formatting Doesn't show an issue with me with luasnip installed when just editing/formatting normally, so I'm assuming you have to trigger a snippet insertion, which likely primes a buf_set_text event to fire which overwrites part of your buffer after the snippet is confirmed. |
Yes, it only happens after triggering a snippet insertion. It does not happen using If there was a way to avoid the error after sending |
Let's completely remove EFM from the equation, that's not important. Texlab does not sync the buffer, unless it's directly writing to disk (which I think it does not). We (neovim) synchronize the buffer. If you use formatting_sync we should block on formatting. I'll look at this later but I can't easily reproduce your issue. |
Not even with the docker files above? |
That's correct. Initially,
Instead,
|
@pfoerster I'm sorry, to be clear I don't think this is a texlab issue and believe it's more an issue of a snippet plugin and the returned formatting request fighting for control of the buffer clientside :) Also to clarify I'm a neovim maintainer/the person (currently) responsible for our built-in language server client. |
@mjlbach No worries. If there is anything I can do to help troubleshoot the issue from the side of |
Since it seems to be a |
@tiagovla I wouldn't normally allow this since it's a plugin issue, but you can file it on lspconfig (sans EFM, I know what that issue is) and I'll continue to look into it |
Problem
After using a lua snippet and saving, if I leave the next insert mode a copy of the document will be pasted.
I noticed it only happens with texlab, it works fine with pyright. Also the issue is related to the formatter, it won't happen if it's disabled. I tried to use efm to format instead, but texlab + efm don't work together #485.
System
Minimal config
Log
lsp.log
The text was updated successfully, but these errors were encountered: