From a392dc347b387bca1c1d4d8528a1e5726fa36437 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 23 Oct 2022 00:22:28 +0800 Subject: [PATCH] style(lsp): format lsp.lua --- lua/spacevim/lsp.lua | 114 +++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/lua/spacevim/lsp.lua b/lua/spacevim/lsp.lua index f9da11d09..5e2b910a5 100644 --- a/lua/spacevim/lsp.lua +++ b/lua/spacevim/lsp.lua @@ -5,71 +5,71 @@ M.clients = {} -- which can be called via vim.lsp.start_client() function M.register(filetype, cmd) - M.clients[filetype] = { - ['cmd'] = cmd - } + M.clients[filetype] = { + ['cmd'] = cmd, + } end local function spliteof(data, delimiter) - local result = { } - local from = 1 - local delim_from, delim_to = string.find( data, delimiter, from ) - while delim_from do - table.insert( result, string.sub( data, from , delim_from-1 ) ) - from = delim_to + 1 - delim_from, delim_to = string.find( data, delimiter, from ) - end - table.insert( result, string.sub( data, from ) ) - return result + local result = {} + local from = 1 + local delim_from, delim_to = string.find(data, delimiter, from) + while delim_from do + table.insert(result, string.sub(data, from, delim_from - 1)) + from = delim_to + 1 + delim_from, delim_to = string.find(data, delimiter, from) + end + table.insert(result, string.sub(data, from)) + return result end -- -- if data.contents is a string and not empty -- silent put =a:data -- return 'markdown' --- if data +-- if data function M.hover_callback(success, data) - if not success then - vim.api.nvim_command('call SpaceVim#util#echoWarn("Failed to retrieve hover information")') - return - end - if (type(data.contents) == "table") then - vim.api.nvim_command('leftabove split __lspdoc__') - vim.api.nvim_command('set filetype=markdown.lspdoc') - vim.api.nvim_command('setlocal nobuflisted') - vim.api.nvim_command('setlocal buftype=nofile') - vim.api.nvim_command('setlocal bufhidden=wipe') - vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents.value, "\n")) - elseif type(data.contents) == 'string' and data.contents ~= '' then - -- for k, v in pairs(data) do - -- print(k .. " - " .. v) - -- kind is filetype - -- value is contents string - -- end - vim.api.nvim_command('leftabove split __lspdoc__') - vim.api.nvim_command('set filetype=markdown.lspdoc') - vim.api.nvim_command('setlocal nobuflisted') - vim.api.nvim_command('setlocal buftype=nofile') - vim.api.nvim_command('setlocal bufhidden=wipe') - vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents, "\n")) - elseif type(data.contents.language) ~= 'string' and data.contents.language ~= '' then - vim.api.nvim_command('leftabove split __lspdoc__') - vim.api.nvim_command('set filetype=markdown.lspdoc') - vim.api.nvim_command('setlocal nobuflisted') - vim.api.nvim_command('setlocal buftype=nofile') - vim.api.nvim_command('setlocal bufhidden=wipe') - vim.api.nvim_buf_set_lines(0, 0, -1, 0, {'```' .. data.contents.language}) - vim.api.nvim_buf_set_lines(0, 1, -1, 0, spliteof(data.contents, "\n")) - vim.api.nvim_buf_set_lines(0, -1, -1, 0, {'```'}) - elseif type(data.contents.kind) ~= 'string' and data.contents.kind ~= '' then - vim.api.nvim_command('leftabove split __lspdoc__') - vim.api.nvim_command('set filetype=' .. data.contents.kind .. '.lspdoc') - vim.api.nvim_command('setlocal nobuflisted') - vim.api.nvim_command('setlocal buftype=nofile') - vim.api.nvim_command('setlocal bufhidden=wipe') - vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents, "\n")) - else - print('No hover information found') - end - -- print(type(data)) + if not success then + vim.api.nvim_command('call SpaceVim#util#echoWarn("Failed to retrieve hover information")') + return + end + if type(data.contents) == 'table' then + vim.api.nvim_command('leftabove split __lspdoc__') + vim.api.nvim_command('set filetype=markdown.lspdoc') + vim.api.nvim_command('setlocal nobuflisted') + vim.api.nvim_command('setlocal buftype=nofile') + vim.api.nvim_command('setlocal bufhidden=wipe') + vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents.value, '\n')) + elseif type(data.contents) == 'string' and data.contents ~= '' then + -- for k, v in pairs(data) do + -- print(k .. " - " .. v) + -- kind is filetype + -- value is contents string + -- end + vim.api.nvim_command('leftabove split __lspdoc__') + vim.api.nvim_command('set filetype=markdown.lspdoc') + vim.api.nvim_command('setlocal nobuflisted') + vim.api.nvim_command('setlocal buftype=nofile') + vim.api.nvim_command('setlocal bufhidden=wipe') + vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents, '\n')) + elseif type(data.contents.language) ~= 'string' and data.contents.language ~= '' then + vim.api.nvim_command('leftabove split __lspdoc__') + vim.api.nvim_command('set filetype=markdown.lspdoc') + vim.api.nvim_command('setlocal nobuflisted') + vim.api.nvim_command('setlocal buftype=nofile') + vim.api.nvim_command('setlocal bufhidden=wipe') + vim.api.nvim_buf_set_lines(0, 0, -1, 0, { '```' .. data.contents.language }) + vim.api.nvim_buf_set_lines(0, 1, -1, 0, spliteof(data.contents, '\n')) + vim.api.nvim_buf_set_lines(0, -1, -1, 0, { '```' }) + elseif type(data.contents.kind) ~= 'string' and data.contents.kind ~= '' then + vim.api.nvim_command('leftabove split __lspdoc__') + vim.api.nvim_command('set filetype=' .. data.contents.kind .. '.lspdoc') + vim.api.nvim_command('setlocal nobuflisted') + vim.api.nvim_command('setlocal buftype=nofile') + vim.api.nvim_command('setlocal bufhidden=wipe') + vim.api.nvim_buf_set_lines(0, 0, -1, 0, spliteof(data.contents, '\n')) + else + print('No hover information found') + end + -- print(type(data)) end return M