Browse Source

User configurable latex lsp#2 (#861)

* Adjust tex.lua and default-config for lsp magic

With this commit table elements are added to default-config.lua, which
are referenced in tex.lua. The settings are set to default.

This enables the user to configure settings accordingly inside of
lv-config.lua.
- build arguments
- forwardsearch executable e.g. zathura
- forwardsearch arguments for chosen executable are implemented
  automatically
- handlers for virtual_text, signs, underline and update_in_insert are
  set to the default

* Added Texlab-Build and Forward as which-keys

With this commit the two commands `:TexlabBuild` and `:TexlabForward`
are added as which-keys under the category +LaTeX.

- b is for TexlabBuild
- p is for TexlanForward (Preview)

* Change which-key for +Latex

The which-key for +Latex has to be changed because `L` is already used
by +Lush.

With this commit the which-key for +Latex is changed to `t`.

* Add documentation of options

All configurable texlab option is documented in lv-config.example.lua.

Also a link to the documentation of the options from latex-lsp/texlab
is added.
PZ31k0nauT 4 years ago
parent
commit
b6c8d4b2a2
3 changed files with 106 additions and 3 deletions
  1. 61 2
      ftplugin/tex.lua
  2. 29 0
      lua/default-config.lua
  3. 16 1
      utils/installer/lv-config.example.lua

+ 61 - 2
ftplugin/tex.lua

@@ -2,17 +2,74 @@ if require("lv-utils").check_lsp_client_active "texlab" then
   return
 end
 
+local preview_settings = {}
+
+local sumatrapdf_args = { "-reuse-instance", "%p", "-forward-search", "%f", "%l" }
+local evince_args = { "-f", "%l", "%p", "\"code -g %f:%l\"" }
+local okular_args = { "--unique", "file:%p#src:%l%f" }
+local zathura_args = { "--synctex-forward", "%l:1:%f", "%p" }
+local qpdfview_args = { "--unique", "%p#src:%f:%l:1" }
+local skim_args = { "%l", "%p", "%f" }
+
+if O.lang.latex.forward_search.executable == "C:/Users/{User}/AppData/Local/SumatraPDF/SumatraPDF.exe" then
+  preview_settings = sumatrapdf_args
+elseif O.lang.latex.forward_search.executable == "evince-synctex" then
+  preview_settings = evince_args
+elseif O.lang.latex.forward_search.executable == "okular" then
+  preview_settings = okular_args
+elseif O.lang.latex.forward_search.executable == "zathura" then
+  preview_settings = zathura_args
+elseif O.lang.latex.forward_search.executable == "qpdfview" then
+  preview_settings = qpdfview_args
+elseif O.lang.latex.forward_search.executable == "/Applications/Skim.app/Contents/SharedSupport/displayline" then
+  preview_settings = skim_args
+end
+
 require("lspconfig").texlab.setup {
   cmd = { DATA_PATH .. "/lspinstall/latex/texlab" },
   on_attach = require("lsp").common_on_attach,
+  handlers = {
+    ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
+      virtual_text = O.lang.latex.diagnostics.virtual_text,
+      signs = O.lang.latex.diagnostics.signs,
+      underline = O.lang.latex.diagnostics.underline,
+       update_in_insert = true,
+    }),
+  },
+  filetypes = { "tex", "bib" },
+  settings = {
+    texlab = {
+      auxDirectory = O.lang.latex.aux_directory,
+      bibtexFormatter = O.lang.latex.bibtex_formatter,
+      build = {
+        args = O.lang.latex.build.args,
+        executable = O.lang.latex.build.executable,
+        forwardSearchAfter = O.lang.latex.build.forward_search_after,
+        onSave = O.lang.latex.build.on_save,
+      },
+      chktex = {
+        onEdit = O.lang.latex.chktex.on_edit,
+        onOpenAndSave = O.lang.latex.chktex.on_open_and_save,
+      },
+      diagnosticsDelay = O.lang.latex.diagnostics_delay,
+      formatterLineLength = O.lang.latex.formatter_line_length,
+      forwardSearch = {
+        args = preview_settings,
+        executable = O.lang.latex.forward_search.executable,
+      },
+      latexFormatter = O.lang.latex.latex_formatter,
+      latexindent = {
+         modifyLineBreaks = O.lang.latex.latexindent.modify_line_breaks,
+      },
+    },
+  },
 }
-
 vim.g.vimtex_compiler_method = "latexmk"
 vim.g.vimtex_view_method = "zathura"
 vim.g.vimtex_fold_enabled = 0
 vim.g.vimtex_quickfix_ignore_filters = O.lang.latex.ignore_errors
 
-O.plugin.which_key.mappings["L"] = {
+O.plugin.which_key.mappings["t"] = {
   name = "+Latex",
   c = { "<cmd>VimtexCompile<cr>", "Toggle Compilation Mode" },
   f = { "<cmd>call vimtex#fzf#run()<cr>", "Fzf Find" },
@@ -20,6 +77,8 @@ O.plugin.which_key.mappings["L"] = {
   s = { "<cmd>VimtexStop<cr>", "Stop Project Compilation" },
   t = { "<cmd>VimtexTocToggle<cr>", "Toggle Table Of Content" },
   v = { "<cmd>VimtexView<cr>", "View PDF" },
+  b = { "<cmd>TexlabBuild<cr>", "Build with Texlab" },
+  p = { "<cmd>TexlabForward<cr>", "Preview with Texlab" },
 }
 
 -- Compile on initialization, cleanup on quit

+ 29 - 0
lua/default-config.lua

@@ -150,6 +150,35 @@ O = {
     },
     kotlin = {},
     latex = {
+      filetypes = { "tex", "bib"},
+      aux_directory = nil,
+      bibtex_formatter = "texlab",
+      diagnostics_delay = 300,
+      formatter_line_length = 80,
+      latex_formatter = "latexindent",
+      build = {
+        executable = "latexmk",
+        args = {'-pdf', '-interaction=nonstopmode', '-synctex=1', '%f'},
+        on_save = false,
+        forward_search_after = false,
+      },
+      chktex = {
+        on_open_and_save = false,
+        on_edit = false,
+      },
+      forward_search = {
+        executable = nil,
+        args = {}
+      },
+      latexindent = {
+        ["local"] = nil,
+        modify_line_breaks = false
+      },
+      diagnostics = {
+        virtual_text = {spacing = 0, prefix = ""},
+        signs = true,
+        underline = true,
+      },
       auto_save = false,
       ignore_errors = {},
     },

+ 16 - 1
utils/installer/lv-config.example.lua

@@ -52,7 +52,22 @@ O.lang.tsserver.linter = nil
 --   args = {"--emit=stdout", "--edition=2018"},
 -- }
 
--- latex
+--LaTeX
+-- Options: https://github.com/latex-lsp/texlab/blob/master/docs/options.md
+O.lang.latex.active = true
+O.lang.latex.aux_directory = "."
+O.lang.latex.bibtex_formatter = "texlab"
+O.lang.latex.build.args = { '-pdf', '-interaction=nonstopmode', '-synctex=1', '%f' }
+O.lang.latex.build.executable = "latexmk"
+O.lang.latex.build.forward_search_after = false
+O.lang.latex.build.on_save = false
+O.lang.latex.chktex.on_edit = false
+O.lang.latex.chktex.on_open_and_save = false
+O.lang.latex.diagnostics_delay = 300
+O.lang.latex.formatter_line_length = 80
+O.lang.latex.forward_search.executable = "zathura"
+O.lang.latex.latex_formatter = "latexindent"
+O.lang.latex.latexindent.modify_line_breaks = false
 -- O.lang.latex.auto_save = false
 -- O.lang.latex.ignore_errors = { }