aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorAshkan Kiani <ashkan.k.kiani@gmail.com>2019-11-13 10:00:49 -0800
committerAshkan Kiani <ashkan.k.kiani@gmail.com>2019-11-13 10:01:43 -0800
commit9d815ea8264304ee4ed7151f286ac9f66e6f74b9 (patch)
tree0632ea955546e7fa3e8340ff1435246d2ce91079 /lua
parentAdd configuration options. (diff)
downloadnvim-lspconfig-9d815ea8264304ee4ed7151f286ac9f66e6f74b9.tar
nvim-lspconfig-9d815ea8264304ee4ed7151f286ac9f66e6f74b9.tar.gz
nvim-lspconfig-9d815ea8264304ee4ed7151f286ac9f66e6f74b9.tar.bz2
nvim-lspconfig-9d815ea8264304ee4ed7151f286ac9f66e6f74b9.tar.lz
nvim-lspconfig-9d815ea8264304ee4ed7151f286ac9f66e6f74b9.tar.xz
nvim-lspconfig-9d815ea8264304ee4ed7151f286ac9f66e6f74b9.tar.zst
nvim-lspconfig-9d815ea8264304ee4ed7151f286ac9f66e6f74b9.zip
Use spaces instead of tabs.
Diffstat (limited to 'lua')
-rw-r--r--lua/common_lsp/texlab.lua161
-rw-r--r--lua/common_lsp/util.lua51
2 files changed, 107 insertions, 105 deletions
diff --git a/lua/common_lsp/texlab.lua b/lua/common_lsp/texlab.lua
index a4c5cf78..bf1503d0 100644
--- a/lua/common_lsp/texlab.lua
+++ b/lua/common_lsp/texlab.lua
@@ -6,123 +6,124 @@ local lsp = vim.lsp
local M = {}
local texlab_build_status = vim.tbl_add_reverse_lookup {
- Success = 0;
- Error = 1;
- Failure = 2;
- Cancelled = 3;
+ Success = 0;
+ Error = 1;
+ Failure = 2;
+ Cancelled = 3;
}
function M.texlab_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)
+ 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)
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.texlab_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)
- if err then error(tostring(err)) end
- print("Cancel result", vim.inspect(result))
- end)
+ bufnr = util.validate_bufnr(bufnr)
+ local params = { token = "texlab-build-*" }
+ lsp.buf_request(bufnr, 'window/progress/cancel', params, function(err, method, result, client_id)
+ if err then error(tostring(err)) end
+ print("Cancel result", vim.inspect(result))
+ end)
end
-- TODO support more of https://github.com/microsoft/vscode-languageserver-node/blob/master/protocol/src/protocol.progress.proposed.md
local function lookup_configuration(config, section)
- local settings = config.texlab_settings
- for part in vim.gsplit(section, '.', true) do
- settings = settings[part]
- end
- return settings
+ local settings = config.texlab_settings
+ for part in vim.gsplit(section, '.', true) do
+ settings = settings[part]
+ end
+ return settings
end
local default_config
default_config = {
- name = "texlab";
- cmd = {"texlab"};
- filetype = {"tex"};
- texlab_log_level = lsp.protocol.MessageType.Warning;
- texlab_settings = {
- latex = {
- build = {
- args = {"-pdf", "-interaction=nonstopmode", "-synctex=1"};
- executable = "latexmk";
- onSave = false;
- }
- }
- }
+ name = "texlab";
+ cmd = {"texlab"};
+ filetype = {"tex"};
+ texlab_log_level = lsp.protocol.MessageType.Warning;
+ texlab_settings = {
+ latex = {
+ build = {
+ args = {"-pdf", "-interaction=nonstopmode", "-synctex=1"};
+ executable = "latexmk";
+ onSave = false;
+ }
+ }
+ }
}
local function nvim_command(command)
- validate { command = { command, 's' } }
- for line in vim.gsplit(command, "\n", true) do
- api.nvim_command(line)
- end
+ validate { command = { command, 's' } }
+ for line in vim.gsplit(command, "\n", true) do
+ api.nvim_command(line)
+ end
end
local function setup_callbacks(config)
- config.callbacks = config.callbacks or {}
+ 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
- lsp.builtin_callbacks[method](err, method, params, client_id)
- end
- end
+ config.callbacks["window/logMessage"] = function(err, method, params, client_id)
+ if params and params.type <= config.texlab_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
+ -- 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 = lookup_configuration(config, item.section) or vim.NIL
- print(string.format("config[%q] = %s", item.section, vim.inspect(value)))
- table.insert(result, value)
- end
- end
- return result
- end
+ local result = {}
+ for _, item in ipairs(params.items) do
+ if item.section then
+ local value = lookup_configuration(config, item.section) or vim.NIL
+ print(string.format("config[%q] = %s", item.section, vim.inspect(value)))
+ table.insert(result, value)
+ end
+ end
+ return result
+ end
end
function M.texlab(config)
- config = vim.tbl_extend("keep", config, default_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.texlab_settings, default_config.texlab_settings)
- config.capabilities = config.capabilities or vim.lsp.protocol.make_client_capabilities()
- util.tbl_deep_extend(config.capabilities, {
- workspace = {
- configuration = true;
- }
- })
+ config.capabilities = config.capabilities or vim.lsp.protocol.make_client_capabilities()
+ util.tbl_deep_extend(config.capabilities, {
+ workspace = {
+ configuration = true;
+ }
+ })
- setup_callbacks(config)
+ 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.texlab_setup_commands()
- else
- nvim_command(string.format("autocmd BufEnter <buffer=%d> ++once lua require'common_lsp/texlab'.texlab_setup_commands()", bufnr))
- end
- end)
- lsp.add_filetype_config(config)
+ config.on_attach = util.add_hook_after(config.on_attach, function(client, bufnr)
+ if bufnr == api.nvim_get_current_buf() then
+ M.texlab_setup_commands()
+ else
+ nvim_command(string.format("autocmd BufEnter <buffer=%d> ++once lua require'common_lsp/texlab'.texlab_setup_commands()", bufnr))
+ end
+ end)
+ lsp.add_filetype_config(config)
end
function M.texlab_setup_commands()
- nvim_command [[
- command! TexlabBuild lua require'common_lsp/texlab'.texlab_buf_build(0)
- ]]
+ nvim_command [[
+ command! TexlabBuild lua require'common_lsp/texlab'.texlab_buf_build(0)
+ ]]
end
return M
+-- vim:et ts=2 sw=2
diff --git a/lua/common_lsp/util.lua b/lua/common_lsp/util.lua
index ccf420ce..2de92447 100644
--- a/lua/common_lsp/util.lua
+++ b/lua/common_lsp/util.lua
@@ -4,45 +4,45 @@ local api = vim.api
local M = {}
function M.validate_bufnr(bufnr)
- validate {
- bufnr = { bufnr, 'n' }
- }
- return bufnr == 0 and api.nvim_get_current_buf() or bufnr
+ validate {
+ bufnr = { bufnr, 'n' }
+ }
+ return bufnr == 0 and api.nvim_get_current_buf() or bufnr
end
function M.add_hook_before(fn, new_fn)
- if fn then
- return function(...)
- -- TODO which result?
- new_fn(...)
- return fn(...)
- end
- else
- return new_fn
- end
+ if fn then
+ return function(...)
+ -- TODO which result?
+ new_fn(...)
+ return fn(...)
+ end
+ else
+ return new_fn
+ end
end
function M.add_hook_after(fn, new_fn)
- if fn then
- return function(...)
- -- TODO which result?
- fn(...)
- return new_fn(...)
- end
- else
- return new_fn
- end
+ if fn then
+ return function(...)
+ -- TODO which result?
+ fn(...)
+ return new_fn(...)
+ end
+ else
+ return new_fn
+ end
end
local function split_lines(s)
- return vim.split(s, "\n", true)
+ return vim.split(s, "\n", true)
end
function M.tbl_deep_extend(dst, ...)
- validate { dst = { dst, 't' } }
+ validate { dst = { dst, 't' } }
for i = 1, select("#", ...) do
local t = select(i, ...)
- validate { arg = { t, 't' } }
+ validate { arg = { t, 't' } }
for k, v in pairs(t) do
if type(v) == 'table' and not vim.tbl_islist(v) then
dst[k] = M.tbl_deep_extend(dst[k] or {}, v)
@@ -55,3 +55,4 @@ function M.tbl_deep_extend(dst, ...)
end
return M
+-- vim:et ts=2 sw=2