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

Auto Build breaks if files get changed externally #2053

Closed
tfncp opened this issue Apr 28, 2020 · 9 comments
Closed

Auto Build breaks if files get changed externally #2053

tfncp opened this issue Apr 28, 2020 · 9 comments
Labels
question Issue represents a question

Comments

@tfncp
Copy link

tfncp commented Apr 28, 2020

Is your feature request related to a problem? Please describe.
I'm working on a multi-file LaTex document and my LaTeX sources are managed in a git repository with multiple branches.
When I switch the git branch, some latex files get changed in the filesystem externally (by git). This unfortunately breaks the auto build feature of Latex Workshop, it is not triggered any more. When I close VS Code and reopen it and everything works fine again.

Describe the solution you'd like
I'd like auto build to automatically detect file changes, additions, deletions, etc. that are caused externally.
Alternatively a key-board shortcut for manually reinitializing the auto build file-watcher / latex workshop would work as well.

@tfncp tfncp added the feature request Feature request label Apr 28, 2020
@tamuratak tamuratak removed the feature request Feature request label Apr 28, 2020
@tamuratak

This comment has been minimized.

@tamuratak tamuratak added can't reproduce Issue cannot be reproduced need more info More information needed to identify the issue labels Apr 28, 2020
@tamuratak

This comment has been minimized.

@tfncp
Copy link
Author

tfncp commented May 1, 2020

Sorry, I was busy last week, but now I had time to reproduce the behaviour.
For a new test I created a very small demo git repo containing only a latex file main.tex and a simple latexmkrc file in the master. I also created a branch1 in the git repo where I just modified some text in the main.tex file.

With this setup the test is performed like this:

  1. I start with the git master branch in my working directory.
  2. I open VS code (beginning of log file below) => document get's built and shown in internal pdf viewer.
  3. I switch the git branch using git checkout branch1 on an external console window. During the checkout of the branch VS code is still open and the main.tex file is changed.
  4. The modified file content is shown in VS code and the modification is automatically recognised by latex workshop (see [10:33:10] in the log). The document is rebuilt. Everything is fine :-)
  5. But now at about 10:34:xx I modify the text in main.tex in VS code and I save the file --> nothing happens, no new line in the log is shown.

I can reproduce that behaviour using macOS or windows, I havn't tested in a linux environment.

LaTeX Workshot log output of the described test:

[10:32:29] Initializing LaTeX Workshop.
[10:32:29] Creating file watcher for .pdf files.
[10:32:29] Creating LaTeX Workshop http and websocket server.
[10:32:29] LaTeX Workshop initialized.
[10:32:29] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:32:29] Root file changed from: undefined to /Users/tf/source/latextest/main.tex. Find all dependencies.
[10:32:29] Instantiating a new file watcher for /Users/tf/source/latextest/main.tex
[10:32:29] Creating file watcher for .bib files.
[10:32:29] Parsing /Users/tf/source/latextest/main.tex
[10:32:29] Parse fls file.
[10:32:29] Server created on 127.0.0.1:55673
[10:32:29] Adding /Users/tf/source/latextest/main.tex to file watcher.
[10:32:30] Snippet data loaded.
[10:32:30] LaTeX Workshop version: 8.9.0
[10:32:35] LOG command invoked.
[10:32:35] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:32:35] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:32:40] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:32:40] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:32:40] File watcher: responding to change in /Users/tf/source/latextest/main.tex
[10:32:40] Parsing /Users/tf/source/latextest/main.tex
[10:32:40] Parse fls file.
[10:32:40] /Users/tf/source/latextest/main.tex changed. Auto build project.
[10:32:40] BUILD command invoked.
[10:32:40] Building root file: /Users/tf/source/latextest/main.tex
[10:32:40] Build root file /Users/tf/source/latextest/main.tex
[10:32:40] Recipe step 1: latexmk, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=/Users/tf/source/latextest,/Users/tf/source/latextest/main
[10:32:40] cwd: /Users/tf/source/latextest
[10:32:40] LaTeX build process spawned. PID: 34602.
[10:32:41] Recipe of length 1 finished. PID: 34602.
[10:32:41] Successfully built /Users/tf/source/latextest/main.tex.
[10:32:43] VIEW command invoked with mode: file:///Users/tf/source/latextest/main.tex.
[10:32:43] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:32:43] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:32:43] Serving PDF file at http://localhost:55673/viewer.html?file=pdf..JTJGVXNlcnMlMkZ0ZiUyRnNvdXJjZSUyRmxhdGV4dGVzdCUyRm1haW4ucGRm
[10:32:43] The encoded path is /Users/tf/source/latextest/main.pdf
[10:32:43] Open PDF tab for /Users/tf/source/latextest/main.pdf
[10:32:44] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:32:44] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:32:44] Handle data type: open
[10:32:44] Preview PDF file: /Users/tf/source/latextest/main.pdf
[10:32:44] Handle data type: request_params
[10:32:45] Handle data type: loaded
[10:33:10] File watcher: responding to change in /Users/tf/source/latextest/main.tex
[10:33:10] Parsing /Users/tf/source/latextest/main.tex
[10:33:10] Parse fls file.
[10:33:10] /Users/tf/source/latextest/main.tex changed. Auto build project.
[10:33:10] BUILD command invoked.
[10:33:10] Building root file: /Users/tf/source/latextest/main.tex
[10:33:10] Build root file /Users/tf/source/latextest/main.tex
[10:33:10] Recipe step 1: latexmk, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=/Users/tf/source/latextest,/Users/tf/source/latextest/main
[10:33:10] cwd: /Users/tf/source/latextest
[10:33:10] LaTeX build process spawned. PID: 34649.
[10:33:12] LaTeX log parsed with 1 messages.
[10:33:12] Recipe of length 1 finished. PID: 34649.
[10:33:12] Successfully built /Users/tf/source/latextest/main.tex.
[10:33:12] Refresh PDF viewer for /Users/tf/source/latextest/main.pdf
[10:33:12] Parse fls file.
[10:33:12] Preview PDF file: /Users/tf/source/latextest/main.pdf
[10:33:12] Handle data type: loaded
[10:33:24] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:33:24] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:33:39] LOG command invoked.
[10:33:39] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:33:39] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:49:40] LOG command invoked.
[10:57:44] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:57:44] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:57:52] LOG command invoked.
[10:57:53] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:57:53] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.
[10:57:55] Found root file from active editor: /Users/tf/source/latextest/main.tex
[10:57:55] Root file remains unchanged from: /Users/tf/source/latextest/main.tex.

@tfncp

This comment has been minimized.

@tamuratak tamuratak reopened this May 1, 2020
@tamuratak

This comment has been minimized.

@tamuratak tamuratak removed can't reproduce Issue cannot be reproduced need more info More information needed to identify the issue labels May 1, 2020
@tamuratak
Copy link
Contributor

Set latex-workshop.latex.watch.usePolling: true. See https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexwatchusepolling

@jlelong
Copy link
Collaborator

jlelong commented May 1, 2020

Well, I believe this is related to paulmillr/chokidar#237

The issue is that git checkout actually changes the inode of the file. Right after the git checkout, chokidar catches a rename event, which we do not handle for now and then a change event.

Adding

            this.fileWatcher.on('raw', (type, _filename, details) => {
                if (type === 'rename') {
                    this.fileWatcher?.unwatch(details.watchedPath)
                    this.fileWatcher?.add(details.watchedPath)
                }
            })

seems to fix everything.

@tamuratak
Copy link
Contributor

I am not sure whether the code works fine on all the platforms. The word, raw, is equal to danger here. I think setting latex-workshop.latex.watch.usePolling: true by default is a simple solution.

@jlelong
Copy link
Collaborator

jlelong commented May 1, 2020

I am not sure whether the code works fine on all the platforms

I also fear this. I had the impression that using polling was a kind of last resort but if it works, let us just leave it like this. Maybe we could ask the chokidar guys if they have a suggestion.

Repository owner locked as resolved and limited conversation to collaborators May 27, 2021
@tamuratak tamuratak added the question Issue represents a question label May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Issue represents a question
Projects
None yet
Development

No branches or pull requests

3 participants