aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-treesitter.lua
diff options
context:
space:
mode:
authorSantos Gallegos <stsewd@protonmail.com>2021-07-04 16:12:17 -0500
committerGitHub <noreply@github.com>2021-07-04 21:12:17 +0000
commitbe8f65608796e50aa2e2da5452849c263558f0ed (patch)
tree39f6057de9026ab312c3bb838e773910129b5575 /lua/nvim-treesitter.lua
parentfeat(keywords) merge return and yield into keyword.return group (diff)
downloadnvim-treesitter-be8f65608796e50aa2e2da5452849c263558f0ed.tar
nvim-treesitter-be8f65608796e50aa2e2da5452849c263558f0ed.tar.gz
nvim-treesitter-be8f65608796e50aa2e2da5452849c263558f0ed.tar.bz2
nvim-treesitter-be8f65608796e50aa2e2da5452849c263558f0ed.tar.lz
nvim-treesitter-be8f65608796e50aa2e2da5452849c263558f0ed.tar.xz
nvim-treesitter-be8f65608796e50aa2e2da5452849c263558f0ed.tar.zst
nvim-treesitter-be8f65608796e50aa2e2da5452849c263558f0ed.zip
Use stylua for autoformat code (#1480)
Diffstat (limited to 'lua/nvim-treesitter.lua')
-rw-r--r--lua/nvim-treesitter.lua55
1 files changed, 30 insertions, 25 deletions
diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua
index 145df7be8..af46bd017 100644
--- a/lua/nvim-treesitter.lua
+++ b/lua/nvim-treesitter.lua
@@ -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