Skip to content

Commit

Permalink
Merge pull request #490 from NotAShelf/typst-preview
Browse files Browse the repository at this point in the history
languages/typst: add live preview for tinymist
  • Loading branch information
NotAShelf authored Dec 10, 2024
2 parents 48bcd5d + 0327918 commit 48829f9
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/release-notes/rl-0.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Release 0.8 {#sec-release-0.8}

[NotAShelf](https://github.com/notashelf):

[typst-preview.nvim]: https://github.com/chomosuke/typst-preview.nvim

- Add [typst-preview.nvim] under
`languages.typst.extensions.typst-preview-nvim`.
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
flake = false;
};

plugin-typst-preview-nvim = {
url = "github:chomosuke/typst-preview.nvim";
flake = false;
};

plugin-nvim-metals = {
url = "github:scalameta/nvim-metals";
flake = false;
Expand Down
62 changes: 59 additions & 3 deletions modules/plugins/languages/typst.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList;
inherit (lib.types) enum either listOf package str;
inherit (lib.types) nullOr enum either attrsOf listOf package str;
inherit (lib.attrsets) attrNames;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.generators) mkLuaInline;
inherit (lib.meta) getExe;
inherit (lib.nvim.lua) expToLua toLuaObject;
inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption;
inherit (lib.nvim.dag) entryAnywhere;

cfg = config.vim.languages.typst;

Expand All @@ -33,6 +36,7 @@
}
'';
};

tinymist = {
package = pkgs.tinymist;
lspConfig = ''
Expand Down Expand Up @@ -120,6 +124,50 @@ in {
default = formats.${cfg.format.type}.package;
};
};

extensions = {
typst-preview-nvim = {
enable =
mkEnableOption ''
[typst-preview.nvim]: https://github.com/chomosuke/typst-preview.nvim
Low latency typst preview for Neovim via [typst-preview.nvim]
''
// {default = true;};

setupOpts = mkPluginSetupOption "typst-preview-nvim" {
open_cmd = mkOption {
type = nullOr str;
default = null;
example = "firefox %s -P typst-preview --class typst-preview";
description = ''
Custom format string to open the output link provided with `%s`
'';
};

dependencies_bin = mkOption {
type = attrsOf str;
default = {
"tinymist" = getExe servers.tinymist.package;
"websocat" = getExe pkgs.websocat;
};

description = ''
Provide the path to binaries for dependencies. Setting this
to a non-null value will skip the download of the binary by
the plugin.
'';
};

extra_args = mkOption {
type = nullOr (listOf str);
default = null;
example = ["--input=ver=draft" "--ignore-system-fonts"];
description = "A list of extra arguments (or `null`) to be passed to previewer";
};
};
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
Expand All @@ -136,5 +184,13 @@ in {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.typst-lsp = servers.${cfg.lsp.server}.lspConfig;
})

# Extensions
(mkIf cfg.extensions.typst-preview-nvim.enable {
vim.startPlugins = ["typst-preview-nvim"];
vim.pluginRC.typst-preview-nvim = entryAnywhere ''
require("typst-preview").setup(${toLuaObject cfg.extensions.typst-preview-nvim.setupOpts})
'';
})
]);
}
4 changes: 2 additions & 2 deletions release.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"release": "v0.7",
"isReleaseBranch": true
"release": "v0.8",
"isReleaseBranch": false
}

0 comments on commit 48829f9

Please sign in to comment.