Skip to content

Commit 91e710d

Browse files
committed
Working on typst "kernel" for exporter
1 parent 237067f commit 91e710d

File tree

9 files changed

+107
-6
lines changed

9 files changed

+107
-6
lines changed

codedown.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ rec {
5757
};
5858

5959
kernels = everythingEnv.config.builtKernels;
60+
exporters = everythingEnv.config.builtExporters;
6061

6162
makeEnvironment = callPackage ./nix/makeEnvironment.nix {
6263
inherit pkgsStable pkgsMaster;

modules/exporters/typst/default.nix

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{ callPackage
2+
, lib
23
, pandoc
34
, symlinkJoin
45
, typst
@@ -10,6 +11,8 @@
1011
with { inherit (settings.interface) attrs extensions; };
1112

1213
let
14+
kernelName = "typst";
15+
1316
common = callPackage ../../kernels/common.nix {};
1417

1518
script = common.writeShellScriptBinWithAttrs {} "typst-export" ''
@@ -18,6 +21,12 @@ let
1821
echo_and_run ${typst}/bin/typst compile "$1" "$2"
1922
'';
2023

24+
languageServers = lib.optionals settings.lsp.tinymist.enable
25+
[(callPackage ./language_server_tinymist { inherit kernelName; })];
26+
27+
packageOptions = {};
28+
packageSearch = common.searcher packageOptions;
29+
2130
icon = ./typst.png;
2231
iconMonochrome = ./typst.svg;
2332

@@ -28,7 +37,9 @@ symlinkJoin {
2837
paths = [
2938
(callPackage ./kernel.nix { inherit attrs extensions; })
3039
script
31-
];
40+
]
41+
++ languageServers
42+
;
3243

3344
passthru = {
3445
meta = {
@@ -57,6 +68,15 @@ symlinkJoin {
5768
typst = typst.version;
5869
};
5970

71+
inherit packageOptions packageSearch;
72+
6073
inherit settingsSchema settings;
74+
75+
modes = {
76+
inherit attrs extensions;
77+
code_mirror_mode = "typst";
78+
};
79+
80+
languageServerNames = map (x: x.languageServerName) languageServers;
6181
};
6282
}

modules/exporters/typst/kernel.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}:
88

99
let
10-
common = callPackage ../common.nix {};
10+
common = callPackage ../../kernels/common.nix {};
1111

1212
in
1313

modules/exporters/typst/language_server_tinymist/default.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}:
88

99
let
10-
common = callPackage ../../common.nix {};
10+
common = callPackage ../../../kernels/common.nix {};
1111

1212
languageServerName = "tinymist";
1313

@@ -26,7 +26,6 @@ common.writeTextDirWithMetaAndPassthru tinymist.meta passthru "lib/codedown/lang
2626
type = "stream";
2727
primary = true;
2828
args = [
29-
"${tinymist}/bin/typst"
30-
"start"
29+
"${tinymist}/bin/tinymist"
3130
];
3231
}])

modules/exporters/typst/module.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ config, options, lib, nixosOptionsToSettingsSchema, ... }:
1+
{ config, options, lib, nixosOptionsToSettingsSchema, boilerplate, ... }:
22

33
with lib;
44

nix/makeEnvironment.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ symlinkJoin {
8282
paths =
8383
attrValues evaluated.config.builtKernels
8484
++ attrValues evaluated.config.builtLanguageServers
85+
++ attrValues evaluated.config.builtExporters
8586
++ lib.optionals (builtins.length exporters > 0) [(writeTextDir "lib/codedown/exporters.yaml" (lib.generators.toYAML {} exporters))]
8687
++ attrValues evaluated.config.packages
8788
++ lib.mapAttrsToList linkBinaries evaluated.config.extraBinDirs

tests/app/Spec/Tests/Typst.hs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{-# LANGUAGE RankNTypes #-}
2+
{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
3+
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}
4+
5+
module Spec.Tests.Typst (tests) where
6+
7+
import Control.Lens hiding (List)
8+
import Data.String.Interpolate
9+
import Data.Text as T
10+
import Language.LSP.Protocol.Lens hiding (diagnostics, hover, text)
11+
import Language.LSP.Protocol.Types
12+
import Language.LSP.Test hiding (message)
13+
import Test.Sandwich as Sandwich
14+
import TestLib.JupyterRunnerContext
15+
import TestLib.LSP
16+
import TestLib.NixEnvironmentContext
17+
import TestLib.NixTypes
18+
import TestLib.TestBuilding
19+
import TestLib.TestSearchers
20+
import TestLib.Types
21+
22+
23+
kernelName :: Text
24+
kernelName = "typst"
25+
26+
tests :: LanguageSpec
27+
tests = describe [i|Typst|] $ introduceNixEnvironment [] config [i|Typst|] $ introduceJupyterRunner $ do
28+
it "has expected fields" $ do
29+
testEval [i|exporters.typst.settingsSchema|]
30+
testEval [i|exporters.typst.modes|]
31+
testEval [i|exporters.typst.settings|]
32+
testEval [i|exporters.typst.args|]
33+
testEval [i|exporters.typst.meta|]
34+
35+
-- Used to view all versions in codedown-languages
36+
testEval [i|exporters.typst.versions|]
37+
38+
39+
describe "LSP" $ do
40+
testDiagnosticsLabelDesired "simple" lsName "test.typ" (Just "typst")
41+
[__i|TODO
42+
|]
43+
((== []) . getDiagnosticRanges')
44+
45+
46+
documentHighlightCode :: Text
47+
documentHighlightCode = [__i|foo = "hello"
48+
println(foo)|]
49+
50+
documentHighlightResults :: [DocumentHighlight]
51+
documentHighlightResults = [
52+
DocumentHighlight (Range (Position 0 0) (Position 0 3)) (Just DocumentHighlightKind_Write)
53+
, DocumentHighlight (Range (Position 1 8) (Position 1 11)) (Just DocumentHighlightKind_Read)
54+
]
55+
56+
lsName :: Text
57+
lsName = "tinymist"
58+
59+
-- kernelSpec :: NixKernelSpec
60+
-- kernelSpec = NixKernelSpec {
61+
-- nixKernelName = "typst"
62+
-- , nixKernelChannel = "codedown"
63+
-- , nixKernelDisplayName = Just [i|Typst|]
64+
-- , nixKernelPackages = []
65+
-- , nixKernelMeta = Nothing
66+
-- , nixKernelIcon = Nothing
67+
-- , nixKernelExtraConfig = Just [
68+
-- "lsp.tinymist.enable = true"
69+
-- ]
70+
-- }
71+
72+
config = [
73+
"exporters.typst.enable = true;"
74+
, "exporters.typst.lsp.tinymist.enable = true;"
75+
]
76+
77+
main :: IO ()
78+
main = jupyterMain tests

tests/src/TestLib/LSP.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ withLspSession' handleFn name filename codeToTest extraFiles session = do
256256
& set (workspace . _Just . configuration) Nothing
257257
& set (workspace . _Just . didChangeWatchedFiles . _Just . dynamicRegistration) (Just False)
258258
& set (workspace . _Just . didChangeConfiguration . _Just . dynamicRegistration) (Just False)
259+
& set (textDocument . _Just . semanticTokens . _Just . dynamicRegistration) (Just False)
259260

260261
handleFn $ runSessionWithConfigCustomProcess modifyCp sessionConfig cp caps homeDir (session homeDir)
261262

tests/tests.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ executable tests
121121
Spec.Tests.SettingsSchemas
122122
Spec.Tests.Shells.Zsh
123123
Spec.Tests.Spellchecker
124+
Spec.Tests.Typst
124125
Paths_tests
125126
hs-source-dirs:
126127
app

0 commit comments

Comments
 (0)