Skip to content
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

With the zed latex extension, Previewer opens often in the wrong position #1227

Open
mocenigo opened this issue Sep 30, 2024 · 3 comments
Open

Comments

@mocenigo
Copy link

Actual cursor position and position in fwd_search.rs / ForwardSearch differ.

I am using Zed Zed 0.154.3 and the texlab 5.19.0 with zed-latex 0.0.7. My PDF previewer is Skim.

I often observe that upon saving, the Previewer does not open in the position where the cursor was in the tex file at the moment I actually saved. It is usually a previous position, and only after I edit a bit the posizion is adjourned. To reproduce, I also do not move the cursor after hitting cmd-S until the Previewer comes to the foreground.

I thus re-compiled texlab with debugging log force-activated and a separated log file, in fwd_search.rs I added outputs for child, child.cursor and line (such as log::debug!("[FwdSearch] child={:?}", &child);) and I can read the following in the log output:

DEBUG - [FwdSearch] child=Document("file:///Users/mocenigo/Research/PAC-Analysis/paper_short/truncated-reduced.tex")
DEBUG - [FwdSearch] child.cursor=LineCol { line: 0, col: 0 }
DEBUG - [FwdSearch] line="1"

whereas I know I have moevd to line 955 and the position given in the same log a few lines before is

DEBUG - < {"jsonrpc":"2.0","id":3,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///Users/mocenigo/Research/PAC-Analysis/paper_short/truncated-reduced.tex"},"position":{"line":955,"character":16}}}

Even if a movement of the cursor is finally detected, the two places are often out of sync and the Previewer opens in the wrong place.

I do not know whether the bug is in texlab or caused by a bug in Zed.

@mocenigo mocenigo changed the title With the zed latex extensim, Previewer opens often in the wrong position With the zed latex extension, Previewer opens often in the wrong position Sep 30, 2024
@pfoerster
Copy link
Member

I do not know whether the bug is in texlab or caused by a bug in Zed.

The issue lies within LSP itself. With the current protocol, the server has to guess the cursor position before triggering the forward search (there is no request to query the cursor position).

The easiest way to fix this issue would be to:

  1. Disable texlab.build.onSave
  2. Trigger the build manually and set the optional position parameter to the cursor position.

Then, the server knows the position and does not need guess where the cursor is currently at.

@mocenigo
Copy link
Author

mocenigo commented Sep 30, 2024

I do not know whether the bug is in texlab or caused by a bug in Zed.

The issue lies within LSP itself. With the current protocol, the server has to guess the cursor position before triggering the forward search (there is no request to query the cursor position).

The easiest way to fix this issue would be to:

  1. Disable texlab.build.onSave
  2. Trigger the build manually and set the optional position parameter to the cursor position.

Then, the server knows the position and does not need guess where the cursor is currently at.

OK 1, is easiky done. How does one do 2)?
I actually hate that the file is recompiled at each save, but it was my understanding that triggering the build manually was not possible. Of course with multiple cursors one has to pick one, I would say the first.

@pfoerster
Copy link
Member

How does one do 2)?

This needs to be done manually in the editor. You can use these requests:

https://github.com/latex-lsp/texlab/wiki/LSP-Internals#custom-messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants