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

Not using ${workspaceFolder} in "typst-preview.fontPaths" #107

Closed
tiankaima opened this issue Sep 1, 2023 · 9 comments · Fixed by #108
Closed

Not using ${workspaceFolder} in "typst-preview.fontPaths" #107

tiankaima opened this issue Sep 1, 2023 · 9 comments · Fixed by #108
Labels
enhancement New feature or request

Comments

@tiankaima
Copy link

Describe the bug
In settings.json, ${workspaceFolder} is not parsed in "typst-preview.fontPaths" but directly passed as string to typst, causing it unable to compile

To Reproduce
settings.json:

{
    "typst-preview.fontPaths": [
        "${workspaceFolder}/fonts"
    ]
}

Expected behavior

Error message pops and no window opens.

Package/Software version:

VSCode version(Help -> About):

版本: 1.81.1 (Universal)
提交: 6c3e3dba23e8fadc360aed75ce363ba185c49794
日期: 2023-08-09T22:20:33.924Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 23.0.0

typst-preview extension version: v0.7.4

Logs:

typst-preview server log(Output Panel -> typst-preview):

2023-09-01T06:44:28Z INFO  typst_preview] Arguments: CliArguments {
        font_paths: [
            "${workspaceFolder}/fonts",
        ],
        root: Some(
            "***",
        ),
        data_plane_host: "127.0.0.1:0",
        control_plane_host: "127.0.0.1:0",
        static_file_host: "127.0.0.1:23627",
        dont_open_in_browser: true,
        enable_partial_rendering: true,
        input: "***/***.typ",
    }
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /Users/runner/.cargo/git/checkouts/typst.ts-bd03698c1f5efd74/3ba125d/compiler/src/font/system.rs:44:49
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: typst_ts_compiler::font::system::FontProfileRebuilder::search_file
   4: typst_ts_compiler::font::system::SystemFontSearcher::search_file
   5: typst_ts_compiler::system::<impl typst_ts_compiler::world::CompilerWorld<typst_ts_compiler::system::SystemCompilerFeat>>::new
   6: tokio::runtime::park::CachedParkThread::block_on
   7: tokio::runtime::context::runtime::enter_runtime
   8: tokio::runtime::runtime::Runtime::block_on
   9: typst_preview::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

typst-preview client log(Help -> Toggle Developer Tools -> Console):

typst-preview process exited with code 101

Additional context
Add any other context about the problem here.

@Enter-tainer
Copy link
Owner

Enter-tainer commented Sep 1, 2023

nice catch. should we replace these placeholders with acutal paths in config?

@Enter-tainer
Copy link
Owner

vscode doc said these variables are only supported in launch.json and tasks.json. We can support these vars though. But is it a common practice to do so?

@tiankaima
Copy link
Author

tiankaima commented Sep 1, 2023

vscode doc said these variables are only supported in launch.json and tasks.json. We can support these vars though. But is it a common practice to do so?

I would think so, what's your recommendation on an opensource project to share its font?

Ref: microsoft/vscode#70769 microsoft/vscode#46471

@Enter-tainer
Copy link
Owner

For this specific case, I guess setting it to ./some/font/path should work for now. But I'm not sure. Perhaps installing your font to some "standard directory" would make your life easier.

https://www.npmjs.com/package/vscode-variables is mentioned in issues you posted and it looks nice to me. I will fix this soonish.

@tiankaima
Copy link
Author

tiankaima commented Sep 1, 2023

if you mean:

{
    "typst-preview.fontPaths": [
        "./fonts"
    ]
}

then the answer is still no. It still won't compile

Outpus:

[2023-09-01T07:18:35Z INFO  typst_preview] Arguments: CliArguments {
        font_paths: [
            "./fonts",
        ],
        root: Some(
            "/Users/tiankaima/Source/ustclug/cheatsheet",
        ),
        data_plane_host: "127.0.0.1:0",
        control_plane_host: "127.0.0.1:0",
        static_file_host: "127.0.0.1:23627",
        dont_open_in_browser: true,
        enable_partial_rendering: true,
        input: "/Users/tiankaima/Source/ustclug/cheatsheet/cheatsheet.typ",
    }
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /Users/runner/.cargo/git/checkouts/typst.ts-bd03698c1f5efd74/3ba125d/compiler/src/font/system.rs:44:49
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: typst_ts_compiler::font::system::FontProfileRebuilder::search_file
   4: typst_ts_compiler::font::system::SystemFontSearcher::search_file
   5: typst_ts_compiler::system::<impl typst_ts_compiler::world::CompilerWorld<typst_ts_compiler::system::SystemCompilerFeat>>::new
   6: tokio::runtime::park::CachedParkThread::block_on
   7: tokio::runtime::context::runtime::enter_runtime
   8: tokio::runtime::runtime::Runtime::block_on
   9: typst_preview::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@Enter-tainer
Copy link
Owner

Enter-tainer commented Sep 1, 2023

opensource project to share its font

Alright, I believe I understand your use case. You have a repository for typst containing fonts. I recommend instructing your users to install these fonts in a designated, standardized location. (In some typesetting software(LaTeX), you even don't have the opportunity to customize font path 😇 )

This issue should be resolved, though.

@Enter-tainer Enter-tainer added the enhancement New feature or request label Sep 1, 2023
@Myriad-Dreamin
Copy link
Collaborator

Myriad-Dreamin commented Sep 1, 2023

Another enhancement but not too related here. Noticed that it produces a unreadable error: "No such file or directory", I should link it to a very old issue Myriad-Dreamin/typst.ts#59.

I consider following typst-cli, https://github.com/typst/typst/blob/ca1096de78fe219d58c651defcdf4bfc93f6d7e9/crates/typst-cli/src/fonts.rs#L170, which just ignore missing files. But for font paths provided by users, I prefer to don't silently fail.

We may log the real reason of "No such file or directory" and other warnings in diagnostics console to remind users more friendly, @Enter-tainer, regarding to typst 0.6.0 provided typst::eval::Tracer along with warning primitives.

@Myriad-Dreamin
Copy link
Collaborator

For sharing font paths, there already an environment variable TYPST_FONT_PATHS in system user level since typst-preview 0.7.4. The searching orders follows typst/typst#1847 (comment).

would be also great for sharing font paths to have capability of inherit typst-preview.fontPaths options among different level of setting. I'm not sure whether we should have it, @Enter-tainer. I don't know whether vscode is too smart to join typst-preview.fontPaths in workspace, user and global setting files.

@Enter-tainer
Copy link
Owner

AFAICT in vscode, local settings simply override global ones so the idea of cascading config files may not work. Other parts looks good to me. Producing better error messages is a good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants