mirror of
https://github.com/neovim/neovim.git
synced 2025-10-16 06:46:07 +00:00
Merge pull request #15391 from vigoux/ts-lua-builtin
feat(treesitter): highlighting for core languages, enabled for Lua
This commit is contained in:
2
.github/workflows/env.sh
vendored
2
.github/workflows/env.sh
vendored
@@ -57,7 +57,7 @@ EOF
|
|||||||
functionaltest-lua)
|
functionaltest-lua)
|
||||||
BUILD_FLAGS="$BUILD_FLAGS -DPREFER_LUA=ON"
|
BUILD_FLAGS="$BUILD_FLAGS -DPREFER_LUA=ON"
|
||||||
FUNCTIONALTEST=functionaltest-lua
|
FUNCTIONALTEST=functionaltest-lua
|
||||||
DEPS_CMAKE_FLAGS="$DEPS_CMAKE_FLAGS -DUSE_BUNDLED_LUAJIT=OFF -DUSE_BUNDLED_TS_PARSERS=OFF"
|
DEPS_CMAKE_FLAGS="$DEPS_CMAKE_FLAGS -DUSE_BUNDLED_LUAJIT=OFF"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
|
@@ -208,6 +208,12 @@ set(LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc891
|
|||||||
set(TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz)
|
set(TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz)
|
||||||
set(TREESITTER_C_SHA256 af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2 )
|
set(TREESITTER_C_SHA256 af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2 )
|
||||||
|
|
||||||
|
set(TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.12.tar.gz)
|
||||||
|
set(TREESITTER_LUA_SHA256 b6d7c6d04e9101a2e589d25f1d61668301e776c0b8defa6eae8dd86272e9e7c3)
|
||||||
|
|
||||||
|
set(TREESITTER_VIM_URL https://github.com/vigoux/tree-sitter-viml/archive/v0.1.0.tar.gz)
|
||||||
|
set(TREESITTER_VIM_SHA256 ea64fa211ccc7197669017b55911fdb56e8d4b6de96ba25c32b9586ec1c4f4c5)
|
||||||
|
|
||||||
set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.7.tar.gz)
|
set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.7.tar.gz)
|
||||||
set(TREESITTER_SHA256 b355e968ec2d0241bbd96748e00a9038f83968f85d822ecb9940cbe4c42e182e)
|
set(TREESITTER_SHA256 b355e968ec2d0241bbd96748e00a9038f83968f85d822ecb9940cbe4c42e182e)
|
||||||
|
|
||||||
|
@@ -1,29 +1,25 @@
|
|||||||
ExternalProject_Add(treesitter-c
|
function(BuildTSParser LANG TS_URL TS_SHA256 TS_CMAKE_FILE)
|
||||||
PREFIX ${DEPS_BUILD_DIR}
|
set(NAME treesitter-${LANG})
|
||||||
URL ${TREESITTER_C_URL}
|
ExternalProject_Add(${NAME}
|
||||||
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/treesitter-c
|
PREFIX ${DEPS_BUILD_DIR}
|
||||||
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
|
URL ${TREESITTER_C_URL}
|
||||||
-DPREFIX=${DEPS_BUILD_DIR}
|
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/${NAME}
|
||||||
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/treesitter-c
|
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
|
||||||
-DURL=${TREESITTER_C_URL}
|
-DPREFIX=${DEPS_BUILD_DIR}
|
||||||
-DEXPECTED_SHA256=${TREESITTER_C_SHA256}
|
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/${NAME}
|
||||||
-DTARGET=treesitter-c
|
-DURL=${TS_URL}
|
||||||
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
|
-DEXPECTED_SHA256=${TS_SHA256}
|
||||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
-DTARGET=${NAME}
|
||||||
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
|
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/TreesitterParserCMakeLists.txt
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
||||||
${DEPS_BUILD_DIR}/src/treesitter-c/CMakeLists.txt
|
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
CMAKE_ARGS
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TS_CMAKE_FILE}
|
||||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
${DEPS_BUILD_DIR}/src/${NAME}/CMakeLists.txt
|
||||||
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
|
CMAKE_ARGS
|
||||||
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
|
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
|
||||||
${BUILD_TYPE_STRING}
|
-DPARSERLANG=${LANG})
|
||||||
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
|
endfunction()
|
||||||
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_ALT_SEP}
|
|
||||||
# Pass toolchain
|
|
||||||
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
|
|
||||||
-DPARSERLANG=c
|
|
||||||
|
|
||||||
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
|
BuildTSParser(c ${TREESITTER_C_URL} ${TREESITTER_C_SHA256} TreesitterParserCMakeLists.txt)
|
||||||
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}
|
BuildTSParser(lua ${TREESITTER_LUA_URL} ${TREESITTER_LUA_SHA256} TreesitterParserCMakeLists.txt)
|
||||||
LIST_SEPARATOR |)
|
BuildTSParser(vim ${TREESITTER_VIM_URL} ${TREESITTER_VIM_SHA256} TreesitterParserCMakeLists.txt)
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
# some parsers have c++ scanner, problem?
|
project(parser C)
|
||||||
project(parser C) # CXX
|
|
||||||
|
file(GLOB source_files src/*.c)
|
||||||
|
|
||||||
add_library(parser
|
add_library(parser
|
||||||
MODULE
|
MODULE
|
||||||
src/parser.c
|
${source_files}
|
||||||
)
|
)
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
parser
|
parser
|
||||||
|
@@ -123,7 +123,7 @@ foreach(PROG ${RUNTIME_PROGRAMS})
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
globrecurse_wrapper(RUNTIME_FILES ${CMAKE_CURRENT_SOURCE_DIR}
|
globrecurse_wrapper(RUNTIME_FILES ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
*.vim *.lua *.dict *.py *.rb *.ps *.spl *.tutor *.tutor.json)
|
*.vim *.lua *.scm *.dict *.py *.rb *.ps *.spl *.tutor *.tutor.json)
|
||||||
|
|
||||||
foreach(F ${RUNTIME_FILES})
|
foreach(F ${RUNTIME_FILES})
|
||||||
get_filename_component(BASEDIR ${F} DIRECTORY)
|
get_filename_component(BASEDIR ${F} DIRECTORY)
|
||||||
|
@@ -375,9 +375,9 @@ get_captures_at_position({bufnr}, {row}, {col})
|
|||||||
Gets a list of captures for a given cursor position
|
Gets a list of captures for a given cursor position
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{bufnr} (number) The buffer number
|
{bufnr} (number) Buffer number (0 for current buffer)
|
||||||
{row} (number) The position row
|
{row} (number) Position row
|
||||||
{col} (number) The position column
|
{col} (number) Position column
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(table) A table of captures
|
(table) A table of captures
|
||||||
@@ -398,12 +398,14 @@ get_parser({bufnr}, {lang}, {opts}) *get_parser()*
|
|||||||
callback
|
callback
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{bufnr} The buffer the parser should be tied to
|
{bufnr} (number|nil) Buffer the parser should be tied to: (default
|
||||||
{lang} The filetype of this parser
|
current buffer)
|
||||||
{opts} Options object to pass to the created language tree
|
{lang} (string) |nil Filetype of this parser (default: buffer
|
||||||
|
filetype)
|
||||||
|
{opts} (table|nil) Options to pass to the created language tree
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
The parser
|
(table) Parser object
|
||||||
|
|
||||||
get_string_parser({str}, {lang}, {opts}) *get_string_parser()*
|
get_string_parser({str}, {lang}, {opts}) *get_string_parser()*
|
||||||
Gets a string parser
|
Gets a string parser
|
||||||
@@ -417,8 +419,8 @@ is_ancestor({dest}, {source}) *is_ancestor()*
|
|||||||
Determines whether a node is the ancestor of another
|
Determines whether a node is the ancestor of another
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{dest} (table) the possible ancestor
|
{dest} (table) Possible ancestor
|
||||||
{source} (table) the possible descendant node
|
{source} (table) Possible descendant node
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(boolean) True if dest is an ancestor of source
|
(boolean) True if dest is an ancestor of source
|
||||||
@@ -427,20 +429,57 @@ is_in_node_range({node}, {line}, {col}) *is_in_node_range()*
|
|||||||
Determines whether (line, col) position is in node range
|
Determines whether (line, col) position is in node range
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{node} Node defining the range
|
{node} (table) Node defining the range
|
||||||
{line} A line (0-based)
|
{line} (number) Line (0-based)
|
||||||
{col} A column (0-based)
|
{col} (number) Column (0-based)
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
(boolean) True if the position is in node range
|
||||||
|
|
||||||
node_contains({node}, {range}) *node_contains()*
|
node_contains({node}, {range}) *node_contains()*
|
||||||
Determines if a node contains a range
|
Determines if a node contains a range
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{node} (table) The node
|
{node} (table)
|
||||||
{range} (table) The range
|
{range} (table)
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(boolean) True if the node contains the range
|
(boolean) True if the node contains the range
|
||||||
|
|
||||||
|
start({bufnr}, {lang}, {opts}) *start()*
|
||||||
|
Start treesitter highlighting for a buffer
|
||||||
|
|
||||||
|
Can be used in an ftplugin or FileType autocommand
|
||||||
|
|
||||||
|
Note: By default, disables regex syntax highlighting, which may be
|
||||||
|
required for some plugins. In this case, add `{ syntax = true }`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex',
|
||||||
|
callback = function(args)
|
||||||
|
vim.treesitter.start(args.buf, 'latex', { syntax = true })
|
||||||
|
end
|
||||||
|
})
|
||||||
|
<
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
{bufnr} (number|nil) Buffer to be highlighted (default: current
|
||||||
|
buffer)
|
||||||
|
{lang} (string|nil) Language of the parser (default: buffer
|
||||||
|
filetype)
|
||||||
|
{opts} (table|nil) Optional keyword arguments:
|
||||||
|
• `syntax` boolean Run regex syntax highlighting (default
|
||||||
|
false)
|
||||||
|
|
||||||
|
stop({bufnr}) *stop()*
|
||||||
|
Stop treesitter highlighting for a buffer
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
{bufnr} (number|nil) Buffer to stop highlighting (default: current
|
||||||
|
buffer)
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
Lua module: vim.treesitter.language *treesitter-language*
|
Lua module: vim.treesitter.language *treesitter-language*
|
||||||
|
3
runtime/ftplugin/lua.lua
Normal file
3
runtime/ftplugin/lua.lua
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
if vim.g.ts_highlight_lua then
|
||||||
|
vim.treesitter.start()
|
||||||
|
end
|
@@ -32,9 +32,11 @@ setmetatable(M, {
|
|||||||
---
|
---
|
||||||
--- It is not recommended to use this, use vim.treesitter.get_parser() instead.
|
--- It is not recommended to use this, use vim.treesitter.get_parser() instead.
|
||||||
---
|
---
|
||||||
---@param bufnr The buffer the parser will be tied to
|
---@param bufnr string Buffer the parser will be tied to (0 for current buffer)
|
||||||
---@param lang The language of the parser
|
---@param lang string Language of the parser
|
||||||
---@param opts Options to pass to the created language tree
|
---@param opts table|nil Options to pass to the created language tree
|
||||||
|
---
|
||||||
|
---@returns table Created parser object
|
||||||
function M._create_parser(bufnr, lang, opts)
|
function M._create_parser(bufnr, lang, opts)
|
||||||
language.require_language(lang)
|
language.require_language(lang)
|
||||||
if bufnr == 0 then
|
if bufnr == 0 then
|
||||||
@@ -79,11 +81,11 @@ end
|
|||||||
--- If needed this will create the parser.
|
--- If needed this will create the parser.
|
||||||
--- Unconditionally attach the provided callback
|
--- Unconditionally attach the provided callback
|
||||||
---
|
---
|
||||||
---@param bufnr The buffer the parser should be tied to
|
---@param bufnr number|nil Buffer the parser should be tied to: (default current buffer)
|
||||||
---@param lang The filetype of this parser
|
---@param lang string |nil Filetype of this parser (default: buffer filetype)
|
||||||
---@param opts Options object to pass to the created language tree
|
---@param opts table|nil Options to pass to the created language tree
|
||||||
---
|
---
|
||||||
---@returns The parser
|
---@returns table Parser object
|
||||||
function M.get_parser(bufnr, lang, opts)
|
function M.get_parser(bufnr, lang, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
@@ -120,8 +122,8 @@ end
|
|||||||
|
|
||||||
--- Determines whether a node is the ancestor of another
|
--- Determines whether a node is the ancestor of another
|
||||||
---
|
---
|
||||||
---@param dest table the possible ancestor
|
---@param dest table Possible ancestor
|
||||||
---@param source table the possible descendant node
|
---@param source table Possible descendant node
|
||||||
---
|
---
|
||||||
---@returns (boolean) True if dest is an ancestor of source
|
---@returns (boolean) True if dest is an ancestor of source
|
||||||
function M.is_ancestor(dest, source)
|
function M.is_ancestor(dest, source)
|
||||||
@@ -156,9 +158,11 @@ end
|
|||||||
|
|
||||||
---Determines whether (line, col) position is in node range
|
---Determines whether (line, col) position is in node range
|
||||||
---
|
---
|
||||||
---@param node Node defining the range
|
---@param node table Node defining the range
|
||||||
---@param line A line (0-based)
|
---@param line number Line (0-based)
|
||||||
---@param col A column (0-based)
|
---@param col number Column (0-based)
|
||||||
|
---
|
||||||
|
---@returns (boolean) True if the position is in node range
|
||||||
function M.is_in_node_range(node, line, col)
|
function M.is_in_node_range(node, line, col)
|
||||||
local start_line, start_col, end_line, end_col = M.get_node_range(node)
|
local start_line, start_col, end_line, end_col = M.get_node_range(node)
|
||||||
if line >= start_line and line <= end_line then
|
if line >= start_line and line <= end_line then
|
||||||
@@ -177,8 +181,8 @@ function M.is_in_node_range(node, line, col)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Determines if a node contains a range
|
---Determines if a node contains a range
|
||||||
---@param node table The node
|
---@param node table
|
||||||
---@param range table The range
|
---@param range table
|
||||||
---
|
---
|
||||||
---@returns (boolean) True if the node contains the range
|
---@returns (boolean) True if the node contains the range
|
||||||
function M.node_contains(node, range)
|
function M.node_contains(node, range)
|
||||||
@@ -190,9 +194,9 @@ function M.node_contains(node, range)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Gets a list of captures for a given cursor position
|
---Gets a list of captures for a given cursor position
|
||||||
---@param bufnr number The buffer number
|
---@param bufnr number Buffer number (0 for current buffer)
|
||||||
---@param row number The position row
|
---@param row number Position row
|
||||||
---@param col number The position column
|
---@param col number Position column
|
||||||
---
|
---
|
||||||
---@returns (table) A table of captures
|
---@returns (table) A table of captures
|
||||||
function M.get_captures_at_position(bufnr, row, col)
|
function M.get_captures_at_position(bufnr, row, col)
|
||||||
@@ -241,4 +245,52 @@ function M.get_captures_at_position(bufnr, row, col)
|
|||||||
return matches
|
return matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Start treesitter highlighting for a buffer
|
||||||
|
---
|
||||||
|
--- Can be used in an ftplugin or FileType autocommand
|
||||||
|
---
|
||||||
|
--- Note: By default, disables regex syntax highlighting, which may be required for some plugins.
|
||||||
|
--- In this case, add `{ syntax = true }`.
|
||||||
|
---
|
||||||
|
--- Example:
|
||||||
|
---
|
||||||
|
--- <pre>
|
||||||
|
--- vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex',
|
||||||
|
--- callback = function(args)
|
||||||
|
--- vim.treesitter.start(args.buf, 'latex', { syntax = true })
|
||||||
|
--- end
|
||||||
|
--- })
|
||||||
|
--- </pre>
|
||||||
|
---
|
||||||
|
---@param bufnr number|nil Buffer to be highlighted (default: current buffer)
|
||||||
|
---@param lang string|nil Language of the parser (default: buffer filetype)
|
||||||
|
---@param opts table|nil Optional keyword arguments:
|
||||||
|
--- - `syntax` boolean Run regex syntax highlighting (default false)
|
||||||
|
function M.start(bufnr, lang, opts)
|
||||||
|
bufnr = bufnr or a.nvim_get_current_buf()
|
||||||
|
|
||||||
|
local parser = M.get_parser(bufnr, lang)
|
||||||
|
|
||||||
|
M.highlighter.new(parser)
|
||||||
|
|
||||||
|
vim.b[bufnr].ts_highlight = true
|
||||||
|
|
||||||
|
if opts and opts.syntax then
|
||||||
|
vim.bo[bufnr].syntax = 'on'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Stop treesitter highlighting for a buffer
|
||||||
|
---
|
||||||
|
---@param bufnr number|nil Buffer to stop highlighting (default: current buffer)
|
||||||
|
function M.stop(bufnr)
|
||||||
|
bufnr = bufnr or a.nvim_get_current_buf()
|
||||||
|
|
||||||
|
if M.highlighter.active[bufnr] then
|
||||||
|
M.highlighter.active[bufnr]:destroy()
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.bo[bufnr].syntax = 'on'
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
3
runtime/queries/c/injections.scm
Normal file
3
runtime/queries/c/injections.scm
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
(preproc_arg) @c
|
||||||
|
|
||||||
|
; (comment) @comment
|
192
runtime/queries/lua/highlights.scm
Normal file
192
runtime/queries/lua/highlights.scm
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
;; Keywords
|
||||||
|
|
||||||
|
"return" @keyword.return
|
||||||
|
|
||||||
|
[
|
||||||
|
"goto"
|
||||||
|
"in"
|
||||||
|
"local"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
(label_statement) @label
|
||||||
|
|
||||||
|
(break_statement) @keyword
|
||||||
|
|
||||||
|
(do_statement
|
||||||
|
[
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
] @keyword)
|
||||||
|
|
||||||
|
(while_statement
|
||||||
|
[
|
||||||
|
"while"
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
] @repeat)
|
||||||
|
|
||||||
|
(repeat_statement
|
||||||
|
[
|
||||||
|
"repeat"
|
||||||
|
"until"
|
||||||
|
] @repeat)
|
||||||
|
|
||||||
|
(if_statement
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"elseif"
|
||||||
|
"else"
|
||||||
|
"then"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(elseif_statement
|
||||||
|
[
|
||||||
|
"elseif"
|
||||||
|
"then"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(else_statement
|
||||||
|
[
|
||||||
|
"else"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(for_statement
|
||||||
|
[
|
||||||
|
"for"
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
] @repeat)
|
||||||
|
|
||||||
|
(function_declaration
|
||||||
|
[
|
||||||
|
"function"
|
||||||
|
"end"
|
||||||
|
] @keyword.function)
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
[
|
||||||
|
"function"
|
||||||
|
"end"
|
||||||
|
] @keyword.function)
|
||||||
|
|
||||||
|
;; Operators
|
||||||
|
|
||||||
|
[
|
||||||
|
"and"
|
||||||
|
"not"
|
||||||
|
"or"
|
||||||
|
] @keyword.operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"%"
|
||||||
|
"^"
|
||||||
|
"#"
|
||||||
|
"=="
|
||||||
|
"~="
|
||||||
|
"<="
|
||||||
|
">="
|
||||||
|
"<"
|
||||||
|
">"
|
||||||
|
"="
|
||||||
|
"&"
|
||||||
|
"~"
|
||||||
|
"|"
|
||||||
|
"<<"
|
||||||
|
">>"
|
||||||
|
"//"
|
||||||
|
".."
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
;; Punctuations
|
||||||
|
|
||||||
|
[
|
||||||
|
";"
|
||||||
|
":"
|
||||||
|
","
|
||||||
|
"."
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
;; Brackets
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
;; Variables
|
||||||
|
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
((identifier) @variable.builtin
|
||||||
|
(#eq? @variable.builtin "self"))
|
||||||
|
|
||||||
|
;; Constants
|
||||||
|
|
||||||
|
((identifier) @constant
|
||||||
|
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
|
||||||
|
(vararg_expression) @constant
|
||||||
|
|
||||||
|
(nil) @constant.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
(false)
|
||||||
|
(true)
|
||||||
|
] @boolean
|
||||||
|
|
||||||
|
;; Tables
|
||||||
|
|
||||||
|
(field name: (identifier) @field)
|
||||||
|
|
||||||
|
(dot_index_expression field: (identifier) @field)
|
||||||
|
|
||||||
|
(table_constructor
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @constructor)
|
||||||
|
|
||||||
|
;; Functions
|
||||||
|
|
||||||
|
(parameters (identifier) @parameter)
|
||||||
|
|
||||||
|
(function_call name: (identifier) @function.call)
|
||||||
|
(function_declaration name: (identifier) @function)
|
||||||
|
|
||||||
|
(function_call name: (dot_index_expression field: (identifier) @function.call))
|
||||||
|
(function_declaration name: (dot_index_expression field: (identifier) @function))
|
||||||
|
|
||||||
|
(method_index_expression method: (identifier) @method)
|
||||||
|
|
||||||
|
(function_call
|
||||||
|
(identifier) @function.builtin
|
||||||
|
(#any-of? @function.builtin
|
||||||
|
;; built-in functions in Lua 5.1
|
||||||
|
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
|
||||||
|
"load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
|
||||||
|
"rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
|
||||||
|
"tonumber" "tostring" "type" "unpack" "xpcall"))
|
||||||
|
|
||||||
|
;; Others
|
||||||
|
|
||||||
|
(comment) @comment
|
||||||
|
|
||||||
|
(hash_bang_line) @comment
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
;; Error
|
||||||
|
(ERROR) @error
|
22
runtime/queries/lua/injections.scm
Normal file
22
runtime/queries/lua/injections.scm
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
((function_call
|
||||||
|
name: [
|
||||||
|
(identifier) @_cdef_identifier
|
||||||
|
(_ _ (identifier) @_cdef_identifier)
|
||||||
|
]
|
||||||
|
arguments: (arguments (string content: _ @c)))
|
||||||
|
(#eq? @_cdef_identifier "cdef"))
|
||||||
|
|
||||||
|
((function_call
|
||||||
|
name: (_) @_vimcmd_identifier
|
||||||
|
arguments: (arguments (string content: _ @vim)))
|
||||||
|
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_cmd"))
|
||||||
|
|
||||||
|
; ((function_call
|
||||||
|
; name: (_) @_vimcmd_identifier
|
||||||
|
; arguments: (arguments (string content: _ @query) .))
|
||||||
|
; (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query"))
|
||||||
|
|
||||||
|
; ;; highlight string as query if starts with `;; query`
|
||||||
|
; ((string ("string_content") @query) (#lua-match? @query "^%s*;+%s?query"))
|
||||||
|
|
||||||
|
; (comment) @comment
|
245
runtime/queries/vim/highlights.scm
Normal file
245
runtime/queries/vim/highlights.scm
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
(identifier) @variable
|
||||||
|
((identifier) @constant
|
||||||
|
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
|
||||||
|
;; Keywords
|
||||||
|
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"else"
|
||||||
|
"elseif"
|
||||||
|
"endif"
|
||||||
|
] @conditional
|
||||||
|
|
||||||
|
[
|
||||||
|
"try"
|
||||||
|
"catch"
|
||||||
|
"finally"
|
||||||
|
"endtry"
|
||||||
|
"throw"
|
||||||
|
] @exception
|
||||||
|
|
||||||
|
[
|
||||||
|
"for"
|
||||||
|
"endfor"
|
||||||
|
"in"
|
||||||
|
"while"
|
||||||
|
"endwhile"
|
||||||
|
"break"
|
||||||
|
"continue"
|
||||||
|
] @repeat
|
||||||
|
|
||||||
|
[
|
||||||
|
"function"
|
||||||
|
"endfunction"
|
||||||
|
] @keyword.function
|
||||||
|
|
||||||
|
;; Function related
|
||||||
|
(function_declaration name: (_) @function)
|
||||||
|
(call_expression function: (identifier) @function)
|
||||||
|
(parameters (identifier) @parameter)
|
||||||
|
(default_parameter (identifier) @parameter)
|
||||||
|
|
||||||
|
[ (bang) (spread) (at) ] @punctuation.special
|
||||||
|
|
||||||
|
[ (no_option) (inv_option) (default_option) (option_name) ] @variable.builtin
|
||||||
|
[
|
||||||
|
(scope)
|
||||||
|
"a:"
|
||||||
|
"$"
|
||||||
|
] @namespace
|
||||||
|
|
||||||
|
;; Commands and user defined commands
|
||||||
|
|
||||||
|
[
|
||||||
|
"let"
|
||||||
|
"unlet"
|
||||||
|
"const"
|
||||||
|
"call"
|
||||||
|
"execute"
|
||||||
|
"normal"
|
||||||
|
"set"
|
||||||
|
"setlocal"
|
||||||
|
"silent"
|
||||||
|
"echo"
|
||||||
|
"echomsg"
|
||||||
|
"autocmd"
|
||||||
|
"augroup"
|
||||||
|
"return"
|
||||||
|
"syntax"
|
||||||
|
"lua"
|
||||||
|
"ruby"
|
||||||
|
"perl"
|
||||||
|
"python"
|
||||||
|
"highlight"
|
||||||
|
"command"
|
||||||
|
"delcommand"
|
||||||
|
"comclear"
|
||||||
|
"colorscheme"
|
||||||
|
"startinsert"
|
||||||
|
"stopinsert"
|
||||||
|
"global"
|
||||||
|
"runtime"
|
||||||
|
"wincmd"
|
||||||
|
"cnext"
|
||||||
|
"cprevious"
|
||||||
|
"cNext"
|
||||||
|
"vertical"
|
||||||
|
"leftabove"
|
||||||
|
"aboveleft"
|
||||||
|
"rightbelow"
|
||||||
|
"belowright"
|
||||||
|
"topleft"
|
||||||
|
"botright"
|
||||||
|
(unknown_command_name)
|
||||||
|
] @keyword
|
||||||
|
(map_statement cmd: _ @keyword)
|
||||||
|
(command_name) @function.macro
|
||||||
|
|
||||||
|
;; Syntax command
|
||||||
|
|
||||||
|
(syntax_statement (keyword) @string)
|
||||||
|
(syntax_statement [
|
||||||
|
"enable"
|
||||||
|
"on"
|
||||||
|
"off"
|
||||||
|
"reset"
|
||||||
|
"case"
|
||||||
|
"spell"
|
||||||
|
"foldlevel"
|
||||||
|
"iskeyword"
|
||||||
|
"keyword"
|
||||||
|
"match"
|
||||||
|
"cluster"
|
||||||
|
"region"
|
||||||
|
] @keyword)
|
||||||
|
|
||||||
|
(syntax_argument name: _ @keyword)
|
||||||
|
|
||||||
|
[
|
||||||
|
"<buffer>"
|
||||||
|
"<nowait>"
|
||||||
|
"<silent>"
|
||||||
|
"<script>"
|
||||||
|
"<expr>"
|
||||||
|
"<unique>"
|
||||||
|
] @constant.builtin
|
||||||
|
|
||||||
|
(hl_attribute
|
||||||
|
key: _ @property
|
||||||
|
val: _ @constant)
|
||||||
|
|
||||||
|
(hl_group) @variable
|
||||||
|
(augroup_name) @namespace
|
||||||
|
|
||||||
|
(au_event) @constant
|
||||||
|
(normal_statement (commands) @constant)
|
||||||
|
|
||||||
|
;; Highlight command
|
||||||
|
|
||||||
|
(highlight_statement [
|
||||||
|
"default"
|
||||||
|
"link"
|
||||||
|
"clear"
|
||||||
|
] @keyword)
|
||||||
|
|
||||||
|
;; Command command
|
||||||
|
|
||||||
|
(command_attribute
|
||||||
|
name: _ @property
|
||||||
|
val: (behavior
|
||||||
|
name: _ @constant
|
||||||
|
val: (identifier)? @function)?)
|
||||||
|
|
||||||
|
;; Runtime command
|
||||||
|
|
||||||
|
(runtime_statement (where) @keyword.operator)
|
||||||
|
|
||||||
|
;; Colorscheme command
|
||||||
|
|
||||||
|
(colorscheme_statement (name) @string)
|
||||||
|
|
||||||
|
;; Literals
|
||||||
|
|
||||||
|
(string_literal) @string
|
||||||
|
(integer_literal) @number
|
||||||
|
(float_literal) @float
|
||||||
|
(comment) @comment
|
||||||
|
(pattern) @string.special
|
||||||
|
(pattern_multi) @string.regex
|
||||||
|
(filename) @string
|
||||||
|
(heredoc (body) @string)
|
||||||
|
((heredoc (parameter) @keyword))
|
||||||
|
((scoped_identifier
|
||||||
|
(scope) @_scope . (identifier) @boolean)
|
||||||
|
(#eq? @_scope "v:")
|
||||||
|
(#any-of? @boolean "true" "false"))
|
||||||
|
|
||||||
|
;; Operators
|
||||||
|
|
||||||
|
[
|
||||||
|
"||"
|
||||||
|
"&&"
|
||||||
|
"&"
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"%"
|
||||||
|
".."
|
||||||
|
"is"
|
||||||
|
"isnot"
|
||||||
|
"=="
|
||||||
|
"!="
|
||||||
|
">"
|
||||||
|
">="
|
||||||
|
"<"
|
||||||
|
"<="
|
||||||
|
"=~"
|
||||||
|
"!~"
|
||||||
|
"="
|
||||||
|
"+="
|
||||||
|
"-="
|
||||||
|
"*="
|
||||||
|
"/="
|
||||||
|
"%="
|
||||||
|
".="
|
||||||
|
"..="
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
; Some characters have different meanings based on the context
|
||||||
|
(unary_operation "!" @operator)
|
||||||
|
(binary_operation "." @operator)
|
||||||
|
|
||||||
|
;; Punctuation
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
(field_expression "." @punctuation.delimiter)
|
||||||
|
|
||||||
|
[
|
||||||
|
","
|
||||||
|
":"
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
(ternary_expression ["?" ":"] @conditional)
|
||||||
|
|
||||||
|
; Options
|
||||||
|
((set_value) @number
|
||||||
|
(#match? @number "^[0-9]+(\.[0-9]+)?$"))
|
||||||
|
|
||||||
|
((set_item
|
||||||
|
option: (option_name) @_option
|
||||||
|
value: (set_value) @function)
|
||||||
|
(#any-of? @_option
|
||||||
|
"tagfunc" "tfu"
|
||||||
|
"completefunc" "cfu"
|
||||||
|
"omnifunc" "ofu"
|
||||||
|
"operatorfunc" "opfunc"))
|
26
runtime/queries/vim/injections.scm
Normal file
26
runtime/queries/vim/injections.scm
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
(lua_statement (script (body) @lua))
|
||||||
|
(lua_statement (chunk) @lua)
|
||||||
|
; (ruby_statement (script (body) @ruby))
|
||||||
|
; (ruby_statement (chunk) @ruby)
|
||||||
|
; (python_statement (script (body) @python))
|
||||||
|
; (python_statement (chunk) @python)
|
||||||
|
;; (perl_statement (script (body) @perl))
|
||||||
|
;; (perl_statement (chunk) @perl)
|
||||||
|
|
||||||
|
; (autocmd_statement (pattern) @regex)
|
||||||
|
|
||||||
|
((set_item
|
||||||
|
option: (option_name) @_option
|
||||||
|
value: (set_value) @vim)
|
||||||
|
(#any-of? @_option
|
||||||
|
"includeexpr" "inex"
|
||||||
|
"printexpr" "pexpr"
|
||||||
|
"formatexpr" "fex"
|
||||||
|
"indentexpr" "inde"
|
||||||
|
"foldtext" "fdt"
|
||||||
|
"foldexpr" "fde"
|
||||||
|
"diffexpr" "dex"
|
||||||
|
"patchexpr" "pex"
|
||||||
|
"charconvert" "ccv"))
|
||||||
|
|
||||||
|
; (comment) @comment
|
@@ -27,13 +27,13 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Set up the connection between FileType and Syntax autocommands.
|
" Set up the connection between FileType and Syntax autocommands.
|
||||||
" This makes the syntax automatically set when the file type is detected.
|
" This makes the syntax automatically set when the file type is detected
|
||||||
|
" unless treesitter highlighting is enabled.
|
||||||
" Avoid an error when 'verbose' is set and <amatch> expansion fails.
|
" Avoid an error when 'verbose' is set and <amatch> expansion fails.
|
||||||
augroup syntaxset
|
augroup syntaxset
|
||||||
au! FileType * 0verbose exe "set syntax=" . expand("<amatch>")
|
au! FileType * if !exists('b:ts_highlight') | 0verbose exe "set syntax=" . expand("<amatch>") | endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
|
||||||
" Execute the syntax autocommands for the each buffer.
|
" Execute the syntax autocommands for the each buffer.
|
||||||
" If the filetype wasn't detected yet, do that now.
|
" If the filetype wasn't detected yet, do that now.
|
||||||
" Always do the syntaxset autocommands, for buffers where the 'filetype'
|
" Always do the syntaxset autocommands, for buffers where the 'filetype'
|
||||||
|
@@ -186,7 +186,6 @@ static const char *highlight_init_both[] = {
|
|||||||
"default link DiagnosticSignInfo DiagnosticInfo",
|
"default link DiagnosticSignInfo DiagnosticInfo",
|
||||||
"default link DiagnosticSignHint DiagnosticHint",
|
"default link DiagnosticSignHint DiagnosticHint",
|
||||||
|
|
||||||
"default link @error Error",
|
|
||||||
"default link @text.underline Underlined",
|
"default link @text.underline Underlined",
|
||||||
"default link @todo Todo",
|
"default link @todo Todo",
|
||||||
"default link @debug Debug",
|
"default link @debug Debug",
|
||||||
|
@@ -755,16 +755,6 @@ function module.pending_win32(pending_fn)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.pending_c_parser(pending_fn)
|
|
||||||
local status, _ = unpack(module.exec_lua([[ return {pcall(vim.treesitter.require_language, 'c')} ]]))
|
|
||||||
if not status then
|
|
||||||
pending_fn 'no C parser, skipping'
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
module.exec_lua [[vim._ts_remove_language 'c']]
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Calls pending() and returns `true` if the system is too slow to
|
-- Calls pending() and returns `true` if the system is too slow to
|
||||||
-- run fragile or expensive tests. Else returns `false`.
|
-- run fragile or expensive tests. Else returns `false`.
|
||||||
function module.skip_fragile(pending_fn, cond)
|
function module.skip_fragile(pending_fn, cond)
|
||||||
|
@@ -5,7 +5,6 @@ local clear = helpers.clear
|
|||||||
local insert = helpers.insert
|
local insert = helpers.insert
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
local pending_c_parser = helpers.pending_c_parser
|
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
@@ -107,12 +106,11 @@ describe('treesitter highlighting', function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
exec_lua([[ hl_query = ... ]], hl_query)
|
exec_lua([[ hl_query = ... ]], hl_query)
|
||||||
|
command [[ hi link @error ErrorMsg ]]
|
||||||
command [[ hi link @warning WarningMsg ]]
|
command [[ hi link @warning WarningMsg ]]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('is updated with edits', function()
|
it('is updated with edits', function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert(hl_text)
|
insert(hl_text)
|
||||||
screen:expect{grid=[[
|
screen:expect{grid=[[
|
||||||
/// Schedule Lua callback on main loop's event queue |
|
/// Schedule Lua callback on main loop's event queue |
|
||||||
@@ -276,8 +274,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('is updated with :sort', function()
|
it('is updated with :sort', function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert(test_text)
|
insert(test_text)
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
local parser = vim.treesitter.get_parser(0, "c")
|
local parser = vim.treesitter.get_parser(0, "c")
|
||||||
@@ -351,8 +347,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("supports with custom parser", function()
|
it("supports with custom parser", function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
screen:set_default_attr_ids {
|
screen:set_default_attr_ids {
|
||||||
[1] = {bold = true, foreground = Screen.colors.SeaGreen4};
|
[1] = {bold = true, foreground = Screen.colors.SeaGreen4};
|
||||||
}
|
}
|
||||||
@@ -417,8 +411,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("supports injected languages", function()
|
it("supports injected languages", function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert([[
|
insert([[
|
||||||
int x = INT_MAX;
|
int x = INT_MAX;
|
||||||
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
||||||
@@ -479,8 +471,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("supports overriding queries, like ", function()
|
it("supports overriding queries, like ", function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert([[
|
insert([[
|
||||||
int x = INT_MAX;
|
int x = INT_MAX;
|
||||||
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
||||||
@@ -520,8 +510,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("supports highlighting with custom highlight groups", function()
|
it("supports highlighting with custom highlight groups", function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert(hl_text)
|
insert(hl_text)
|
||||||
|
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
@@ -577,8 +565,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("supports highlighting with priority", function()
|
it("supports highlighting with priority", function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert([[
|
insert([[
|
||||||
int x = INT_MAX;
|
int x = INT_MAX;
|
||||||
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
|
||||||
@@ -594,9 +580,9 @@ describe('treesitter highlighting', function()
|
|||||||
-- expect everything to have Error highlight
|
-- expect everything to have Error highlight
|
||||||
screen:expect{grid=[[
|
screen:expect{grid=[[
|
||||||
{12:int}{8: x = INT_MAX;} |
|
{12:int}{8: x = INT_MAX;} |
|
||||||
{8:#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))}|
|
{8:#define READ_STRING(x, y) (}{12:char_u}{8: *)read_string((x), (}{12:size_t}{8:)(y))}|
|
||||||
{8:#define foo void main() { \} |
|
{8:#define foo }{12:void}{8: main() { \} |
|
||||||
{8: return 42; \} |
|
{8: }{12:return}{8: 42; \} |
|
||||||
{8: }} |
|
{8: }} |
|
||||||
^ |
|
^ |
|
||||||
{1:~ }|
|
{1:~ }|
|
||||||
@@ -625,8 +611,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("allows to use captures with dots (don't use fallback when specialization of foo exists)", function()
|
it("allows to use captures with dots (don't use fallback when specialization of foo exists)", function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert([[
|
insert([[
|
||||||
char* x = "Will somebody ever read this?";
|
char* x = "Will somebody ever read this?";
|
||||||
]])
|
]])
|
||||||
@@ -708,7 +692,6 @@ describe('treesitter highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("supports conceal attribute", function()
|
it("supports conceal attribute", function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
insert(hl_text)
|
insert(hl_text)
|
||||||
|
|
||||||
-- conceal can be empty or a single cchar.
|
-- conceal can be empty or a single cchar.
|
||||||
|
@@ -6,7 +6,6 @@ local command = helpers.command
|
|||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local pcall_err = helpers.pcall_err
|
local pcall_err = helpers.pcall_err
|
||||||
local matches = helpers.matches
|
local matches = helpers.matches
|
||||||
local pending_c_parser = helpers.pending_c_parser
|
|
||||||
local insert = helpers.insert
|
local insert = helpers.insert
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
@@ -28,15 +27,11 @@ describe('treesitter language API', function()
|
|||||||
eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers",
|
eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers",
|
||||||
pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')"))
|
pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')"))
|
||||||
|
|
||||||
if not pending_c_parser(pending) then
|
matches("Error executing lua: Failed to load parser: uv_dlsym: .+",
|
||||||
matches("Error executing lua: Failed to load parser: uv_dlsym: .+",
|
pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")'))
|
||||||
pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")'))
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('inspects language', function()
|
it('inspects language', function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
local keys, fields, symbols = unpack(exec_lua([[
|
local keys, fields, symbols = unpack(exec_lua([[
|
||||||
local lang = vim.treesitter.inspect_language('c')
|
local lang = vim.treesitter.inspect_language('c')
|
||||||
local keys, symbols = {}, {}
|
local keys, symbols = {}, {}
|
||||||
@@ -76,7 +71,6 @@ describe('treesitter language API', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('checks if vim.treesitter.get_parser tries to create a new parser on filetype change', function ()
|
it('checks if vim.treesitter.get_parser tries to create a new parser on filetype change', function ()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
command("set filetype=c")
|
command("set filetype=c")
|
||||||
-- Should not throw an error when filetype is c
|
-- Should not throw an error when filetype is c
|
||||||
eq('c', exec_lua("return vim.treesitter.get_parser(0):lang()"))
|
eq('c', exec_lua("return vim.treesitter.get_parser(0):lang()"))
|
||||||
@@ -87,7 +81,6 @@ describe('treesitter language API', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('retrieve the tree given a range', function ()
|
it('retrieve the tree given a range', function ()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
insert([[
|
insert([[
|
||||||
int main() {
|
int main() {
|
||||||
int x = 3;
|
int x = 3;
|
||||||
@@ -102,7 +95,6 @@ describe('treesitter language API', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('retrieve the node given a range', function ()
|
it('retrieve the node given a range', function ()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
insert([[
|
insert([[
|
||||||
int main() {
|
int main() {
|
||||||
int x = 3;
|
int x = 3;
|
||||||
|
@@ -4,7 +4,6 @@ local clear = helpers.clear
|
|||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local insert = helpers.insert
|
local insert = helpers.insert
|
||||||
local pending_c_parser = helpers.pending_c_parser
|
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@@ -15,10 +14,6 @@ end
|
|||||||
describe('treesitter node API', function()
|
describe('treesitter node API', function()
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
if pending_c_parser(pending) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
it('can move between siblings', function()
|
it('can move between siblings', function()
|
||||||
insert([[
|
insert([[
|
||||||
int main(int x, int y, int z) {
|
int main(int x, int y, int z) {
|
||||||
|
@@ -5,13 +5,11 @@ local eq = helpers.eq
|
|||||||
local insert = helpers.insert
|
local insert = helpers.insert
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
local pending_c_parser = helpers.pending_c_parser
|
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
describe('treesitter parser API', function()
|
describe('treesitter parser API', function()
|
||||||
clear()
|
clear()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
it('parses buffer', function()
|
it('parses buffer', function()
|
||||||
if helpers.pending_win32(pending) then return end
|
if helpers.pending_win32(pending) then return end
|
||||||
@@ -249,7 +247,6 @@ void ui_refresh(void)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('supports getting text of multiline node', function()
|
it('supports getting text of multiline node', function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
insert(test_text)
|
insert(test_text)
|
||||||
local res = exec_lua([[
|
local res = exec_lua([[
|
||||||
local parser = vim.treesitter.get_parser(0, "c")
|
local parser = vim.treesitter.get_parser(0, "c")
|
||||||
|
@@ -4,7 +4,6 @@ local clear = helpers.clear
|
|||||||
local insert = helpers.insert
|
local insert = helpers.insert
|
||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
local exec_lua = helpers.exec_lua
|
local exec_lua = helpers.exec_lua
|
||||||
local pending_c_parser = helpers.pending_c_parser
|
|
||||||
|
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
@@ -12,7 +11,6 @@ describe('treesitter utils', function()
|
|||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
it('can find an ancestor', function()
|
it('can find an ancestor', function()
|
||||||
if pending_c_parser(pending) then return end
|
|
||||||
|
|
||||||
insert([[
|
insert([[
|
||||||
int main() {
|
int main() {
|
||||||
|
Reference in New Issue
Block a user