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

Forward search after build stopped working on MacOS + Skim on 5.5.0 #880

Closed
bvdmitri opened this issue Apr 17, 2023 · 14 comments · Fixed by #889
Closed

Forward search after build stopped working on MacOS + Skim on 5.5.0 #880

bvdmitri opened this issue Apr 17, 2023 · 14 comments · Fixed by #889
Labels
bug Something isn't working

Comments

@bvdmitri
Copy link

bvdmitri commented Apr 17, 2023

This is a follow-up on #475

After the recent release the forward search after build stopped working properly with Skim application on MacOS. Previosuly everything was working fine, but now it basically jumps on the most top-level \section after each build, which may be quite far away from the actual cursor position.

I should note that manual forward search still works fine. The problem is only with the automatic forward search after build.

Can I somehow control the settings and restore the previous behaviour as it was working as expected?
My setup is Neovim + LSP + Texlab and the pdf reader is Skim.
My config is:

------------------- Latex LS settings -----------------
-- requires brew install --cask mactex & the Skim application
vim.g.texlabwd = string.format("/tmp/texlab-latex/%s", vim.g.wd) 
vim.g.texlab_latexindent_config = string.format("%s/latexindent.yaml", vim.g.pwd)

-- Create texlab working directory if it does not exist
os.execute(string.format("mkdir -p %s", vim.g.texlabwd))

lspconfig.texlab.setup {
  on_attach = on_attach,
  log_level = vim.lsp.protocol.MessageType.Log,
  -- cmd = { "texlab", "-vvvv", "--log-file=/tmp/texlab.log" },
  settings = {
    texlab = {
      auxDirectory = vim.g.texlabwd,
      build = {
        -- executable = "tectonic",
        -- args = {  "-X", "compile", "%f", "-p", "--synctex", "--keep-logs", "--keep-intermediates", "--outdir", vim.b.texlabwd },
        executable = "latexmk",
        args = { "-pdf", "-f", "-interaction=nonstopmode", "-synctex=1", string.format("-outdir=%s", vim.g.texlabwd), "%f" },
        onSave = true,
        forwardSearchAfter = true
      },
      chktex = {
        onOpenAndSave = true
      },
      forwardSearch = {
        executable = "/Applications/Skim.app/Contents/SharedSupport/displayline",
        args = { "-g", "%l", "%p", "%f" }
      },
      latexFormatter = "latexindent",
      latexindent = {
        ['local'] = vim.g.texlab_latexindent_config,
        modifyLineBreaks = true
      }
    }
  },
  capabilities = lsp_capabilities
}
@bvdmitri bvdmitri changed the title Forward search stopped working on MacOS + Skim on 5.5.0 Forward search after build stopped working on MacOS + Skim on 5.5.0 Apr 17, 2023
@bvdmitri
Copy link
Author

Update: Well I'm not sure what is the problem, but it does work in some situations and does not work randomly. I cannot reproduce it reliably now, I will update the issue once I understand why it may jump all of a sudden in a different place.

@bvdmitri
Copy link
Author

bvdmitri commented Apr 17, 2023

Ah, I understand now, basically if I first use the format command + build (in my setup I use latexindent) the position after build is wrong. If I simply save the file without formatting everything works as expected. But I usually do formatting + save and this is currently broken. That also explains why manual forward search command works without problem, because no formatting is involved.

@pfoerster
Copy link
Member

@bvdmitri Thanks for the report! The issue was that texlab was resetting the cursor position to zero after the change notification resulting from the formatting request was processed. This is fixed now by b61313e.

@pfoerster pfoerster added the bug Something isn't working label Apr 29, 2023
@pfoerster
Copy link
Member

Released with v5.5.1

@bvdmitri
Copy link
Author

bvdmitri commented May 8, 2023

Hey! Thanks, but as soon as I can tell the issue is still present on 5.5.1.

@pfoerster pfoerster reopened this May 15, 2023
@carlosala
Copy link

I tried and was working for me today. I needed to reinstall texlab and not sure what was going on but it worked after reinstalling. I'm sure I touched something in my way there xD

@carlosala
Copy link

What's not fully working for me it's inverse search though.

@pfoerster
Copy link
Member

@bvdmitri
Can you give #889 a try? It should now be much more reliable.

@pfoerster
Copy link
Member

@carlosala

What's not fully working for me it's inverse search though.

Inverse search is not done by the server, so you need to check the configuration of your PDF viewer.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 21, 2023
## [5.6.0] - 2023-05-20

### Added

- Add `texlab.cancelBuild` command to cancel the currently active build ([#887](latex-lsp/texlab#887))

### Fixed

- Fix resolving include commands from the `import` package ([#885](latex-lsp/texlab#885))
- Fix regression when tracking active cursor position ([#880](latex-lsp/texlab#880))
@MarkusLohmayer
Copy link

MarkusLohmayer commented Jun 17, 2023

Hey @pfoerster! I am on 5.7.0 and forward search after build does not work (always sends line number 1) while regular forward search works.

@pfoerster pfoerster reopened this Jun 24, 2023
@pfoerster
Copy link
Member

@MarkusLohmayer I have a few questions:

  • Which LSP client are you using?
  • Does it also happen if you trigger the build manually or is it always after saving?
  • Do you have formatting on save enabled?

@MarkusLohmayer
Copy link

MarkusLohmayer commented Jun 24, 2023

Dear @pfoerster, thanks for reopening.

I am sorry, either last time I tried I did not experiment sufficiently or for some unknown reason the behavior changed.

  • I am using NeoVim's native LSP client.
  • If I use :TexlabForward everything works nicely. Only when I set texlab.build.forwardSearchAfter (obviously together with texlab.build.onSave) then I get the line number where I last made an edit, which is not necessarily the cursor position. Anyways, it is much better than always line number 1, as observed last time I activated forwardSearchAfter. Is line number of last edit the intended behavior?
  • I am pretty sure I have no formatting on save enabled. Which option would that be? I don't see anything getting formatted anyways. I also have no auto-command calling lua vim.lsp.buf.format().

Let me know if I can provide more information which would be useful.

@pfoerster
Copy link
Member

@MarkusLohmayer

Is line number of last edit the intended behavior?

Unfortunately, the LSP spec does not provide a way at the moment to retrieve the cursor position so the current implementation uses a best-effort approach. Effectively, the server tries to guess the cursor position by looking at the following requests/notifications:

  • textDocument/didChange
  • textDocument/hover
  • textDocument/completion

So if you just move the cursor around but do not change the document or trigger any hover/completion requests, then texlab will not be notified.

I am pretty sure I have no formatting on save enabled. Which option would that be? I don't see anything getting formatted anyways. I also have no auto-command calling lua vim.lsp.buf.format().

Previously, formatting on save was the problem because the text edit of latexindent resetted the saved cursor position.

@MarkusLohmayer
Copy link

Thank you very much @pfoerster !
I now understand the limitations and appreciate the approach you take.
Consequently you may please close the issue again. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants