aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-treesitter.lua
diff options
context:
space:
mode:
authorTravonteD <tman1300@aol.com>2020-05-11 11:29:40 -0400
committerGitHub <noreply@github.com>2020-05-11 11:29:40 -0400
commit73ea03fb8d45378bb4c86cd98371232403a7495a (patch)
tree67920137c386b0876a57d7bc08ba4a9743f8881d /lua/nvim-treesitter.lua
parentMerge pull request #21 from haorenW1025/master (diff)
parentMerge pull request #47 from theHamsta/fix-typo-contributing.md (diff)
downloadnvim-treesitter-73ea03fb8d45378bb4c86cd98371232403a7495a.tar
nvim-treesitter-73ea03fb8d45378bb4c86cd98371232403a7495a.tar.gz
nvim-treesitter-73ea03fb8d45378bb4c86cd98371232403a7495a.tar.bz2
nvim-treesitter-73ea03fb8d45378bb4c86cd98371232403a7495a.tar.lz
nvim-treesitter-73ea03fb8d45378bb4c86cd98371232403a7495a.tar.xz
nvim-treesitter-73ea03fb8d45378bb4c86cd98371232403a7495a.tar.zst
nvim-treesitter-73ea03fb8d45378bb4c86cd98371232403a7495a.zip
Merge pull request #1 from nvim-treesitter/master
Updates from master
Diffstat (limited to 'lua/nvim-treesitter.lua')
-rw-r--r--lua/nvim-treesitter.lua58
1 files changed, 43 insertions, 15 deletions
diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua
index b053f39b0..90b5468a3 100644
--- a/lua/nvim-treesitter.lua
+++ b/lua/nvim-treesitter.lua
@@ -1,30 +1,58 @@
local api = vim.api
-local parsers = require'nvim-treesitter.parsers'
-local configs = require 'nvim-treesitter.configs'
local install = require'nvim-treesitter.install'
local locals = require'nvim-treesitter.locals'
-local highlight = require'nvim-treesitter.highlight'
+local utils = require'nvim-treesitter.utils'
+local info = require'nvim-treesitter.info'
+local configs = require'nvim-treesitter.configs'
local M = {}
-function M.available_parsers()
- return vim.tbl_keys(configs.repositories)
-end
-
-- This function sets up everythin needed for a given language
-- this is the main interface through the plugin
function M.setup(lang)
- if parsers.has_parser(lang) then
- local autocmd = "autocmd NvimTreesitter FileType %s lua require'nvim-treesitter.highlight'.setup()"
- api.nvim_command(string.format(autocmd, lang))
+ utils.setup_commands('install', install.commands)
+ utils.setup_commands('info', info.commands)
+ utils.setup_commands('configs', configs.commands)
+
+ for _, ft in pairs(configs.available_parsers()) do
+ for _, mod in pairs(configs.available_modules()) do
+ if configs.is_enabled(mod, ft) then
+ local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod)
+ api.nvim_command(string.format("autocmd FileType %s %s", ft, cmd))
+ end
+ end
end
end
--- This function initialize the plugin
--- it is run at startup
-M._root = {}
-function M._root.setup()
- install.setup()
+function M.statusline(indicator_size)
+ local indicator_size = indicator_size or 1000
+ local expr = require"nvim-treesitter.utils".expression_at_point()
+ local current_node =
+ require'nvim-treesitter.node_movement'.current_node[api.nvim_get_current_buf()]
+
+ local indicator = ""
+ while expr and (#indicator + #(expr:type()) + 5) < indicator_size do
+
+ local prefix = ""
+ if expr:parent() then
+ prefix = "->"
+ end
+
+
+ if expr == current_node then
+ indicator = string.format("%s[%s]%s", prefix, expr:type(), indicator)
+ else
+ indicator = prefix .. expr:type() .. indicator
+ end
+
+ expr = expr:parent()
+ end
+
+ if expr then
+ return "..." .. indicator
+ else
+ return indicator
+ end
end
return M