diff options
Diffstat (limited to 'lua/common_lsp/texlab.lua')
| -rw-r--r-- | lua/common_lsp/texlab.lua | 82 |
1 files changed, 46 insertions, 36 deletions
diff --git a/lua/common_lsp/texlab.lua b/lua/common_lsp/texlab.lua index 2fd74c81..592e0499 100644 --- a/lua/common_lsp/texlab.lua +++ b/lua/common_lsp/texlab.lua @@ -1,19 +1,19 @@ -local api = vim.api -local validate = vim.validate local util = require 'common_lsp/util' -local lsp = vim.lsp +local api, lsp = vim.api, vim.lsp local M = {} +M.name = "texlab" + -- TODO support more of https://github.com/microsoft/vscode-languageserver-node/blob/master/protocol/src/protocol.progress.proposed.md local default_config default_config = { - name = "texlab"; + name = M.name; cmd = {"texlab"}; filetype = {"tex", "bib"}; - texlab_log_level = lsp.protocol.MessageType.Warning; - texlab_settings = { + log_level = lsp.protocol.MessageType.Warning; + settings = { latex = { build = { args = {"-pdf", "-interaction=nonstopmode", "-synctex=1"}; @@ -28,23 +28,20 @@ local function setup_callbacks(config) config.callbacks = config.callbacks or {} config.callbacks["window/logMessage"] = function(err, method, params, client_id) - if params and params.type <= config.texlab_log_level then + if params and params.type <= config.log_level then lsp.builtin_callbacks[method](err, method, params, client_id) end end - -- TODO use existing callback? config.callbacks["workspace/configuration"] = function(err, method, params, client_id) if err then error(tostring(err)) end if not params.items then return {} end - local result = {} for _, item in ipairs(params.items) do if item.section then - local value = util.lookup_section(config.texlab_settings, item.section) or vim.NIL - print(string.format("config[%q] = %s", item.section, vim.inspect(value))) + local value = util.lookup_section(config.settings, item.section) or vim.NIL table.insert(result, value) end end @@ -60,29 +57,29 @@ end -- {config} is the same as |vim.lsp.add_filetype_config()|, but with some -- additions and changes: -- --- {texlab_log_level} +-- {name} +-- Defaults to "texlab" +-- +-- {cmd} +-- Defaults to {"texlab"} +-- +-- {filetype} +-- Defaults to {"tex", "bib"} +-- +-- {log_level} -- controls the level of logs to show from build processes and other -- window/logMessage events. By default it is set to -- vim.lsp.protocol.MessageType.Warning instead of -- vim.lsp.protocol.MessageType.Log. -- --- {texlab_settings} +-- {settings} -- The settings specified here https://texlab.netlify.com/docs/reference/configuration. -- This is a table, and the keys are case sensitive. --- Example: `texlab_settings = { latex = { build = { executable = "latexmk" } } }` --- --- {filetype} --- Defaults to {"tex", "bib"} --- --- {cmd} --- Defaults to {"texlab"} --- --- {name} --- Defaults to "texlab" +-- Example: `settings = { latex = { build = { onSave = true; } } }` function M.setup(config) config = vim.tbl_extend("keep", config, default_config) - util.tbl_deep_extend(config.texlab_settings, default_config.texlab_settings) + util.tbl_deep_extend(config.settings, default_config.settings) config.capabilities = config.capabilities or vim.lsp.protocol.make_client_capabilities() util.tbl_deep_extend(config.capabilities, { @@ -97,16 +94,30 @@ function M.setup(config) if bufnr == api.nvim_get_current_buf() then M._setup_buffer() else - util.nvim_multiline_command(string.format("autocmd BufEnter <buffer=%d> ++once lua require'common_lsp/texlab'._setup_buffer()", bufnr)) + api.nvim_command(string.format( + "autocmd BufEnter <buffer=%d> ++once lua require'common_lsp/%s'._setup_buffer()", + M.name, + bufnr)) end end) + lsp.add_filetype_config(config) end +-- Declare any commands here. You can use additional modifiers like "-range" +-- which will be added as command options. All of these commands are buffer +-- level by default. +M.commands = { + TexlabBuild = { + function() + M.buf_build(0) + end; + }; +} + function M._setup_buffer() - util.nvim_multiline_command [[ - command! TexlabBuild -buffer lua require'common_lsp/texlab'.texlab_buf_build(0) - ]] + -- Create the module commands + util.create_module_commands(M.name, M.commands) end local texlab_build_status = vim.tbl_add_reverse_lookup { @@ -116,21 +127,20 @@ local texlab_build_status = vim.tbl_add_reverse_lookup { Cancelled = 3; } -function M.texlab_buf_build(bufnr) +function M.buf_build(bufnr) bufnr = util.validate_bufnr(bufnr) local params = { textDocument = { uri = vim.uri_from_bufnr(bufnr) } } - lsp.buf_request(bufnr, 'textDocument/build', params, function(err, method, result, client_id) - if err then error(tostring(err)) end - print("Build "..texlab_build_status[result.status]) - end) + lsp.buf_request(bufnr, 'textDocument/build', params, + function(err, _, result, _) + if err then error(tostring(err)) end + print("Build "..texlab_build_status[result.status]) + end) end -M.buf_build = M.texlab_buf_build - -- bufnr isn't actually required here, but we need a valid buffer in order to -- be able to find the client for buf_request. -- TODO find a client by looking through buffers for a valid client? -function M.texlab_build_cancel_all(bufnr) +function M.build_cancel_all(bufnr) bufnr = util.validate_bufnr(bufnr) local params = { token = "texlab-build-*" } lsp.buf_request(bufnr, 'window/progress/cancel', params, function(err, method, result, client_id) |
