Enter-tainer / typst-preview

[DEPRECATED] Use tinymist instead
https://Enter-tainer.github.io/typst-preview/
MIT License
446 stars 21 forks source link

Preview does not display in VS code in nixos/nix #205

Closed ethanabrooks closed 10 months ago

ethanabrooks commented 10 months ago

Describe the bug The pdf preview does not display in VS code (the pane is blank). To Reproduce Steps to reproduce the behavior (Library test):

  1. echo "hello" > test.typ
  2. open test.typ in VS Code
  3. Cmd-shift-P
  4. Preview current file
  5. Observe that the pane that opens up is blank.

Expected behavior I expect to see a preview of the pdf rendered by typst.

Package/Software version:

VSCode version(Help -> About):

Version: 1.85.0
Commit: af28b32d7e553898b2a91af498b1fb666fdebe0c
Date: 2023-12-06T18:17:50.719Z
Electron: 25.9.7
ElectronBuildId: 25551756
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 22.5.0

typst-preview extension version: v0.7.3

Logs:

typst-preview server log(Output Panel -> typst-preview): [2023-12-22T13:23:36Z INFO typst_preview] Arguments: CliArguments { font_paths: [], root: Some( "/Users/ethan/tex/dissertation-typst", ), preview_mode: Document, data_plane_host: "127.0.0.1:0", control_plane_host: "127.0.0.1:0", static_file_host: "127.0.0.1:0", dont_open_in_browser: true, enable_partial_rendering: true, input: "/Users/ethan/tex/dissertation-typst/test.typ", } [2023-12-22T13:23:36Z INFO typst_preview] Data plane server listening on: 127.0.0.1:49711 [2023-12-22T13:23:36Z INFO typst_preview] Control plane server listening on: 127.0.0.1:49712 [2023-12-22T13:23:36Z DEBUG typst_preview::actor::typst] TypstActor: waiting for message [2023-12-22T13:23:36Z DEBUG typst_ts_compiler::service::compile] CompileActor: initialized [2023-12-22T13:23:36Z DEBUG typst_ts_compiler::service::watch] start watching files... [2023-12-22T13:23:36Z DEBUG typst_ts_compiler::service::compile] CompileActor: fs event incoming None [2023-12-22T13:23:36Z INFO typst_preview] Static file server listening on: 127.0.0.1:49713 [2023-12-22T13:23:36Z INFO typst_ts_compiler::service::diag] /test.typ: compiling ... [2023-12-22T13:23:36Z INFO typst_ts_compiler::service::diag] /test.typ: Compilation succeeded in 1.100125ms [2023-12-22T13:23:36Z INFO typst_preview] Peer address: 127.0.0.1:49714 [2023-12-22T13:23:36Z INFO typst_preview] New WebSocket connection: 127.0.0.1:49714 [2023-12-22T13:23:36Z DEBUG typst_preview::actor::editor] EditorActor: received message from mailbox: CompileStatus(Compiling) [2023-12-22T13:23:36Z DEBUG typst_preview::actor::editor] EditorActor: received message from mailbox: CompileStatus(CompileSuccess) [2023-12-22T13:23:36Z DEBUG typst_ts_compiler::service::compile] CompileActor: fs event incoming Some(Update(FileChangeSet { removes: [], inserts: [("/Users/ethan/tex/dissertation-typst/test.typ", FileSnapshot { mtime: SystemTime { tv_sec: 1703251411, tv_nsec: 333073323 }, content: FileContent { len: 5 } })] })) [2023-12-22T13:23:36Z INFO typst_ts_compiler::service::diag] /test.typ: compiling ... [2023-12-22T13:23:36Z INFO typst_ts_compiler::service::diag] /test.typ: Compilation succeeded in 40.458µs [2023-12-22T13:23:36Z DEBUG typst_preview::actor::editor] EditorActor: received message from mailbox: CompileStatus(Compiling) [2023-12-22T13:23:36Z DEBUG typst_preview::actor::editor] EditorActor: received message from mailbox: CompileStatus(CompileSuccess) [2023-12-22T13:23:36Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SyncMemoryFiles [] [2023-12-22T13:23:36Z DEBUG typst_preview::actor::typst] TypstActor: processing SYNC memory files: [] [2023-12-22T13:23:36Z DEBUG typst_ts_compiler::service::compile] CompileActor: memory event incoming [2023-12-22T13:23:36Z INFO typst_ts_compiler::service::diag] /test.typ: compiling ... [2023-12-22T13:23:36Z INFO typst_ts_compiler::service::diag] /test.typ: Compilation succeeded in 13.916µs [2023-12-22T13:23:36Z DEBUG typst_preview::actor::editor] EditorActor: received message from mailbox: CompileStatus(Compiling) [2023-12-22T13:23:36Z DEBUG typst_preview::actor::editor] EditorActor: received message from mailbox: CompileStatus(CompileSuccess) [2023-12-22T13:23:37Z INFO typst_preview] Peer address: 127.0.0.1:49715 [2023-12-22T13:23:37Z INFO typst_preview] New WebSocket connection: 127.0.0.1:49715 [2023-12-22T13:23:37Z DEBUG typst_preview::actor::render] OutlineRenderActor: waiting for message [2023-12-22T13:23:37Z DEBUG typst_preview::actor::render] RenderActor: waiting for message [2023-12-22T13:23:37Z DEBUG typst_preview::actor::webview] WebviewActor: received message from websocket: Ok(Text("current")) [2023-12-22T13:23:37Z DEBUG typst_preview::actor::render] RenderActor: has_full_render: true [2023-12-22T13:23:37Z DEBUG typst_preview::actor::render] OutlineRenderActor: sending outline [2023-12-22T13:23:37Z DEBUG typst_preview::actor::render] OutlineRenderActor: waiting for message [2023-12-22T13:23:37Z DEBUG typst_preview::actor::editor] EditorActor: received message from mailbox: Outline(Outline { items: [] }) [2023-12-22T13:23:37Z DEBUG typst_preview::actor::render] RenderActor: waiting for message [2023-12-22T13:23:37Z DEBUG typst_preview::actor::webview] WebviewActor: received svg from renderer [2023-12-22T13:23:38Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 0, character: 0 } [2023-12-22T13:23:38Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 0, character: 0 } [2023-12-22T13:23:38Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 0, character: 56 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 0, character: 56 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 1, character: 5 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 1, character: 5 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 2, character: 8 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 2, character: 8 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 3, character: 11 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 3, character: 11 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 4, character: 10 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 4, character: 10 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 6, character: 16 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 6, character: 16 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 7, character: 18 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 7, character: 18 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 10, character: 22 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 10, character: 22 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 12, character: 5 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 12, character: 5 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 13, character: 25 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 13, character: 25 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 13, character: 87 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 13, character: 87 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 14, character: 26 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 14, character: 26 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 14, character: 84 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 14, character: 84 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 15, character: 28 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 15, character: 28 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task [2023-12-22T13:23:39Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 15, character: 86 } [2023-12-22T13:23:39Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest { filepath: "extension-output-mgt19937.typst-preview-#1-typst-preview", line: 15, character: 86 } [2023-12-22T13:23:39Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task

typst-preview client log(Help -> Toggle Developer Tools -> Console): https://gist.github.com/ethanabrooks/67f5676b4224fe9baab49b834d7a390b

Additional context typst-preview works fine running locally from the command line. I use nix so it is not on the global path, but I am setting the typst-preview path in VS code settings.

Enter-tainer commented 10 months ago

What is the version of typst-preview?

Enter-tainer commented 10 months ago

panicked at 'calledResult::unwrap()on anErrvalue: CheckBytesError

We've seen simliar issue before https://github.com/Enter-tainer/typst-preview/issues/75 but it has been fixed

ethanabrooks commented 10 months ago
 ❯ typst-preview --version
typst-preview 
Build Timestamp:     1980-01-01T00:00:00.000000000Z
Build Git Describe:  VERGEN_IDEMPOTENT_OUTPUT
Commit SHA:          VERGEN_IDEMPOTENT_OUTPUT
Commit Date:         None
Commit Branch:       None
Cargo Target Triple: x86_64-apple-darwin
Enter-tainer commented 10 months ago

hmmm the version string looks very interesting. how is it installed? also note that by default the vscode extension doesnt use typst-preview in path, but the one bundled inside vsix. you can tweak extension settings and set the path to your typst-preview

ethanabrooks commented 10 months ago

It is installed using nix: https://search.nixos.org/packages?channel=23.11&show=typst-preview&from=0&size=50&sort=relevance&type=packages&query=typst-preview

I think it is possible to update the logic to point to a newer version.

Enter-tainer commented 10 months ago

it seems to be outdated: latest version is v0.10.2

ethanabrooks commented 10 months ago

Updated and now everything is working! Here is the updated package.nix in case there are any other nix users out there:

{
  lib,
  rustPlatform,
  fetchFromGitHub,
  mkYarnPackage,
  fetchYarnDeps,
  pkg-config,
  libgit2,
  openssl,
  zlib,
  stdenv,
  darwin,
}: let
  # Keep the vscode "mgt19937.typst-preview" extension in sync when updating
  # this package at pkgs/applications/editors/vscode/extensions/default.nix
  version = "0.10.2";

  src = fetchFromGitHub {
    owner = "Enter-tainer";
    repo = "typst-preview";
    rev = "v${version}";
    hash = "sha256-VmUcnmTe5Ngcje0SSpOY13HUIfdxBMg8KwvZ1wupCqc=";
  };

  frontendSrc = "${src}/addons/frontend";

  frontend = mkYarnPackage {
    inherit version;
    pname = "typst-preview-frontend";
    src = frontendSrc;
    packageJSON = ./package.json;

    offlineCache = fetchYarnDeps {
      yarnLock = "${frontendSrc}/yarn.lock";
      hash = "sha256-7a7/UOfau84nLIAKj6Tn9rTUmeBJ7rYDFAdr55ZDLgA=";
    };

    buildPhase = ''
      runHook preBuild
      yarn --offline build
      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall
      cp -R deps/typst-preview-frontend/dist $out
      runHook postInstall
    '';

    doDist = false;
  };
in
  rustPlatform.buildRustPackage {
    pname = "typst-preview";
    inherit version src;

    cargoLock = {
      lockFile = ./Cargo.lock;
      outputHashes = {
        "hayagriva-0.4.0" = "sha256-377lXL3+TO8U91OopMYEI0NrWWwzy6+O7B65bLhP+X4=";
        "typst-0.9.0" = "sha256-+rnsUSGi3QZlbC4i8racsM4U6+l8oA9YjjUOtQAIWOk=";
        "typst-ts-compiler-0.4.0-rc9" = "sha256-NVmbAodDRJBJlGGDRjaEcTHGoCeN4hNjIynIDKqvNbM=";
      };
    };

    nativeBuildInputs = [
      pkg-config
    ];

    buildInputs =
      [
        libgit2
        openssl
        zlib
      ]
      ++ lib.optionals stdenv.isDarwin [
        darwin.apple_sdk.frameworks.CoreFoundation
        darwin.apple_sdk.frameworks.CoreServices
        darwin.apple_sdk.frameworks.Security
        darwin.apple_sdk.frameworks.SystemConfiguration
      ];

    prePatch = ''
      mkdir -p addons/vscode/out/frontend
      cp -R ${frontend}/* addons/vscode/out/frontend/
    '';

    meta = {
      description = "Typst preview extension for VSCode";
      homepage = "https://github.com/Enter-tainer/typst-preview/";
      license = lib.licenses.mit;
      maintainers = with lib.maintainers; [berberman];
      mainProgram = "typst-preview";
    };
  }

You will also have to add the other files in this directory: https://github.com/NixOS/nixpkgs/tree/nixos-23.11/pkgs/by-name/ty/typst-preview

fee1-dead commented 10 months ago

version string looks very interesting

just saw this issue, the timestamp is that way because nix wants builds to be reproducible, even for binary files. That means it can't store the build timestamp because that would affect the bit-by-bit reproducibility goal.