@@ -29,56 +29,79 @@ if not ok then
2929 os.exit (1 )
3030end
3131
32- print (' Installation completed, searching for compiled parsers...' )
33-
34- -- In treesitter main branch, parsers might be in different locations
35- local search_paths = {
36- vim .fn .stdpath (' cache' ) .. ' /nvim-treesitter' ,
37- vim .fn .stdpath (' data' ) .. ' /nvim-treesitter' ,
38- vim .fn .stdpath (' state' ) .. ' /nvim-treesitter' ,
39- install_dir ,
40- ' ~/.local/share/nvim/site' ,
41- ' ~/.cache/nvim/nvim-treesitter' ,
32+ print (' Installation completed, searching for go parser...' )
33+
34+ -- Check the build directory specifically for go parser
35+ local build_locations = {
36+ vim .fn .stdpath (' cache' ) .. ' /nvim-treesitter/tree-sitter-go' ,
37+ vim .fn .stdpath (' data' ) .. ' /nvim-treesitter/tree-sitter-go' ,
38+ install_dir .. ' /parser' ,
39+ ' /tmp/tree-sitter-go' ,
4240}
4341
44- -- Search recursively for .so files
45- for _ , base_path in ipairs (search_paths ) do
46- local expanded = vim .fn .expand (base_path )
42+ local go_parser_found = false
43+
44+ for _ , location in ipairs (build_locations ) do
45+ local expanded = vim .fn .expand (location )
46+ print (' Checking: ' .. expanded )
4747 if vim .fn .isdirectory (expanded ) == 1 then
48- print (' Searching in: ' .. expanded )
49- local so_files = vim .fn .glob (expanded .. ' /**/*.so' , false , true )
50- if # so_files > 0 then
51- print (' Found .so files: ' .. vim .inspect (so_files ))
52- -- Copy all .so files to install_dir/parser
53- for _ , so_file in ipairs (so_files ) do
54- local filename = vim .fn .fnamemodify (so_file , ' :t' )
55- local dest = install_dir .. ' /parser/' .. filename
56- print (' Copying ' .. so_file .. ' to ' .. dest )
48+ print (' Directory exists, listing contents:' )
49+ local files = vim .fn .glob (expanded .. ' /*' , false , true )
50+ for _ , file in ipairs (files ) do
51+ print (' ' .. file )
52+ end
53+
54+ -- Look for go.so specifically
55+ local go_so = vim .fn .glob (expanded .. ' /**/go.so' , false , true )
56+ if # go_so > 0 then
57+ print (' Found go.so: ' .. vim .inspect (go_so ))
58+ for _ , so_file in ipairs (go_so ) do
59+ local dest = install_dir .. ' /parser/go.so'
60+ print (' Copying ' .. so_file .. ' to ' .. dest )
5761 vim .fn .system (string.format (' cp "%s" "%s"' , so_file , dest ))
62+ go_parser_found = true
5863 end
5964 end
6065 end
6166end
6267
63- -- Also look for queries
64- local queries_found = false
65- for _ , base_path in ipairs (search_paths ) do
66- local expanded = vim .fn .expand (base_path )
67- local queries_path = expanded .. ' /queries/go'
68- if vim .fn .isdirectory (queries_path ) == 1 then
69- print (' Found queries in: ' .. queries_path )
70- vim .fn .system (string.format (' cp -r "%s" "%s/"' , queries_path , install_dir .. ' /queries' ))
71- queries_found = true
72- break
68+ -- If not found, search everywhere
69+ if not go_parser_found then
70+ print (' \n Searching entire filesystem for go.so...' )
71+ local search_roots = {
72+ vim .fn .stdpath (' cache' ),
73+ vim .fn .stdpath (' data' ),
74+ vim .fn .stdpath (' state' ),
75+ ' /tmp' ,
76+ }
77+
78+ for _ , root in ipairs (search_roots ) do
79+ local go_files = vim .fn .glob (root .. ' /**/go.so' , false , true )
80+ if # go_files > 0 then
81+ print (' Found go.so files: ' .. vim .inspect (go_files ))
82+ for _ , so_file in ipairs (go_files ) do
83+ local dest = install_dir .. ' /parser/go.so'
84+ print (' Copying ' .. so_file .. ' to ' .. dest )
85+ vim .fn .system (string.format (' cp "%s" "%s"' , so_file , dest ))
86+ go_parser_found = true
87+ end
88+ break
89+ end
7390 end
7491end
7592
76- -- If queries not found, copy from nvim-treesitter source
77- if not queries_found then
78- print (' Copying queries from nvim-treesitter source...' )
79- local ts_queries = vim .fn .expand (' ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter/queries/go' )
93+ -- Copy queries from nvim-treesitter source
94+ print (' \n Copying queries...' )
95+ local ts_queries_paths = {
96+ vim .fn .expand (' ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter/queries/go' ),
97+ ' ../nvim-treesitter/queries/go' ,
98+ }
99+
100+ for _ , ts_queries in ipairs (ts_queries_paths ) do
80101 if vim .fn .isdirectory (ts_queries ) == 1 then
102+ print (' Copying queries from: ' .. ts_queries )
81103 vim .fn .system (string.format (' cp -r "%s" "%s/"' , ts_queries , install_dir .. ' /queries' ))
104+ break
82105 end
83106end
84107
@@ -90,8 +113,13 @@ local queries_dir = install_dir .. '/queries/go'
90113if vim .fn .isdirectory (parser_dir ) == 1 then
91114 local files = vim .fn .readdir (parser_dir )
92115 print (' Parser files: ' .. vim .inspect (files ))
93- if # files == 0 then
94- print (' ERROR: No parser files found!' )
116+
117+ -- Check specifically for go.so
118+ local go_so_exists = vim .fn .filereadable (parser_dir .. ' /go.so' ) == 1
119+ print (' go.so exists: ' .. tostring (go_so_exists ))
120+
121+ if not go_so_exists then
122+ print (' ERROR: go.so not found!' )
95123 os.exit (1 )
96124 end
97125else
@@ -103,17 +131,8 @@ if vim.fn.isdirectory(queries_dir) == 1 then
103131 local files = vim .fn .readdir (queries_dir )
104132 print (' Query files: ' .. vim .inspect (files ))
105133else
106- print (' WARNING: Queries directory does not exist!' )
107- end
108-
109- -- Try to load the parser
110- for _ , parser in ipairs (parsers ) do
111- local ok , lang = pcall (vim .treesitter .language .add , parser )
112- if ok then
113- print (" ✓ Parser " .. parser .. " language added" )
114- else
115- print (" ✗ Parser " .. parser .. " language failed: " .. tostring (lang ))
116- end
134+ print (' ERROR: Queries directory does not exist!' )
135+ os.exit (1 )
117136end
118137
119138print (' Parser installation complete!' )
0 commit comments