File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- -- Check if treesitter is available
2- local ok_parsers , ts_parsers = pcall (require , " nvim-treesitter.parsers" )
3- if not ok_parsers then
4- ts_parsers = nil
5- end
6-
7- local ok_utils , ts_utils = pcall (require , " nvim-treesitter.ts_utils" )
8- if not ok_utils then
9- ts_utils = nil
10- end
1+ local util = require (" luasnip.util.util" )
112
123local function from_cursor_pos ()
13- if not ts_parsers or not ts_utils then
14- return {}
15- end
16-
17- local parser = ts_parsers .get_parser ()
18- local current_node = ts_utils .get_node_at_cursor ()
4+ -- get_parser errors if parser not present (no grammar for language).
5+ local has_parser , parser = pcall (vim .treesitter .get_parser )
196
20- if current_node then
21- return { parser :language_for_range ({ current_node :range () }):lang () }
7+ if has_parser then
8+ local cursor = util .get_cursor_0ind ()
9+ -- assumption: languagetree uses 0-indexed byte-ranges.
10+ return { parser :language_for_range ({ cursor [1 ], cursor [2 ], cursor [1 ], cursor [2 ] }):lang () }
2211 else
2312 return {}
2413 end
You can’t perform that action at this time.
0 commit comments