Set up typst

This commit is contained in:
Natsu Kagami 2023-07-03 22:42:03 +02:00
parent 44021e3df2
commit 4f6a9ce7ca
Signed by: nki
GPG key ID: 55A032EB38B49ADB
6 changed files with 59 additions and 6 deletions

View file

@ -398,11 +398,11 @@
}, },
"nixpkgs-unstable": { "nixpkgs-unstable": {
"locked": { "locked": {
"lastModified": 1687946342, "lastModified": 1688221086,
"narHash": "sha256-vRxti8pOuXS0rJmqjbD8ueEEFXWSK22ISHoCWkhgzzg=", "narHash": "sha256-cdW6qUL71cNWhHCpMPOJjlw0wzSRP0pVlRn2vqX/VVg=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "1c851e8c92b76a00ce84167984a7ec7ba2b1f29c", "rev": "cd99c2b3c9f160cd004318e0697f90bbd5960825",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -71,6 +71,8 @@ in
## Latex ## Latex
tectonic tectonic
texlab texlab
## Typst
typst
## Python ## Python
python3 python3

View file

@ -56,6 +56,21 @@ in
programs.my-kakoune.enable-fish-session = true; programs.my-kakoune.enable-fish-session = true;
programs.kak-lsp.enable = true; programs.kak-lsp.enable = true;
programs.kak-lsp.package = kak-lsp; programs.kak-lsp.package = kak-lsp;
programs.kak-lsp.semanticTokens.additionalFaces = [
# Typst
{ face = "header"; token = "heading"; }
{ face = "ts_markup_link_url"; token = "link"; }
{ face = "ts_markup_link_uri"; token = "ref"; }
{ face = "ts_markup_link_label"; token = "label"; }
{ face = "ts_property"; token = "pol"; }
{ face = "ts_markup_list_checked"; token = "marker"; }
{ face = "ts_constant_builtin_boolean"; token = "bool"; }
{ face = "ts_keyword_control"; token = "delim"; }
{ face = "ts_number"; token = "text"; modifiers = [ "math" ]; }
{ face = "ts_markup_bold"; token = "text"; modifiers = [ "strong" ]; }
{ face = "ts_markup_italic"; token = "text"; modifiers = [ "emph" ]; }
];
programs.kak-lsp.languages.typescript = { programs.kak-lsp.languages.typescript = {
args = [ "--stdio" ]; args = [ "--stdio" ];
command = "typescript-language-server"; command = "typescript-language-server";
@ -95,6 +110,13 @@ in
}); });
}; };
}; };
programs.kak-lsp.languages.typst = {
command = "${pkgs.typst-lsp}/bin/typst-lsp";
filetypes = [ "typst" ];
roots = [ ".git" "main.typ" ];
settings_section = "typst-lsp";
settings.typst-lsp = { };
};
programs.my-kakoune.tree-sitter.extraAliases = { programs.my-kakoune.tree-sitter.extraAliases = {
# Scala stuff # Scala stuff

View file

@ -89,7 +89,7 @@ hook global InsertCompletionHide .* %{
try %{ try %{
eval %sh{test -z "$WE_STARTED_KAK" && kak-lsp --kakoune -s $kak_session} eval %sh{test -z "$WE_STARTED_KAK" && kak-lsp --kakoune -s $kak_session}
} }
hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|fsharp|ocaml|haskell|nix|scala) %{ hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|fsharp|ocaml|haskell|nix|scala|typst) %{
lsp-enable-window lsp-enable-window
map window lsp N -docstring "Display the next message request" ": lsp-show-message-request-next<ret>" map window lsp N -docstring "Display the next message request" ": lsp-show-message-request-next<ret>"
map window normal <c-l> ": enter-user-mode lsp<ret>" map window normal <c-l> ": enter-user-mode lsp<ret>"
@ -109,7 +109,7 @@ hook global WinSetOption filetype=(rust) %{
lsp-inlay-hints-enable window lsp-inlay-hints-enable window
} }
hook global WinSetOption filetype=(rust|go|fsharp) %{ hook global WinSetOption filetype=(rust|go|fsharp|typst) %{
hook window -group semantic-tokens BufReload .* lsp-semantic-tokens hook window -group semantic-tokens BufReload .* lsp-semantic-tokens
hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens
hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens
@ -150,6 +150,21 @@ hook global WinSetOption filetype=(scala) %{
set window indentwidth 2 set window indentwidth 2
} }
hook global WinSetOption filetype=(typst) %{
set-option window comment_line "//"
set-option window comment_block_begin "/*"
set-option window comment_block_end "*/"
# borrow markdown's hooks
require-module markdown
hook window ModeChange pop:insert:.* -group markdown-trim-indent markdown-trim-indent
hook window InsertChar \n -group markdown-insert markdown-insert-on-new-line
hook window InsertChar \n -group markdown-indent markdown-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window markdown-.+ }
}
define-command -params 0 -docstring "Set up build" scala-build-connect %{ define-command -params 0 -docstring "Set up build" scala-build-connect %{
lsp-execute-command 'build-connect' '"[]"' lsp-execute-command 'build-connect' '"[]"'
} }
@ -185,6 +200,11 @@ hook global BufCreate .*[.]sc %{
set-option buffer filetype scala set-option buffer filetype scala
} }
hook global BufCreate .*[.]typ %{
set-option buffer filetype typst
add-highlighter buffer/ wrap
}
hook global BufOpenFile .* %{ hook global BufOpenFile .* %{
modeline-parse modeline-parse
} }

View file

@ -247,6 +247,11 @@ in
default = lspConfig.semantic_tokens.faces; default = lspConfig.semantic_tokens.faces;
description = "The semantic tokens faces mapping given to kak"; description = "The semantic tokens faces mapping given to kak";
}; };
semanticTokens.additionalFaces = mkOption {
type = types.listOf types.anything;
default = [ ];
description = "The semantic tokens faces mapping given to kak";
};
serverTimeout = mkOption { serverTimeout = mkOption {
type = types.int; type = types.int;
@ -274,7 +279,7 @@ in
yj -jt -i \ yj -jt -i \
< ${ < ${
pkgs.writeText "config.json" (builtins.toJSON { pkgs.writeText "config.json" (builtins.toJSON {
semantic_tokens.faces = cfg.semanticTokens.faces; semantic_tokens.faces = cfg.semanticTokens.faces ++ cfg.semanticTokens.additionalFaces;
server.timeout = cfg.serverTimeout; server.timeout = cfg.serverTimeout;
snippet_support = cfg.enableSnippets; snippet_support = cfg.enableSnippets;
verbosity = 255; verbosity = 255;

View file

@ -7,6 +7,10 @@ let
overlay-needs-unstable = final: prev: { overlay-needs-unstable = final: prev: {
# override some packages that needs unstable that cannot be changed in the setup. # override some packages that needs unstable that cannot be changed in the setup.
nix-direnv = prev.unstable.nix-direnv; nix-direnv = prev.unstable.nix-direnv;
# Typst updates really quickly.
typst = final.unstable.typst;
typst-lsp = final.unstable.typst-lsp;
}; };
overlay-imported = final: prev: { overlay-imported = final: prev: {
rnix-lsp = inputs.rnix-lsp.defaultPackage."${final.system}"; rnix-lsp = inputs.rnix-lsp.defaultPackage."${final.system}";