chore: use stylua for formatting (#1040)

* chore: stylua job and config

* reformat with stylua
This commit is contained in:
Simon Hauser
2021-07-23 17:42:37 +02:00
committed by GitHub
parent 664690029f
commit 79644ab677
75 changed files with 3201 additions and 2809 deletions

View File

@@ -1,9 +1,9 @@
local has_devicons, devicons = pcall(require, 'nvim-web-devicons')
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
local Path = require('plenary.path')
local Job = require('plenary.job')
local Path = require "plenary.path"
local Job = require "plenary.job"
local log = require('telescope.log')
local log = require "telescope.log"
local utils = {}
@@ -47,7 +47,7 @@ utils.default_table_mt = {
local obj = {}
rawset(t, k, obj)
return obj
end
end,
}
utils.repeated_table = function(n, val)
@@ -62,13 +62,14 @@ utils.quickfix_items_to_entries = function(locations)
local results = {}
for _, entry in ipairs(locations) do
local vimgrep_str = entry.vimgrep_str or string.format(
"%s:%s:%s: %s",
vim.fn.fnamemodify(entry.display_filename or entry.filename, ":."),
entry.lnum,
entry.col,
entry.text
)
local vimgrep_str = entry.vimgrep_str
or string.format(
"%s:%s:%s: %s",
vim.fn.fnamemodify(entry.display_filename or entry.filename, ":."),
entry.lnum,
entry.col,
entry.text
)
table.insert(results, {
valid = true,
@@ -119,7 +120,7 @@ utils.filter_symbols = function(results, opts)
end
end
else
print("Please pass filtering symbols as either a string or a list of strings")
print "Please pass filtering symbols as either a string or a list of strings"
return
end
@@ -131,7 +132,7 @@ utils.filter_symbols = function(results, opts)
if filename_to_bufnr[symbol.filename] == nil then
filename_to_bufnr[symbol.filename] = vim.uri_to_bufnr(vim.uri_from_fname(symbol.filename))
end
symbol['bufnr'] = filename_to_bufnr[symbol.filename]
symbol["bufnr"] = filename_to_bufnr[symbol.filename]
end
table.sort(filtered_symbols, function(a, b)
if a.bufnr == b.bufnr then
@@ -145,17 +146,17 @@ utils.filter_symbols = function(results, opts)
end
return a.bufnr < b.bufnr
end)
return filtered_symbols
return filtered_symbols
end
-- only account for string|table as function otherwise already printed message and returned nil
local symbols = type(opts.symbols) == 'string' and opts.symbols or table.concat(opts.symbols, ', ')
local symbols = type(opts.symbols) == "string" and opts.symbols or table.concat(opts.symbols, ", ")
print(string.format("%s symbol(s) were not part of the query results", symbols))
return
end
local convert_diagnostic_type = function(severity)
-- convert from string to int
if type(severity) == 'string' then
if type(severity) == "string" then
-- make sure that e.g. error is uppercased to Error
return vim.lsp.protocol.DiagnosticSeverity[severity:gsub("^%l", string.upper)]
end
@@ -186,20 +187,20 @@ utils.diagnostics_to_tbl = function(opts)
opts.severity_bound = convert_diagnostic_type(opts.severity_bound)
local validate_severity = 0
for _, v in ipairs({opts.severity, opts.severity_limit, opts.severity_bound}) do
for _, v in ipairs { opts.severity, opts.severity_limit, opts.severity_bound } do
if v ~= nil then
validate_severity = validate_severity + 1
end
if validate_severity > 1 then
print('Please pass valid severity parameters')
print "Please pass valid severity parameters"
return {}
end
end
local preprocess_diag = function(diag, bufnr)
local filename = vim.api.nvim_buf_get_name(bufnr)
local start = diag.range['start']
local finish = diag.range['end']
local start = diag.range["start"]
local finish = diag.range["end"]
local row = start.line
local col = start.character
@@ -212,13 +213,13 @@ utils.diagnostics_to_tbl = function(opts)
finish = finish,
-- remove line break to avoid display issues
text = vim.trim(diag.message:gsub("[\n]", "")),
type = lsp_type_diagnostic[diag.severity] or lsp_type_diagnostic[1]
type = lsp_type_diagnostic[diag.severity] or lsp_type_diagnostic[1],
}
return buffer_diag
end
local buffer_diags = opts.get_all and vim.lsp.diagnostic.get_all() or
{[current_buf] = vim.lsp.diagnostic.get(current_buf, opts.client_id)}
local buffer_diags = opts.get_all and vim.lsp.diagnostic.get_all()
or { [current_buf] = vim.lsp.diagnostic.get(current_buf, opts.client_id) }
for bufnr, diags in pairs(buffer_diags) do
for _, diag in ipairs(diags) do
-- workspace diagnostics may include empty tables for unused bufnr
@@ -253,14 +254,14 @@ utils.diagnostics_to_tbl = function(opts)
return items
end
utils.path_shorten = function(filename,len)
log.warn("`utils.path_shorten` is deprecated. Use `require('plenary.path').shorten`.")
utils.path_shorten = function(filename, len)
log.warn "`utils.path_shorten` is deprecated. Use `require('plenary.path').shorten`."
return Path:new(filename):shorten(len)
end
utils.path_tail = (function()
local os_sep = utils.get_separator()
local match_string = '[^' .. os_sep .. ']*$'
local match_string = "[^" .. os_sep .. "]*$"
return function(path)
return string.match(path, match_string)
@@ -268,25 +269,25 @@ utils.path_tail = (function()
end)()
utils.is_path_hidden = function(opts, path_display)
path_display = path_display or utils.get_default(opts.path_display, require('telescope.config').values.path_display)
path_display = path_display or utils.get_default(opts.path_display, require("telescope.config").values.path_display)
return path_display == nil or path_display == "hidden" or
type(path_display) ~= "table" or vim.tbl_contains(path_display, "hidden") or path_display.hidden
return path_display == nil
or path_display == "hidden"
or type(path_display) ~= "table"
or vim.tbl_contains(path_display, "hidden")
or path_display.hidden
end
utils.transform_path = function(opts, path)
local path_display = utils.get_default(opts.path_display, require('telescope.config').values.path_display)
local path_display = utils.get_default(opts.path_display, require("telescope.config").values.path_display)
local transformed_path = path
if type(path_display) == "function" then
return path_display(opts, transformed_path)
elseif utils.is_path_hidden(nil, path_display) then
return ''
return ""
elseif type(path_display) == "table" then
if vim.tbl_contains(path_display, "tail") or path_display.tail then
transformed_path = utils.path_tail(transformed_path)
else
@@ -298,7 +299,7 @@ utils.transform_path = function(opts, path)
cwd = vim.fn.expand(opts.cwd)
end
else
cwd = vim.loop.cwd();
cwd = vim.loop.cwd()
end
transformed_path = Path:new(transformed_path):make_relative(cwd)
end
@@ -310,8 +311,7 @@ utils.transform_path = function(opts, path)
return transformed_path
else
log.warn("`path_display` must be either a function or a table.",
"See `:help telescope.defaults.path_display.")
log.warn("`path_display` must be either a function or a table.", "See `:help telescope.defaults.path_display.")
return transformed_path
end
end
@@ -338,31 +338,39 @@ function utils.make_default_callable(f, default_opts)
if not ok then
error(debug.traceback(err))
end
end
end,
})
end
function utils.job_is_running(job_id)
if job_id == nil then return false end
return vim.fn.jobwait({job_id}, 0)[1] == -1
if job_id == nil then
return false
end
return vim.fn.jobwait({ job_id }, 0)[1] == -1
end
function utils.buf_delete(bufnr)
if bufnr == nil then return end
if bufnr == nil then
return
end
-- Suppress the buffer deleted message for those with &report<2
local start_report = vim.o.report
if start_report < 2 then vim.o.report = 2 end
if start_report < 2 then
vim.o.report = 2
end
if vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr) then
vim.api.nvim_buf_delete(bufnr, { force = true })
end
if start_report < 2 then vim.o.report = start_report end
if start_report < 2 then
vim.o.report = start_report
end
end
function utils.max_split(s, pattern, maxsplit)
pattern = pattern or ' '
pattern = pattern or " "
maxsplit = maxsplit or -1
local t = {}
@@ -393,12 +401,11 @@ function utils.max_split(s, pattern, maxsplit)
return t
end
function utils.data_directory()
local sourced_file = require('plenary.debug_utils').sourced_filepath()
local sourced_file = require("plenary.debug_utils").sourced_filepath()
local base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h")
return Path:new({base_directory, 'data'}):absolute() .. Path.path.sep
return Path:new({ base_directory, "data" }):absolute() .. Path.path.sep
end
function utils.display_termcodes(str)
@@ -407,31 +414,38 @@ end
function utils.get_os_command_output(cmd, cwd)
if type(cmd) ~= "table" then
print('Telescope: [get_os_command_output]: cmd has to be a table')
print "Telescope: [get_os_command_output]: cmd has to be a table"
return {}
end
local command = table.remove(cmd, 1)
local stderr = {}
local stdout, ret = Job:new({ command = command, args = cmd, cwd = cwd, on_stderr = function(_, data)
table.insert(stderr, data)
end }):sync()
local stdout, ret = Job
:new({
command = command,
args = cmd,
cwd = cwd,
on_stderr = function(_, data)
table.insert(stderr, data)
end,
})
:sync()
return stdout, ret, stderr
end
utils.strdisplaywidth = function()
error("strdisplaywidth deprecated. please use plenary.strings.strdisplaywidth")
error "strdisplaywidth deprecated. please use plenary.strings.strdisplaywidth"
end
utils.utf_ptr2len = function()
error("utf_ptr2len deprecated. please use plenary.strings.utf_ptr2len")
error "utf_ptr2len deprecated. please use plenary.strings.utf_ptr2len"
end
utils.strcharpart = function()
error("strcharpart deprecated. please use plenary.strings.strcharpart")
error "strcharpart deprecated. please use plenary.strings.strcharpart"
end
utils.align_str = function()
error("align_str deprecated. please use plenary.strings.align_str")
error "align_str deprecated. please use plenary.strings.align_str"
end
utils.transform_devicons = (function()
@@ -441,13 +455,13 @@ utils.transform_devicons = (function()
end
return function(filename, display, disable_devicons)
local conf = require('telescope.config').values
local conf = require("telescope.config").values
if disable_devicons or not filename then
return display
end
local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true })
local icon_display = (icon or ' ') .. ' ' .. (display or '')
local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, "%a+$"), { default = true })
local icon_display = (icon or " ") .. " " .. (display or "")
if conf.color_devicons then
return icon_display, icon_highlight
@@ -469,12 +483,12 @@ utils.get_devicons = (function()
end
return function(filename, disable_devicons)
local conf = require('telescope.config').values
local conf = require("telescope.config").values
if disable_devicons or not filename then
return ''
return ""
end
local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true })
local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, "%a+$"), { default = true })
if conf.color_devicons then
return icon, icon_highlight
else
@@ -483,7 +497,7 @@ utils.get_devicons = (function()
end
else
return function(_, _)
return ''
return ""
end
end
end)()