Use stylua for autoformat code (#1480)

This commit is contained in:
Santos Gallegos 2021-07-04 16:12:17 -05:00 committed by GitHub
parent 90f15d9bf7
commit be8f656087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 1181 additions and 979 deletions

View file

@ -1,24 +1,23 @@
if not pcall(require,"vim.treesitter.languagetree") then
error("nvim-treesitter requires a more recent Neovim nightly version!")
if not pcall(require, "vim.treesitter.languagetree") then
error "nvim-treesitter requires a more recent Neovim nightly version!"
end
local install = require'nvim-treesitter.install'
local utils = require'nvim-treesitter.utils'
local ts_utils = require'nvim-treesitter.ts_utils'
local info = require'nvim-treesitter.info'
local configs = require'nvim-treesitter.configs'
local parsers = require'nvim-treesitter.parsers'
local install = require "nvim-treesitter.install"
local utils = require "nvim-treesitter.utils"
local ts_utils = require "nvim-treesitter.ts_utils"
local info = require "nvim-treesitter.info"
local configs = require "nvim-treesitter.configs"
local parsers = require "nvim-treesitter.parsers"
-- Registers all query predicates
require"nvim-treesitter.query_predicates"
require "nvim-treesitter.query_predicates"
local M = {}
function M.setup()
utils.setup_commands('install', install.commands)
utils.setup_commands('info', info.commands)
utils.setup_commands('configs', configs.commands)
utils.setup_commands("install", install.commands)
utils.setup_commands("info", info.commands)
utils.setup_commands("configs", configs.commands)
configs.init()
end
@ -35,37 +34,43 @@ local get_line_for_node = function(node, type_patterns, transform_fn)
break
end
end
if not is_valid then return '' end
local line = transform_fn(vim.trim(ts_utils.get_node_text(node)[1] or ''))
if not is_valid then
return ""
end
local line = transform_fn(vim.trim(ts_utils.get_node_text(node)[1] or ""))
-- Escape % to avoid statusline to evaluate content as expression
return line:gsub('%%', '%%%%')
return line:gsub("%%", "%%%%")
end
-- Trim spaces and opening brackets from end
local transform_line = function(line)
return line:gsub('%s*[%[%(%{]*%s*$', '')
return line:gsub("%s*[%[%(%{]*%s*$", "")
end
function M.statusline(opts)
if not parsers.has_parser() then return end
if not parsers.has_parser() then
return
end
local options = opts or {}
if type(opts) == 'number' then
options = {indicator_size = opts}
if type(opts) == "number" then
options = { indicator_size = opts }
end
local indicator_size = options.indicator_size or 100
local type_patterns = options.type_patterns or {'class', 'function', 'method'}
local type_patterns = options.type_patterns or { "class", "function", "method" }
local transform_fn = options.transform_fn or transform_line
local separator = options.separator or ' -> '
local separator = options.separator or " -> "
local current_node = ts_utils.get_node_at_cursor()
if not current_node then return "" end
if not current_node then
return ""
end
local lines = {}
local expr = current_node
while expr do
local line = get_line_for_node(expr, type_patterns, transform_fn)
if line ~= '' and not vim.tbl_contains(lines, line) then
if line ~= "" and not vim.tbl_contains(lines, line) then
table.insert(lines, 1, line)
end
expr = expr:parent()
@ -74,7 +79,7 @@ function M.statusline(opts)
local text = table.concat(lines, separator)
local text_len = #text
if text_len > indicator_size then
return '...'..text:sub(text_len - indicator_size, text_len)
return "..." .. text:sub(text_len - indicator_size, text_len)
end
return text