lhl2617 / VSLilyPond

VSCode Extension for LilyPond
https://marketplace.visualstudio.com/items?itemName=lhl2617.vslilypond
90 stars 7 forks source link

How do you auto reload pdf after compiling? #355

Open xiebruce opened 2 years ago

xiebruce commented 2 years ago

I was able to compile the test.ly by pressing command+s on my Mac and it generate a test.pdf file, I open this pdf file in a split window on vscode. image

As you known, we need to repeat this procedure: write code→save(compile)→preview, but I can't do this, every time I save(compile) the test.ly file, the test.pdf file not auto reloading, I have to close it and reopen to see the change.

How can I solve this problem?

vslilypond

v1.7.3

vscode

Version: 1.62.3 (Universal)
Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247
Date: 2021-11-17T07:59:13.865Z (2 wks ago)
Electron: 13.5.2
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin x64 20.6.0

macOS

Big Sur 11.5.1 (20G80)
Apostolique commented 2 years ago

Did you get the LilyPond PDF Preview extension for vscode?

xiebruce commented 2 years ago

Did you get the LilyPond PDF Preview extension for vscode?

No, I didn't, because I think it's included in VSLilyPond, see here and here

image

image

Apostolique commented 2 years ago

But were you using it?

xiebruce commented 2 years ago

But were you using it?

I think yes image

And I found "LilyPond PDF Preview" has been installed automatically image

when I double click on the pdf file that generated by lilypond in vscode, it's opened by the LilyPond PDF Preview plugin reopen by pdf lilypond previewer

lhl2617 commented 2 years ago

This is strange, on my Mac with 11.6 Big Sur, VSLilyPond 1.60 I can’t reproduce this issue

xiebruce commented 2 years ago

This is strange, on my Mac with 11.6 Big Sur, VSLilyPond 1.60 I can’t reproduce this issue

Can you try the latest version of vsccode(Version: 1.62.3 (Universal)) and VSLilyPond(v1.7.3)? maybe you can reproduce this issue.

Here is my demo, if it is as expected, the pdf will auto reload after I save(compile) the test.ly right? But it didn't! vslilypond-pdf-not-auto-reloading

Apostolique commented 2 years ago

Do the other features work like clicking notes to go from pdf to code and from code to pdf?

xiebruce commented 2 years ago

Do the other features work like clicking notes to go from pdf to code and from code to pdf?

Pdf to code: Yes, it works Code to pdf: No, do I need to hold any key before clicking? Actually I tried hold option, cmd, shift, none of these works.

click-pdf-to-code_optimized

Apostolique commented 2 years ago

I forgot that was something from the command pallet (Ctrl + Shift + P): LilyPond PDF Preview: Go to PDF location from Cursor.

If I open the vscode Output panel and select VSLilyPond: PDF Preview, when I save a LilyPond file I see this log:

[LOG]: [WEBVIEW]: reload
[LOG]: [WEBVIEW]: pagesinit
[LOG]: [WEBVIEW]: allPagesLoaded
[LOG]: Clearing links for f:\Compositions\Sample01.pdf
[LOG]: Links cleared for f:\Compositions\Sample01.pdf
[LOG]: [WEBVIEW]: Sent clear-links
[LOG]: [WEBVIEW]: Finished handling textedits
[LOG]: [WEBVIEW]: Received link-register-ready
[LOG]: [WEBVIEW]: Finished registering links
xiebruce commented 2 years ago

I forgot that was something from the command pallet (Ctrl + Shift + P): LilyPond PDF Preview: Go to PDF location from Cursor.

If I open the vscode Output panel and select VSLilyPond: PDF Preview, when I save a LilyPond file I see this log:

[LOG]: [WEBVIEW]: reload
[LOG]: [WEBVIEW]: pagesinit
[LOG]: [WEBVIEW]: allPagesLoaded
[LOG]: Clearing links for f:\Compositions\Sample01.pdf
[LOG]: Links cleared for f:\Compositions\Sample01.pdf
[LOG]: [WEBVIEW]: Sent clear-links
[LOG]: [WEBVIEW]: Finished handling textedits
[LOG]: [WEBVIEW]: Received link-register-ready
[LOG]: [WEBVIEW]: Finished registering links

There's no LilyPond PDF Preview: Go to PDF location from Cursor option on my vscode go-to-pdf_optimized

I tried to uninstall and reinstall it, but I can't image

Apostolique commented 2 years ago

You got my instructions backward. It's not VSLilyPond: Go to PDF... It's LilyPond PDF Preview: Go to PDF location from Cursor.

Also look in your Output for VSLilyPond: PDF Preview: image

xiebruce commented 2 years ago

You got my instructions backward. It's not VSLilyPond: Go to PDF... It's LilyPond PDF Preview: Go to PDF location from Cursor.

Also look in your Output for VSLilyPond: PDF Preview: image

Sorry, I found it, but I can't see any log(including reload log) in the VSLilyPond: PDF Preview console no-reload-log

And I've tried uninstall all lilypond relative extensions and reinstall vslilypond, still the same, no reloading operations can be found.

xiebruce commented 2 years ago

@Apostolique @lhl2617 Hi, according to the info I provided above, do you guys know what's happening on my vscode or vslilypond ?

Apostolique commented 2 years ago

I'm not sure but since it doesn't work you can find any PDF reader that has auto reload for now.

I use SumatraPDF but that's for Windows. I'm sure you can find a similar one for mac.

xiebruce commented 2 years ago

I'm not sure but since it doesn't work you can find any PDF reader that has auto reload for now.

I use SumatraPDF but that's for Windows. I'm sure you can find a similar one for mac.

Yep, the build-in App "Preview.app" on Mac can do this, but I have to press command+tab(same as alt+tab on Win) to see the change.

lhl2617 commented 2 years ago

I'm unable to repro your bug, can you try opening a dev console in VSCode (https://stackoverflow.com/questions/30765782/what-is-the-use-of-the-developer-tools-in-vs-code) and see if anything is wrong there?

xiebruce commented 2 years ago

@lhl2617

Uncaught (in promise) ReferenceError: Cannot access 'd' before initialization
    at pdf.viewer.js:43

image

Dr-ZeeD commented 2 years ago

I seem to be having the same issue. It had worked for me on Big Sur before. After a completely clean install of VS Code and VSLilypond, the auto-refresh of the PDF preview window (which really uses the LilyPond PDF Preview that comes with VSLilyPond) does not work anymore.

Dr-ZeeD commented 2 years ago

Interestingly, I found a situation that results in the PDF within VSCode to refresh:

  1. Open a lilypond file and its preview within VSCode. Also, open a Preview (the app) window of the PDF.
  2. Modify the lilypond file and compile it. Right now, neither the VSCode preview nor the Preview should reflect the changes.
  3. Click on the Preview window. It should refresh and show the changes. After a brief period, the VSCode preview will also refresh and show the changes.
xiebruce commented 2 years ago

Interestingly, I found a situation that results in the PDF within VSCode to refresh:

  1. Open a lilypond file and its preview within VSCode. Also, open a Preview (the app) window of the PDF.
  2. Modify the lilypond file and compile it. Right now, neither the VSCode preview nor the Preview should reflect the changes.
  3. Click on the Preview window. It should refresh and show the changes. After a brief period, the VSCode preview will also refresh and show the changes.

I made a test in your condition, it turns out that the we should switch to another app then switch back to vscode after saving the code, only by doing this, the PDF inside vscode(opened by LilyPond PDF Preview) can reload. This has nothing to do with the macOS app "Preview.app".

Dr-ZeeD commented 2 years ago

I've just tried it with "not Preview.app". Does not work. So far I have only gotten it to work by clicking on Preview.app with the same file.

Tobertet commented 2 years ago

I have the same problem, and I am using Linux.

Whenever I save, I can see the logs in the Output panel and the PDF is being generated. However, the PDF Preview is not refreshing the output.

snowskeleton commented 1 year ago

I'm having the same problem.

macOS v12.4 Monterey VSCode v1.69.1 (Universal) VSLilyPond v1.7.3 LilyPond PDF Preview v0.2.8 (installed with VSLilyPond)

Switching to Preview.app and back updates the PDF both in Preview.app and in LilyPond PDF Viewer. Switching to an app other than Preview.app doesn't seem to trigger the reload. I also tried opening the PDF (after saving/compiling) with QuickLook (pressing Space bar on macOS in the Finder). QuickLook showed me the updated PDF, but neither Preview.app nor LilyPond PDF Viewer updated (until focusing Preview.app, of course).

snowskeleton commented 1 year ago

Update: I found that LilyPond PDF Viewer will automatically update if it's let sit long enough. In my experience, it's usually less than a minute, but not consistent. I can not consistently replicate this.

clojj commented 1 year ago

Hi @lhl2617 ..thanks for this fantastic plugin !

Locally debugging the PDF Preview Extension, I found that (on Linux) compiling with lilypond will generate a new PDF file (with the same name). Therefore when I created a listener for creation event like this:

        this._watcher.onDidCreate((e) => {
          if (e.toString() === this.resource.toString()) {
            this.reload()
          }
        })

here https://github.com/lhl2617/VSLilyPond-PDF-preview/blob/master/src/extension/pdf-preview.ts#L62 ..automatical reload works fine !

So this yields the somewhat weird question, if all OS's lilypond command treat PDF compilation the same or different (?)

If you want I can create a PR and try to cover all events

zzzeek commented 1 year ago

hi folks, I have this bug. I also don't have ready ability to hack on the plugin itself.

so to work around this, I open my console, select "terminal", and on my Fedora linux machine (things may have to be different on OSX) I run this while loop to refresh the pdf each time it gets recreated, which seems to wake up the pdf viewer:

while [ 1 ]; do sleep 1; find . -name "*.pdf" -mmin -0.02  -exec sh -c "echo 'detected changes on {}'; touch {}; sleep 1 " \;   ; done;

That will run every second, and it will: 1. run a find for .pdf files that were modified less than .02 minutes ago 2. do a touch 3. the sleep another second per "touch", so that it doesn't keep touching the file over and over again.

I organize that into a script refresh.sh and just have it wherever my .ly files are.

(noting I just tried lilypond for the first time about an hour ago)

leiyi0612 commented 7 months ago

Hi @lhl2617 ..thanks for this fantastic plugin !

Locally debugging the PDF Preview Extension, I found that (on Linux) compiling with lilypond will generate a new PDF file (with the same name). Therefore when I created a listener for creation event like this:

        this._watcher.onDidCreate((e) => {
          if (e.toString() === this.resource.toString()) {
            this.reload()
          }
        })

here https://github.com/lhl2617/VSLilyPond-PDF-preview/blob/master/src/extension/pdf-preview.ts#L62 ..automatical reload works fine !

So this yields the somewhat weird question, if all OS's lilypond command treat PDF compilation the same or different (?)

If you want I can create a PR and try to cover all events

Thank you for offering the solution, I did this on my Mac and it worked! image