Files
neovim/runtime/lua/vim/lsp/default_callbacks.lua
Ashkan Kiani a4b7004f48 Move everything to buf & default_callbacks
- Rename builtin_callbacks to default_callbacks and slightly change its
semantics:
  - No longer contains the default implementations. Instead, any
  default_callbacks will be used in preference for our .buf methods.
  - Add this to the docs.
2019-11-20 16:03:32 -08:00

58 lines
2.0 KiB
Lua

local log = require 'vim.lsp.log'
local protocol = require 'vim.lsp.protocol'
local util = require 'vim.lsp.util'
local api = vim.api
local M = {}
M['textDocument/publishDiagnostics'] = function(_, _, result)
if not result then return end
local uri = result.uri
local bufnr = vim.uri_to_bufnr(uri)
if not bufnr then
api.nvim_err_writeln(string.format("LSP.publishDiagnostics: Couldn't find buffer for %s", uri))
return
end
util.buf_clear_diagnostics(bufnr)
util.buf_diagnostics_save_positions(bufnr, result.diagnostics)
util.buf_diagnostics_underline(bufnr, result.diagnostics)
util.buf_diagnostics_virtual_text(bufnr, result.diagnostics)
-- util.buf_loclist(bufnr, result.diagnostics)
end
local function log_message(_, _, result, client_id)
local message_type = result.type
local message = result.message
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
api.nvim_err_writeln(string.format("LSP[%s] client has shut down after sending the message", client_name))
end
if message_type == protocol.MessageType.Error then
-- Might want to not use err_writeln,
-- but displaying a message with red highlights or something
api.nvim_err_writeln(string.format("LSP[%s] %s", client_name, message))
else
local message_type_name = protocol.MessageType[message_type]
api.nvim_out_write(string.format("LSP[%s][%s] %s\n", client_name, message_type_name, message))
end
return result
end
M['window/showMessage'] = log_message
M['window/logMessage'] = log_message
-- Add boilerplate error validation and logging for all of these.
for k, fn in pairs(M) do
M[k] = function(err, method, params, client_id)
local _ = log.debug() and log.debug('default_callback', method, { params = params, client_id = client_id, err = err })
if err then
error(tostring(err))
end
return fn(err, method, params, client_id)
end
end
return M
-- vim:sw=2 ts=2 et