mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-06 13:30:01 -04:00
refactor!: update to Neovim 0.7 APIs
* set highlight groups via nvim_set_hl * define autocommands via nvim_create_autocmd * port plugin/nvim-treesitter.vim to Lua * port healthcheck to Lua
This commit is contained in:
parent
bc25a6a5c4
commit
07eb437bb1
8 changed files with 168 additions and 148 deletions
|
|
@ -100,8 +100,13 @@ local function enable_mod_conf_autocmd(mod)
|
|||
return
|
||||
end
|
||||
|
||||
local cmd = string.format("lua require'nvim-treesitter.configs'.reattach_module('%s')", mod)
|
||||
api.nvim_command(string.format("autocmd NvimTreesitter FileType * %s", cmd))
|
||||
api.nvim_create_autocmd("FileType", {
|
||||
group = "NvimTreesitter",
|
||||
callback = function()
|
||||
require("nvim-treesitter.configs").reattach_module(mod)
|
||||
end,
|
||||
desc = "Reattach module",
|
||||
})
|
||||
|
||||
config_mod.loaded = true
|
||||
end
|
||||
|
|
@ -150,7 +155,7 @@ local function disable_mod_conf_autocmd(mod)
|
|||
end
|
||||
-- TODO(kyazdani): detach the correct autocmd... doesn't work when using %s, cmd.
|
||||
-- This will remove all autocomands!
|
||||
api.nvim_command "autocmd! NvimTreesitter FileType *"
|
||||
api.nvim_clear_autocmds { event = "FileType", group = "NvimTreesitter" }
|
||||
config_mod.loaded = false
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,29 +7,26 @@ local shell = require "nvim-treesitter.shell_command_selectors"
|
|||
local install = require "nvim-treesitter.install"
|
||||
local utils = require "nvim-treesitter.utils"
|
||||
|
||||
local health_start = vim.fn["health#report_start"]
|
||||
local health_ok = vim.fn["health#report_ok"]
|
||||
local health_error = vim.fn["health#report_error"]
|
||||
local health_warn = vim.fn["health#report_warn"]
|
||||
local health = require "health"
|
||||
|
||||
local M = {}
|
||||
|
||||
local NVIM_TREESITTER_MINIMUM_ABI = 13
|
||||
|
||||
local function install_health()
|
||||
health_start "Installation"
|
||||
health.report_start "Installation"
|
||||
|
||||
if fn.has "nvim-0.7" == 0 then
|
||||
health_error "Nvim-treesitter requires Neovim 0.7.0+"
|
||||
health.report_error "Nvim-treesitter requires Neovim 0.7.0+"
|
||||
end
|
||||
|
||||
if fn.executable "tree-sitter" == 0 then
|
||||
health_warn(
|
||||
health.report_warn(
|
||||
"`tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar,"
|
||||
.. " not required for :TSInstall)"
|
||||
)
|
||||
else
|
||||
health_ok(
|
||||
health.report_ok(
|
||||
"`tree-sitter` found "
|
||||
.. (utils.ts_cli_version() or "(unknown version)")
|
||||
.. " (parser generator, only needed for :TSInstallFromGrammar)"
|
||||
|
|
@ -37,7 +34,7 @@ local function install_health()
|
|||
end
|
||||
|
||||
if fn.executable "node" == 0 then
|
||||
health_warn(
|
||||
health.report_warn(
|
||||
"`node` executable not found (only needed for :TSInstallFromGrammar," .. " not required for :TSInstall)"
|
||||
)
|
||||
else
|
||||
|
|
@ -45,21 +42,21 @@ local function install_health()
|
|||
local result = handle:read "*a"
|
||||
handle:close()
|
||||
local version = vim.split(result, "\n")[1]
|
||||
health_ok("`node` found " .. version .. " (only needed for :TSInstallFromGrammar)")
|
||||
health.report_ok("`node` found " .. version .. " (only needed for :TSInstallFromGrammar)")
|
||||
end
|
||||
|
||||
if fn.executable "git" == 0 then
|
||||
health_error("`git` executable not found.", {
|
||||
health.report_error("`git` executable not found.", {
|
||||
"Install it with your package manager.",
|
||||
"Check that your `$PATH` is set correctly.",
|
||||
})
|
||||
else
|
||||
health_ok "`git` executable found."
|
||||
health.report_ok "`git` executable found."
|
||||
end
|
||||
|
||||
local cc = shell.select_executable(install.compilers)
|
||||
if not cc then
|
||||
health_error("`cc` executable not found.", {
|
||||
health.report_error("`cc` executable not found.", {
|
||||
"Check that any of "
|
||||
.. vim.inspect(install.compilers)
|
||||
.. " is in your $PATH"
|
||||
|
|
@ -67,7 +64,7 @@ local function install_health()
|
|||
})
|
||||
else
|
||||
local version = vim.fn.systemlist(cc .. (cc == "cl" and "" or " --version"))[1]
|
||||
health_ok(
|
||||
health.report_ok(
|
||||
"`"
|
||||
.. cc
|
||||
.. "` executable found. Selected from "
|
||||
|
|
@ -77,7 +74,7 @@ local function install_health()
|
|||
end
|
||||
if vim.treesitter.language_version then
|
||||
if vim.treesitter.language_version >= NVIM_TREESITTER_MINIMUM_ABI then
|
||||
health_ok(
|
||||
health.report_ok(
|
||||
"Neovim was compiled with tree-sitter runtime ABI version "
|
||||
.. vim.treesitter.language_version
|
||||
.. " (required >="
|
||||
|
|
@ -85,7 +82,7 @@ local function install_health()
|
|||
.. "). Parsers must be compatible with runtime ABI."
|
||||
)
|
||||
else
|
||||
health_error(
|
||||
health.report_error(
|
||||
"Neovim was compiled with tree-sitter runtime ABI version "
|
||||
.. vim.treesitter.language_version
|
||||
.. ".\n"
|
||||
|
|
@ -141,9 +138,9 @@ function M.check()
|
|||
x) errors found in the query, try to run :TSUpdate {lang}]]
|
||||
table.insert(parser_installation, legend)
|
||||
-- Finally call the report function
|
||||
health_start(table.concat(parser_installation, "\n"))
|
||||
health.report_start(table.concat(parser_installation, "\n"))
|
||||
if #error_collection > 0 then
|
||||
health_start "The following errors have been detected:"
|
||||
health.report_start "The following errors have been detected:"
|
||||
for _, p in ipairs(error_collection) do
|
||||
local lang, type, err = unpack(p)
|
||||
local lines = {}
|
||||
|
|
@ -164,7 +161,7 @@ function M.check()
|
|||
end
|
||||
end
|
||||
end
|
||||
health_error(table.concat(lines, "\n"))
|
||||
health.report_error(table.concat(lines, "\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -195,7 +195,10 @@ local indent_funcs = {}
|
|||
function M.attach(bufnr)
|
||||
indent_funcs[bufnr] = vim.bo.indentexpr
|
||||
vim.bo.indentexpr = "nvim_treesitter#indent()"
|
||||
vim.api.nvim_command("au Filetype " .. vim.bo.filetype .. " setlocal indentexpr=nvim_treesitter#indent()")
|
||||
vim.api.nvim_create_autocmd("Filetype", {
|
||||
pattern = vim.bo.filetype,
|
||||
command = "setlocal indentexpr=nvim_treesitter#indent()",
|
||||
})
|
||||
end
|
||||
|
||||
function M.detach(bufnr)
|
||||
|
|
|
|||
|
|
@ -115,21 +115,24 @@ local function print_info_modules(parserlist, module)
|
|||
|
||||
api.nvim_buf_set_option(curbuf, "modified", false)
|
||||
api.nvim_buf_set_option(curbuf, "buftype", "nofile")
|
||||
api.nvim_exec(
|
||||
[[
|
||||
syntax match TSModuleInfoGood /✓/
|
||||
syntax match TSModuleInfoBad /✗/
|
||||
syntax match TSModuleInfoHeader /^>>.*$/ contains=TSModuleInfoNamespace
|
||||
syntax match TSModuleInfoNamespace /^>> \w*/ contained
|
||||
syntax match TSModuleInfoParser /^[^> ]*\ze /
|
||||
highlight default TSModuleInfoGood guifg=LightGreen gui=bold
|
||||
highlight default TSModuleInfoBad guifg=Crimson
|
||||
highlight default link TSModuleInfoHeader Type
|
||||
highlight default link TSModuleInfoNamespace Statement
|
||||
highlight default link TSModuleInfoParser Identifier
|
||||
]],
|
||||
false
|
||||
)
|
||||
vim.cmd [[
|
||||
syntax match TSModuleInfoGood /✓/
|
||||
syntax match TSModuleInfoBad /✗/
|
||||
syntax match TSModuleInfoHeader /^>>.*$/ contains=TSModuleInfoNamespace
|
||||
syntax match TSModuleInfoNamespace /^>> \w*/ contained
|
||||
syntax match TSModuleInfoParser /^[^> ]*\ze /
|
||||
]]
|
||||
|
||||
local highlights = {
|
||||
TSModuleInfoGood = { fg = "LightGreen", bold = true, default = true },
|
||||
TSModuleInfoBad = { fg = "Crimson", default = true },
|
||||
TSModuleInfoHeader = { link = "Type", default = true },
|
||||
TSModuleInfoNamespace = { link = "Statement", default = true },
|
||||
TSModuleInfoParser = { link = "Identifier", default = true },
|
||||
}
|
||||
for k, v in pairs(highlights) do
|
||||
api.nvim_set_hl(0, k, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function module_info(module)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue