mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 10:50:06 -04:00
TSModuleInfo: make new buffer work with given argument
This commit is contained in:
parent
c64c8a4017
commit
fc5e37fe48
1 changed files with 16 additions and 24 deletions
|
|
@ -21,28 +21,12 @@ local function install_info()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function print_info_module(sorted_languages, mod)
|
|
||||||
local max_str_len = #sorted_languages[1]
|
|
||||||
local header = string.format('%s%s', string.rep(' ', max_str_len + 2), mod)
|
|
||||||
api.nvim_out_write(header..'\n')
|
|
||||||
for _, lang in pairs(sorted_languages) do
|
|
||||||
local padding = string.rep(' ', max_str_len - #lang + #mod / 2 + 1)
|
|
||||||
api.nvim_out_write(lang..":"..padding)
|
|
||||||
if configs.is_enabled(mod, lang) then
|
|
||||||
api.nvim_out_write('✓')
|
|
||||||
else
|
|
||||||
api.nvim_out_write('✗')
|
|
||||||
end
|
|
||||||
api.nvim_out_write('\n')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Sort a list of modules into namespaces.
|
-- Sort a list of modules into namespaces.
|
||||||
-- {'mod1', 'mod2.sub1', 'mod2.sub2', 'mod3'}
|
-- {'mod1', 'mod2.sub1', 'mod2.sub2', 'mod3'}
|
||||||
-- ->
|
-- ->
|
||||||
-- { default = {'mod1', 'mod3'}, mod2 = {'sub1', 'sub2'}}
|
-- { default = {'mod1', 'mod3'}, mod2 = {'sub1', 'sub2'}}
|
||||||
local function namespace_modules(modulelist)
|
local function namespace_modules(modulelist)
|
||||||
local modules = { default = {} }
|
local modules = {}
|
||||||
for _, module in ipairs(modulelist) do
|
for _, module in ipairs(modulelist) do
|
||||||
if module:find('%.') then
|
if module:find('%.') then
|
||||||
local namespace, submodule = module:match('^(.*)%.(.*)$')
|
local namespace, submodule = module:match('^(.*)%.(.*)$')
|
||||||
|
|
@ -51,6 +35,9 @@ local function namespace_modules(modulelist)
|
||||||
end
|
end
|
||||||
table.insert(modules[namespace], submodule)
|
table.insert(modules[namespace], submodule)
|
||||||
else
|
else
|
||||||
|
if not modules.default then
|
||||||
|
modules.default = {}
|
||||||
|
end
|
||||||
table.insert(modules.default, module)
|
table.insert(modules.default, module)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -99,17 +86,22 @@ local function append_module_table(curbuf, parserlist, namespace, modulelist)
|
||||||
api.nvim_buf_set_lines(curbuf, -1, -1, true, {''})
|
api.nvim_buf_set_lines(curbuf, -1, -1, true, {''})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function print_info_modules(parserlist)
|
local function print_info_modules(parserlist, module)
|
||||||
api.nvim_command('enew')
|
api.nvim_command('enew')
|
||||||
local curbuf = api.nvim_get_current_buf()
|
local curbuf = api.nvim_get_current_buf()
|
||||||
|
|
||||||
local modules = namespace_modules(configs.available_modules())
|
local modules
|
||||||
table.sort(parserlist)
|
if module then
|
||||||
|
modules = namespace_modules({module})
|
||||||
|
else
|
||||||
|
modules = namespace_modules(configs.available_modules())
|
||||||
|
end
|
||||||
|
|
||||||
local namespaces = {}
|
local namespaces = {}
|
||||||
for k, _ in pairs(modules) do table.insert(namespaces, k) end
|
for k, _ in pairs(modules) do table.insert(namespaces, k) end
|
||||||
table.sort(namespaces)
|
table.sort(namespaces)
|
||||||
|
|
||||||
|
table.sort(parserlist)
|
||||||
for _, namespace in ipairs(namespaces) do
|
for _, namespace in ipairs(namespaces) do
|
||||||
append_module_table(curbuf, parserlist, namespace, modules[namespace])
|
append_module_table(curbuf, parserlist, namespace, modules[namespace])
|
||||||
end
|
end
|
||||||
|
|
@ -130,12 +122,12 @@ local function print_info_modules(parserlist)
|
||||||
]], false)
|
]], false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function module_info(mod)
|
local function module_info(module)
|
||||||
if mod and not configs.get_module(mod) then return end
|
if module and not configs.get_module(module) then return end
|
||||||
|
|
||||||
local parserlist = parsers.available_parsers()
|
local parserlist = parsers.available_parsers()
|
||||||
if mod then
|
if module then
|
||||||
print_info_module(parserlist, mod)
|
print_info_modules(parserlist, module)
|
||||||
else
|
else
|
||||||
print_info_modules(parserlist)
|
print_info_modules(parserlist)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue