diff options
| author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-14 00:04:56 -0800 |
|---|---|---|
| committer | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-14 00:04:56 -0800 |
| commit | 7fbe851feb26529434b64d8fb3a30f5bb01f180c (patch) | |
| tree | b8d81bff4b77b93eeadffa2afa57b59f67f06a7f /lua/common_lsp/texlab.lua | |
| parent | Add note about gopls (diff) | |
| download | nvim-lspconfig-7fbe851feb26529434b64d8fb3a30f5bb01f180c.tar nvim-lspconfig-7fbe851feb26529434b64d8fb3a30f5bb01f180c.tar.gz nvim-lspconfig-7fbe851feb26529434b64d8fb3a30f5bb01f180c.tar.bz2 nvim-lspconfig-7fbe851feb26529434b64d8fb3a30f5bb01f180c.tar.lz nvim-lspconfig-7fbe851feb26529434b64d8fb3a30f5bb01f180c.tar.xz nvim-lspconfig-7fbe851feb26529434b64d8fb3a30f5bb01f180c.tar.zst nvim-lspconfig-7fbe851feb26529434b64d8fb3a30f5bb01f180c.zip | |
Use new skeleton. Add docs generator.
Diffstat (limited to 'lua/common_lsp/texlab.lua')
| -rw-r--r-- | lua/common_lsp/texlab.lua | 170 |
1 files changed, 46 insertions, 124 deletions
diff --git a/lua/common_lsp/texlab.lua b/lua/common_lsp/texlab.lua index edf05c38..d0339e1f 100644 --- a/lua/common_lsp/texlab.lua +++ b/lua/common_lsp/texlab.lua @@ -1,126 +1,8 @@ +local skeleton = require 'common_lsp/skeleton' local util = require 'common_lsp/util' -local api, lsp = vim.api, vim.lsp +local lsp = 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 = M.name; - cmd = {"texlab"}; - filetype = {"tex", "bib"}; - log_level = lsp.protocol.MessageType.Warning; - settings = { - latex = { - build = { - args = {"-pdf", "-interaction=nonstopmode", "-synctex=1"}; - executable = "latexmk"; - onSave = false; - } - } - } -} - -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.log_level then - lsp.builtin_callbacks[method](err, method, params, client_id) - end - end - - 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.settings, item.section) or vim.NIL - table.insert(result, value) - end - end - return result - end -end - --- A function to set up texlab easier. --- --- Additionally, it sets up the following commands: --- - TexlabBuild: builds the current buffer. --- --- {config} is the same as |vim.lsp.add_filetype_config()|, but with some --- additions and changes: --- --- {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. --- --- {settings} --- The settings specified here https://texlab.netlify.com/docs/reference/configuration. --- This is a table, and the keys are case sensitive. --- Example: `settings = { latex = { build = { onSave = true; } } }` -function M.setup(config) - config = vim.tbl_extend("keep", config, default_config) - - 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, { - workspace = { - configuration = true; - } - }) - - setup_callbacks(config) - - config.on_attach = util.add_hook_after(config.on_attach, function(client, bufnr) - if bufnr == api.nvim_get_current_buf() then - M._setup_buffer() - else - 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; - }; - -- TexlabCancelAllBuilds = { - -- }; -} - -function M._setup_buffer() - -- Create the module commands - util.create_module_commands(M.name, M.commands) -end +local cwd = vim.loop.cwd() local texlab_build_status = vim.tbl_add_reverse_lookup { Success = 0; @@ -129,7 +11,7 @@ local texlab_build_status = vim.tbl_add_reverse_lookup { Cancelled = 3; } -function M.buf_build(bufnr) +local function buf_build(bufnr) bufnr = util.validate_bufnr(bufnr) local params = { textDocument = { uri = vim.uri_from_bufnr(bufnr) } } lsp.buf_request(bufnr, 'textDocument/build', params, @@ -142,7 +24,7 @@ end -- 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.build_cancel_all(bufnr) +local function 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) @@ -151,5 +33,45 @@ function M.build_cancel_all(bufnr) end) end -return M +skeleton.texlab = { + default_config = { + cmd = {"texlab"}; + filetypes = {"tex", "bib"}; + root_dir = function() return cwd end; + log_level = lsp.protocol.MessageType.Warning; + settings = { + latex = { + build = { + args = {"-pdf", "-interaction=nonstopmode", "-synctex=1"}; + executable = "latexmk"; + onSave = false; + }; + }; + }; + }; + commands = { + TexlabBuild = { + function() + buf_build(0) + end; + description = "Build the current buffer"; + }; + -- TexlabCancelAllBuilds = { + -- }; + }; + -- on_new_config = function(new_config) end; + -- on_attach = function(client, bufnr) end; + docs = { + description = [[ +https://texlab.netlify.com/ + +A completion engine built from scratch for (la)tex. +]]; + default_config = { + root_dir = "vim's starting directory"; + }; + }; +} + +skeleton.texlab.buf_build = buf_build -- vim:et ts=2 sw=2 |
