Repository navigation
Expand file tree
/
Copy pathnvim-treesitter.lua
More file actions
108 lines (94 loc) · 2.23 KB
/
Copy pathnvim-treesitter.lua
File metadata and controls
108 lines (94 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
-- local status, treesitter = pcall(require, "nvim-treesitter.configs")
--
-- if not status then
-- vim.notify("没有找到 nvim-treesitter")
-- return
-- end
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
local config = {
-- 安装 language parser
-- :TSInstallInfo 命令查看支持的语言
ensure_installed = {
"html",
"css",
"scss",
"sql",
"solidity",
"dart",
"gitignore",
"json",
"vim",
"vue",
"tsx",
"javascript",
"typescript",
"c",
"lua",
"go",
"python",
"prisma",
"dockerfile",
"markdown",
"markdown_inline"
},
-- 启用代码高亮模块
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
incremental_selection = {
enable = true,
},
context_commentstring = {
enable = true,
enable_autocmd = false
},
-- 缩紧
indent = {
enable = true
}
}
local M = {
'nvim-treesitter/nvim-treesitter',
config = function()
local treesitter = require('nvim-treesitter.configs')
treesitter.setup(config)
-- Nvim 0.12 passes a list of nodes to each legacy query predicate.
if vim.fn.has('nvim-0.12') == 1 then
vim.treesitter.query.add_predicate('kind-eq?', function(match, _, _, pred)
local nodes = match[pred[2]]
if not nodes or #nodes == 0 then
return true
end
return vim.tbl_contains({ unpack(pred, 3) }, nodes[#nodes]:type())
end, { force = true })
end
-- nvim-treesitter's markdown injection query still uses the legacy
-- set-lang-from-info-string! directive, which breaks on Nvim 0.12.
vim.treesitter.query.set('markdown', 'injections', [[
(fenced_code_block
(info_string
(language) @injection.language)
(code_fence_content) @injection.content)
((html_block) @injection.content
(#set! injection.language "html")
(#set! injection.combined)
(#set! injection.include-children))
((minus_metadata) @injection.content
(#set! injection.language "yaml")
(#offset! @injection.content 1 0 -1 0)
(#set! injection.include-children))
((plus_metadata) @injection.content
(#set! injection.language "toml")
(#offset! @injection.content 1 0 -1 0)
(#set! injection.include-children))
([
(inline)
(pipe_table_cell)
] @injection.content
(#set! injection.language "markdown_inline"))
]])
end
}
return M