PDF Viewer framework bug fixes and integrated functionallity into texlab lsp implementation

This commit is contained in:
isaacST08 2025-01-30 18:14:51 -07:00
commit 95a0125ce0
4 changed files with 42 additions and 38 deletions

View file

@ -226,31 +226,34 @@ in {
package = mkOption {
type = package;
default = pkgs.okular;
default = cfg.pdfViewer.package;
description = ''
The package to use as your PDF viewer.
This viewer needs to support Synctex.
By default it is set to the package of the pdfViewer option.
'';
};
executable = mkOption {
type = str;
default = "okular";
default = cfg.pdfViewer.executable;
description = ''
Defines the executable of the PDF previewer. The previewer needs to support SyncTeX.
By default it is set to the executable of the pdfViewer option.
'';
};
args = mkOption {
type = listOf str;
default = [
"--unique"
"file:%p#src:%l%f"
];
default = cfg.pdfViewer.args;
description = ''
Defines additional arguments that are passed to the configured previewer to perform the forward search.
The placeholders %f, %p, %l will be replaced by the server.
By default it is set to the args of the pdfViewer option.
Placeholders:
- %f: The path of the current TeX file.
- %p: The path of the current PDF file.

View file

@ -1,17 +1,13 @@
{
config,
lib,
pkgs,
...
}: let
defaultPdfViewerName = "okular";
inherit (lib) mkOverride;
inherit (lib.options) mkOption;
inherit (lib.modules) mkIf;
inherit (lib.types) str package listOf;
inherit (builtins) filter isAttrs hasAttr attrNames length elemAt;
inherit (lib.nvim.config) mkBool;
cfg = config.vim.languages.tex;
viewersCfg = cfg.pdfViewer.viewers;
@ -52,7 +48,10 @@
# this viewer is enabled, otherwise leave it as is.
newEnabledPdfViewersCount =
if currentPdfViewer.enable
then enabledPdfViewersCount + 1
then
if enabledPdfViewersCount > 0
then throw "nvf-tex-language does not support having more than 1 pdf viewer enabled!"
else enabledPdfViewersCount + 1
else enabledPdfViewersCount;
# If this pdf viewer is enabled, set is as the enabled viewer.
@ -81,30 +80,22 @@
in (getEnabledPdfViewersInfo {});
enabledPdfViewerCfg = viewersCfg.${enabledPdfViewersInfo.enabledViewerName};
in {
imports = [
./viewers
];
options.vim.languages.tex.pdfViewer = {
enable =
mkBool (
if enabledPdfViewersInfo.count > 1
then throw "nvf-tex-language does not support having more than 1 pdf viewer enabled!"
else (enabledPdfViewersInfo.count == 1)
) ''
Whether to enable configuring the pdf viewer.
By enabling any of the pdfViewers, this option will be automatically set.
If you enable more than one pdf viewer then an error will be thrown.
'';
name = mkOption {
type = str;
default = enabledPdfViewerCfg.name;
description = ''
TODO
The name of the pdf viewer to use.
This value will be automatically set when any of the viewers are enabled.
Setting this option option manually is not recommended but can be used for some very technical nix-ing.
If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`.
'';
};
@ -112,7 +103,12 @@ in {
type = package;
default = enabledPdfViewerCfg.package;
description = ''
The package to set to use a custom viewer.
The package of the pdf viewer to use.
This value will be automatically set when any of the viewers are enabled.
Setting this option option manually is not recommended but can be used for some very technical nix-ing.
If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`.
'';
};
@ -120,7 +116,12 @@ in {
type = str;
default = enabledPdfViewerCfg.executable;
description = ''
TODO
The executable for the pdf viewer to use.
This value will be automatically set when any of the viewers are enabled.
Setting this option option manually is not recommended but can be used for some very technical nix-ing.
If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`.
'';
};
@ -128,14 +129,13 @@ in {
type = listOf str;
default = enabledPdfViewerCfg.args;
description = ''
TODO
The command line arguments to use when calling the pdf viewer command.
This value will be automatically set when any of the viewers are enabled.
Setting this option option manually is not recommended but can be used for some very technical nix-ing.
If you wish to use a custom viewer, please use the `custom` entry provided under `viewers`.
'';
};
};
# If the pdf viewer has been enabled, but none of the individual viewers have been enabled,
# then enable the default viewer.
config = mkIf (cfg.enable && cfg.pdfViewer.enable && enabledPdfViewersInfo.count == 0) {
vim.languages.tex.pdfViewer.viewers.${defaultPdfViewerName}.enable = mkOverride 75 true;
};
}

View file

@ -37,6 +37,6 @@ in (
};
};
args = viewerCfg: ( viewerCfg.args );
argsFunction = viewerCfg: (viewerCfg.args);
}
)

View file

@ -21,7 +21,7 @@
# when the view command is called.
# This is a function that will take in the cfg of its own pdf viewer.
# i.e. it will be called as "args cfg.pdfViewer.viewers.${name}"
args,
argsFunction,
...
}: let
# Inherit the necessary variables available to any module.
@ -59,10 +59,11 @@ in {
# Check that the language, overall pdf viewing, and this pdf viewer have been enabled before making any
# config.
config = mkIf (cfg.enable && viewerCfg.enable) {
# vim.languages.tex.pdfViewer.viewers.${name} = {
vim.languages.tex.pdfViewer = {
inherit name;
inherit (viewerCfg) package executable;
args = args viewerCfg;
args = argsFunction viewerCfg;
};
};
}