Skip to content

Commit

Permalink
plugins/lsp: fix tinymist implementation and update options
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage authored and nix-infra-bot committed Dec 14, 2024
1 parent 95361fd commit 94535b2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 32 deletions.
3 changes: 3 additions & 0 deletions plugins/lsp/language-servers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ let
};
};
};
tinymist = {
settingsOptions = import ./tinymist-settings.nix { inherit lib; };
};
vls = {
extraOptions = {
autoSetFiletype = mkOption {
Expand Down
90 changes: 61 additions & 29 deletions plugins/lsp/language-servers/tinymist-settings.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{ lib, helpers }:
with lib;
{ lib }:

# https://github.com/Myriad-Dreamin/tinymist/blob/main/editors/neovim/Configuration.md
let
inherit (lib.nixvim) defaultNullOpts mkNullOrOption mkNullOrStr;
inherit (lib) types;
in
{
outputPath = helpers.defaultNullOpts.mkStr "$dir/$name" ''
outputPath = defaultNullOpts.mkStr "$dir/$name" ''
The path pattern to store Typst artifacts, you can use `$root` or `$dir` or `$name` to do magic
configuration, e.g. `$dir/$name` (default) and `$root/target/$dir/$name`.
'';

exportPdf =
helpers.defaultNullOpts.mkEnumFirstDefault
defaultNullOpts.mkEnumFirstDefault
[
"auto"
"never"
Expand All @@ -27,12 +31,12 @@ with lib;
- `onDocumentHasTitle`: Export PDFs when a document has a title (and save a file), which is useful to filter out template files.
'';

rootPath = helpers.mkNullOrStr ''
rootPath = mkNullOrStr ''
Configure the root for absolute paths in typst.
'';

semanticTokens =
helpers.defaultNullOpts.mkEnumFirstDefault
defaultNullOpts.mkEnumFirstDefault
[
"enable"
"disable"
Expand All @@ -44,22 +48,22 @@ with lib;
- `disable`: Do not use semantic tokens for syntax highlighting
'';

systemFonts = helpers.defaultNullOpts.mkBool true ''
systemFonts = defaultNullOpts.mkBool true ''
A flag that determines whether to load system fonts for Typst compiler, which is useful for
ensuring reproducible compilation.
If set to null or not set, the extension will use the default behavior of the Typst compiler.
'';

fontPaths = helpers.defaultNullOpts.mkListOf types.str [ ] ''
fontPaths = defaultNullOpts.mkListOf types.str [ ] ''
Font paths, which doesn't allow for dynamic configuration.
Note: you can use vscode variables in the path, e.g. `$\{workspaceFolder}/fonts`.
'';

compileStatus =
helpers.defaultNullOpts.mkEnumFirstDefault
defaultNullOpts.mkEnumFirstDefault
[
"enable"
"disable"
"enable"
]
''
In VSCode, enable compile status meaning that the extension will show the compilation status in
Expand All @@ -69,32 +73,16 @@ with lib;
server level.
'';

typstExtraArgs = helpers.defaultNullOpts.mkListOf types.str [ ] ''
typstExtraArgs = defaultNullOpts.mkListOf types.str [ ] ''
You can pass any arguments as you like, and we will try to follow behaviors of the
**same version** of typst-cli.
Note: the arguments may be overridden by other settings.
For example, `--font-path` will be overridden by `tinymist.fontPaths`.
'';

serverPath = helpers.mkNullOrStr ''
The extension can use a local tinymist executable instead of the one bundled with the extension.
This setting controls the path to the executable.
'';

"trace.server" =
helpers.defaultNullOpts.mkEnumFirstDefault
[
"off"
"messages"
"verbose"
]
''
Traces the communication between VS Code and the language server.
'';

formatterMode =
helpers.defaultNullOpts.mkEnumFirstDefault
defaultNullOpts.mkEnumFirstDefault
[
"disable"
"typstyle"
Expand All @@ -108,10 +96,54 @@ with lib;
- `typstfmt`: Use typstfmt formatter.
'';

formatterPrintWidth = helpers.defaultNullOpts.mkUnsignedInt 120 ''
formatterPrintWidth = defaultNullOpts.mkUnsignedInt 120 ''
Set the print width for the formatter, which is a **soft limit** of characters per line.
See [the definition of *Print Width*](https://prettier.io/docs/en/options.html#print-width).
Note: this has lower priority than the formatter's specific configurations.
'';

completion = {
triggerOnSnippetPlaceholders = mkNullOrOption types.bool ''
Whether to trigger completions on arguments (placeholders) of snippets.
For example, `box` will be completed to `box(|)`, and server will request the editor (lsp
client) to request completion after moving cursor to the placeholder in the snippet.
Note: this has no effect if the editor doesn't support `editor.action.triggerSuggest` or
`tinymist.triggerSuggestAndParameterHints` command.
Hint: Restarting the editor is required to change this setting.
'';

postfix = defaultNullOpts.mkBool true ''
Whether to enable postfix code completion.
For example, `[A].box|` will be completed to `box[A]|`.
Hint: Restarting the editor is required to change this setting.
'';

postfixUfcs = defaultNullOpts.mkBool true ''
Whether to enable UFCS-style completion.
For example, `[A].box|` will be completed to `box[A]|`.
Hint: Restarting the editor is required to change this setting.
'';

postfixUfcsLeft = defaultNullOpts.mkBool true ''
Whether to enable left-variant UFCS-style completion.
For example, `[A].table|` will be completed to `table(|)[A]`.
Hint: Restarting the editor is required to change this setting.
'';

postfixUfcsRight = defaultNullOpts.mkBool true ''
Whether to enable right-variant UFCS-style completion.
For example, `[A].table|` will be completed to `table([A], |)`.
Hint: Restarting the editor is required to change this setting.
'';
};
}
11 changes: 8 additions & 3 deletions tests/test-sources/plugins/lsp/language-servers/tinymist.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
semanticTokens = "enable";
systemFonts = true;
fontPaths = [ ];
compileStatus = "enable";
compileStatus = "disable";
typstExtraArgs = [ ];
serverPath = null;
"trace.server" = "off";
formatterMode = "disable";
formatterPrintWidth = 120;
completion = {
triggerOnSnippetPlaceholders = null;
postfix = true;
postfixUfcs = true;
postfixUfcsLeft = true;
postfixUfcsRight = true;
};
};
};
};
Expand Down

0 comments on commit 94535b2

Please sign in to comment.