@@ -18,20 +18,51 @@ vim.cmd("set rtp+=" .. runtime_path)
1818require (" luasnip" ).setup ()
1919require (" luasnip.extras.fmt" )
2020require (" luasnip.nodes.absolute_indexer" )
21+ require (" nvim-treesitter.locals" )
22+ require (" nvim-treesitter" ).setup ()
2123require (" mini.test" ).setup ()
2224require (" mini.doc" ).setup ()
25+ require (" nvim-treesitter.configs" ).setup ({
26+ modules = {
27+ " highlight" ,
28+ },
29+ sync_install = false ,
30+ auto_install = true ,
31+ ignore_install = {},
32+ ensure_installed = {},
33+ highlight = {
34+ enable = true ,
35+ },
36+ })
2337
24- -- Setup nvim-treesitter
25- require (" nvim-treesitter" ).install (" python" )
38+ -- Clean path for use in a prefix comparison
39+ --- @param input string
40+ --- @return string
41+ local function clean_path (input )
42+ local pth = vim .fn .fnamemodify (input , " :p" )
43+ if vim .fn .has (" win32" ) == 1 then
44+ pth = pth :gsub (" /" , " \\ " )
45+ end
46+ return pth
47+ end
2648
27- vim .api .nvim_create_autocmd (" FileType" , {
28- group = vim .api .nvim_create_augroup (" PythonTreesitter" , { clear = true }),
29- pattern = " python" ,
30- desc = " Enable treesitter highlighting and indentation" ,
31- callback = function (event )
32- local buf = event .buf
49+ local function ts_is_installed (lang )
50+ local matched_parsers = vim .api .nvim_get_runtime_file (" parser/" .. lang .. " .so" , true ) or {}
51+ local configs = require (" nvim-treesitter.configs" )
52+ local install_dir = configs .get_parser_install_dir ()
53+ if not install_dir then
54+ return false
55+ end
56+ install_dir = clean_path (install_dir )
57+ for _ , path in ipairs (matched_parsers ) do
58+ local abspath = clean_path (path )
59+ if vim .startswith (abspath , install_dir ) then
60+ return true
61+ end
62+ end
63+ return false
64+ end
3365
34- -- Start highlighting
35- pcall (vim .treesitter .start , buf , " python" )
36- end ,
37- })
66+ if not ts_is_installed (" python" ) then
67+ vim .cmd (" TSInstallSync python" )
68+ end
0 commit comments