eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.87k stars 2.48k forks source link

Vscode extension LaTeX Workshop's Viewer does not open in Theia IDE in browser #13522

Open dannaf opened 5 months ago

dannaf commented 5 months ago

Bug Description:

The LaTeX Workshop vscode extension's Viewer does not work on Theia IDE in the browser.

(I considered opening this as a Discussion but decided on an Issue/Bug because this involves a vscode extension working in vscode but specifically not working on Theia. I downloaded the extension on vscode locally and the extension's Viewer did open, so it seems that the problem has to do with Theia. Moreover, while the LaTeX Workshop vscode extension does not officially support Eclipse Theia, Theia does aim to support vscode extensions. So I can still expect that this extension should fully work on Theia, including on Theia IDE — correct?)

Steps to Reproduce:

  1. Run Theia IDE in the browser.
  2. Install the LaTeX Workshop vscode extension (and refresh the browser page).
  3. Navigate in the Explorer to folder containing a latex file and its corresponding compiled pdf. Open the latex file in the Editor.
  4. Click on the extension's View LaTeX PDF file button at the top-right of the editor (or select this action via the command palette). (Or, select any of the extension's other actions beginning with "View LaTeX PDF" from the command palette — none of them worked for me.)
  5. Expect to see the extension's Viewer open, and observe that it does not open. (Compare to vscode where it does open.)

Additional Information

This question is related to https://github.com/eclipse-theia/theia/discussions/7988, but that discussion was never answered (and in any case seems outdated, perhaps even dating to before Theia implemented vscode extensions at runtime?), so I would like to restart this discussion. Moreover, that is not the exact issue that I have. For me the LaTeX Workshop's Viewer is not even opening.

System Information

JonasHelming commented 5 months ago

@dannaf Could you quickly retest this with the latest Theia IDE desktop version? https://theia-ide.org/#theiaide

dannaf commented 5 months ago

Same issue, essentially: the extension's Viewer did not open for me upon clicking the View LaTex PDF file button at the top-right of the Editor.

However, when trying all the four command palette actions that the extension provides, the View LaTeX PDF file in external viewer command worked (it opened the PDF file in Preview) and the View LaTeX PDF file in web browser worked (it opened Chrome in what appears to me to be a version of pdf.js specific to the LaTeX Workshop, with the extension's icon, at the url http://localhost:54496/viewer.html?file=pdf..ZmlsZSUzQSUyRiUyRiUyRlVzZXJzJTJGTmFmdHklMkZFbGlqYWgtcGV0aXRpb24lMkZtYWluLnBkZg). (I was not currently able to test the SyncTeX feature of this web viewer because I do not have LaTeX on my local machine — I'm trying to do everything on a remote server and generally access it only via the Theia IDE browser application.)

dannaf commented 5 months ago

Actually the View LaTeX PDF file in web browser command palette action also did something for me via Theia IDE in the browser. (I am not sure what happened when I opened this issue, as I thought I had tried that and it didn't work, but now when I tried again it opened.) I was not able to test it yet due to my particular networking setup, but at least something opened at a url like I mentioned above.

The main bug that this issue represents is still open, however, because the main in-Theia Viewer that the extension implements is not working, neither in Theia IDE via the browser or via the desktop application.

yuhorun commented 5 months ago

look chrome console after click 'view in tab'

tsmaeder commented 5 months ago

@dannaf Opening a pdf file in the latex workshop viewer works for me in 1.48.0. Please comment if you still have an issue.

JonasHelming commented 5 months ago

FYI, preview is available here: https://download.eclipse.org/theia/ide-preview/1.48.0/

yuhorun commented 5 months ago

1.48.2 not works for me, chrome console show: maximum call stack exceeded error. @dannaf We have the same problem. Did you solve it? Screenshot from 2024-04-04 14-01-16

tsmaeder commented 5 months ago

@yuhorun obviously, we're doing something differently, because opening a pdf file works for me. Can you give exact steps what you are doing so we can figure it out?

yuhorun commented 5 months ago

@tsmaeder

Thank you for your attention and contribution, my operation is as follows:

  1. download the theia-1.48.2 source code, decompress it, and run yarn && yarn download:plugins && yarn browser build && yarn browser start
  2. Go to http://localhost:3000/ and install the james-yu.latex-workshop extension
  3. Open the latex source code, compile the output pdf file, and click the preview button on the top right 4.chrome console output: Error during encoding: 'Maximum call stack size exceeded'

I recorded a video reproducing the error.

os: ubuntu22.04 james-yu.latex-workshop: 9.19.1

https://github.com/eclipse-theia/theia/assets/45552382/4113b58c-6c51-4507-9d34-99b13ed08931

tsmaeder commented 5 months ago

@yuhorun can you open a pdf file from the navigator view if you already have it in the workspace? Btw: the video file does not play for me on Windows 11.

yuhorun commented 5 months ago

@tsmaeder yes, i can open a pdf file from the navigator view if i already have it in the workspace.

I re-uploaded the video to recreate the problem, and if you still can't open it, please play it on google Cloud Drive: https://drive.google.com/file/d/1kO1MlyKdkEttvdqZWp94cw29GsQNGKwL/view

issue.webm

madmini commented 3 months ago

@tsmaeder Please reopen this. I'm experiencing the same issue in 1.49.1 and 1.50.0 preview.

Error message is: Uncaught (in promise) Error: Command with id 'workbench.action.focusLeftGroup' is not registered. (each time I try View LaTeX PDF File) and Error during encoding: 'Maximum call stack size exceeded' (only the first time). This matches the output described and shown above.

tsmaeder commented 3 months ago

@yuhorun I'm not familiar with latex. What setup is needed (I'm on Windows) and how do I "compile"?

madmini commented 3 months ago

@tsmaeder The LaTeX Workshop Requirements section lists TeX Live as recommended among possible alternative LaTeX distributions. I have tested with TeX Live Full (comes at ~8gb install size and took >1h to install) on Windows 11 which (for reference) plays nicely with LaTeX Workshop in VSCode (1.90.0). I believe this issue is independent of the choice of latex distribution, though.

The LaTeX Workshop comes with a Build LaTeX project button (play icon, see also @yuhorun's video) for automagic compilation.

humphreylee commented 1 week ago

Bumped. Encountered same issue with Theia IDE ver. 1.52.0

humphreylee commented 1 week ago

Even the "SNIPPET VIEW" is broken. I tried "LaTeX Workshop" from both OpenVSIX - version 10.1.0 and Marketplace - version 10.2.1. image

This is how it looks like in VS Code image

tsmaeder commented 3 days ago

I believe this is a programming error in the LaTex Workshop extensions. Turns out the extension invokes vscode.fs.stat(uri), but what it does (in pseudocode) is this:

const uri= Uri.file('path/to/file.pdf`);
const statFunction = vscode.workspace.fs.stat;
statFunction(uri)

Invoking the function in this way, the this variable inside the stat method is unbound and we get an error when the method tries to access instance variables off this. The extension interprets this as the pdf file not existing (which it prints to the output view). This works in VS Code by accident because the FS instance is constructed in a way that does not require this to be defined. Note that the API documentation clearly refers to stat as a "method", not a function (https://code.visualstudio.com/api/references/vscode-api#FileSystem).

Note that the corresponding VS Code implementation was done in https://github.com/microsoft/vscode/pull/115530, with the purpose of hiding the main-side proxies from the API consumers and the side effect of the FileSystem methods working without a this value. Maybe it's a good idea to do a similar refactor in Theia? @msujew @JonasHelming thoughts?

msujew commented 3 days ago

@tsmaeder I see. I would also think of the vscode API methods as functions that don't require a this context.

A refactoring to support this use case would be appropriate.

tsmaeder commented 3 days ago

I would also think of the vscode API methods as functions that don't require a this context.

Namespaces have functions, but objects have methods. The VS Code doc explicitly distinguishes between the two 🤷

tsmaeder commented 2 days ago

The thing is, we'd have to refactor every interface instance we return and every class defined in the VS Code API. Not sure that's worth it for enabling what is basically a programming error.

humphreylee commented 2 days ago

I wanted to file an issue in LaTeX Workshop repo, but unfortunately Theia is not officially supported.

msujew commented 2 days ago

@tsmaeder I'd argue that the fs object is special, as most devs use the node:fs import like this:

import * as fs from 'node:fs';

fs.stat(...);

If you want to use vscode.workspace.fs as a drop-in replacement for node:fs, it makes sense to replicate the same behavior as the fs import, which exposes functions not methods. We should support that IMO.

tsmaeder commented 2 days ago

@msujew invoking an object method as a pure function is a programming error. The equivalent in your example would be this:

import * as fs from 'node:fs';

const bla= fs.stat;
bla('/usr/bin/ls');

That might or might not work.

tsmaeder commented 1 day ago

I wanted to file an issue in LaTeX Workhop repo, but unfortunately Theia is not officially supported.

They might still want to know about this. "Does not support" does not mean they are actively trying to be incompatible.

tsmaeder commented 1 day ago

A cursory inspection has identified at least 16 classes we'd have to adapt.

tsmaeder commented 22 hours ago

Another problem is that if we rewrite the api objects we would have to make sure we convert them properly when sending stuff over the ext/main interface. The VS Code style is that they create a proxy object that has only getters/setters referring to some "original" object. Sending such an object will typically send an object without any properties.