Use different Helix configurations for different Typst endpoints
This commit is contained in:
parent
e24f431fe4
commit
e30dc02e04
4 changed files with 68 additions and 31 deletions
20
README.md
20
README.md
|
|
@ -35,6 +35,24 @@ individual languages and editors as needed.
|
|||
programming and natural languages.
|
||||
- 🏛 **REUSE**: Simplifies software licensing and checks for errors.
|
||||
|
||||
## Usage
|
||||
## 💡 How it works
|
||||
|
||||
`editors/helix` exposes a set of configuration options for `languages.toml`,
|
||||
defining the language servers used and the formatters. Although Helix does not
|
||||
accept `languages.toml` as an argument, it can read from `.helix/languages.toml`
|
||||
in the project directory, so a wrapper automatically creates this file when
|
||||
Helix launches.
|
||||
|
||||
Because some configuration options do not allow per-file configurations, a
|
||||
wrapper script can generate Helix variations with different configurations. For
|
||||
example, `typst-default` launches a Helix instance where `tinymist` points to
|
||||
`scratch/typst.typ`, whereas `typst-alt` launches a Helix instance pointing to
|
||||
`scratch/typst-alt.typ`.
|
||||
|
||||
`flake-parts` allows different components to build onto the configuration
|
||||
defined in `editors/helix`, so each language in `languages` adds its own
|
||||
`language` and `language-server` definitions, but only when enabled.
|
||||
|
||||
## 🔧 Usage
|
||||
|
||||
Use this [template](https://git.sudoer777.dev/me/nix-flake-template).
|
||||
|
|
|
|||
|
|
@ -39,17 +39,10 @@
|
|||
en-us = {
|
||||
enable = true;
|
||||
dictionary = [
|
||||
"Asahi"
|
||||
"Catppuccin"
|
||||
"GmbH"
|
||||
"Haug"
|
||||
"Laurenz"
|
||||
"LLMs"
|
||||
"Mädje"
|
||||
"Nushell"
|
||||
"Reece"
|
||||
"SOPS"
|
||||
"Stylix"
|
||||
];
|
||||
vale."{**/*.md,**/scratch/vale.txt}".packages = {
|
||||
RedHat.enable = true;
|
||||
|
|
|
|||
|
|
@ -216,24 +216,32 @@
|
|||
{
|
||||
languages.en-us.dictionary = [
|
||||
"aarch64"
|
||||
"Asahi"
|
||||
"Catppuccin"
|
||||
"Devshell"
|
||||
"Dolstra"
|
||||
"Eelco"
|
||||
"FileCopyrightText"
|
||||
"Flake"
|
||||
"formatters"
|
||||
"https"
|
||||
"GmbH"
|
||||
"Jujutsu"
|
||||
"LanguageTool"
|
||||
"LLMs"
|
||||
"LTeX"
|
||||
"Nix"
|
||||
"NixOS"
|
||||
"Nixpkgs"
|
||||
"Nushell"
|
||||
"qutebrowser"
|
||||
"REUSE"
|
||||
"SnippetBegin"
|
||||
"SnippetCopyrightText"
|
||||
"SnippetEnd"
|
||||
"SOPS"
|
||||
"SPDX"
|
||||
"Stylix"
|
||||
"TODO"
|
||||
];
|
||||
editors.helix.languages.language-server = {
|
||||
|
|
|
|||
|
|
@ -35,11 +35,30 @@
|
|||
};
|
||||
config = lib.mkIf config.languages.typst.enable (
|
||||
let
|
||||
tinymistURL = "127.0.0.1:23635";
|
||||
fonts = pkgs.buildEnv {
|
||||
name = "fonts";
|
||||
paths = config.languages.typst.fonts;
|
||||
};
|
||||
tinymist = {
|
||||
url = "127.0.0.1:23635";
|
||||
config = {
|
||||
command = "${pkgs.tinymist}/bin/tinymist";
|
||||
config = {
|
||||
preview.background = {
|
||||
enabled = true;
|
||||
args = [
|
||||
"--data-plane-host=${tinymist.url}"
|
||||
"--invert-colors=never"
|
||||
];
|
||||
};
|
||||
typstExtraArgs = [
|
||||
"--ignore-system-fonts"
|
||||
"--font-path"
|
||||
"${fonts}/share/fonts"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
languages.en-us.dictionary = [
|
||||
|
|
@ -69,32 +88,32 @@
|
|||
];
|
||||
language-server.tinymist = {
|
||||
command = "${pkgs.tinymist}/bin/tinymist";
|
||||
config = {
|
||||
preview.background = {
|
||||
enabled = true;
|
||||
args = [
|
||||
"--data-plane-host=${tinymistURL}"
|
||||
"--invert-colors=never"
|
||||
];
|
||||
};
|
||||
typstExtraArgs = [
|
||||
"--ignore-system-fonts"
|
||||
"--font-path"
|
||||
"${fonts}/share/fonts"
|
||||
# "${config.languages.typst.entrypoint}"
|
||||
];
|
||||
};
|
||||
config = tinymist.config;
|
||||
};
|
||||
};
|
||||
treefmt.programs.typstyle.enable = true;
|
||||
devshells.default.commands = lib.mkIf config.editors.helix.enable (
|
||||
lib.mapAttrsToList (
|
||||
name: value:
|
||||
# (
|
||||
let
|
||||
# helix = {
|
||||
# config =
|
||||
# };
|
||||
tinymist' = tinymist // {
|
||||
config = tinymist.config // {
|
||||
config = tinymist.config.config // {
|
||||
typstExtraArgs = tinymist.config.config.typstExtraArgs ++ [ value ];
|
||||
};
|
||||
};
|
||||
};
|
||||
helix' = {
|
||||
base = config.editors.helix;
|
||||
config = helix'.base // {
|
||||
languages = helix'.base.languages // {
|
||||
language-server = helix'.base.languages.language-server // {
|
||||
tinymist = tinymist'.config;
|
||||
};
|
||||
};
|
||||
};
|
||||
package = mkHelixPackage helix'.config;
|
||||
};
|
||||
in
|
||||
{
|
||||
help = " launch Typst editing environment for ${name}";
|
||||
|
|
@ -105,14 +124,13 @@
|
|||
let git_root = (git rev-parse --show-toplevel | str trim)
|
||||
let file_path = $"($git_root)/${value}"
|
||||
let bg_process = (job spawn {
|
||||
${nixGLPkgs.nixgl.nixGLMesa}/bin/nixGLMesa ${pkgs.qutebrowser}/bin/qutebrowser ${tinymistURL}
|
||||
${nixGLPkgs.nixgl.nixGLMesa}/bin/nixGLMesa ${pkgs.qutebrowser}/bin/qutebrowser ${tinymist.url}
|
||||
})
|
||||
${pkgs.helix}/bin/hx $file_path
|
||||
${helix'.package}/bin/hx $file_path
|
||||
job kill $bg_process
|
||||
'';
|
||||
}
|
||||
) config.languages.typst.entrypoints
|
||||
# )
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue