File tree 1 file changed +10
-3
lines changed 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change
1
+ local A = vim .api
2
+
1
3
--- Common commentstring shared b/w mutliple languages
2
4
local M = {
3
5
cxx_l = ' //%s' ,
82
84
--- @param ctx Ctx
83
85
--- @return string
84
86
function ft .calculate (ctx )
85
- local buf = vim .api .nvim_get_current_buf ()
86
- local langtree = vim .treesitter .get_parser (buf )
87
+ local buf = A .nvim_get_current_buf ()
88
+ local ok , langtree = pcall (vim .treesitter .get_parser , buf )
89
+ local buf_type = A .nvim_buf_get_option (buf , ' filetype' )
90
+
91
+ if not ok then
92
+ return ft .get (buf_type , ctx .ctype )
93
+ end
87
94
88
95
local range = {
89
96
ctx .range .srow - 1 ,
@@ -102,7 +109,7 @@ function ft.calculate(ctx)
102
109
end
103
110
end
104
111
105
- return found or ft .get (vim . api . nvim_buf_get_option ( buf , ' filetype ' ) , ctx .ctype )
112
+ return found or ft .get (buf_type , ctx .ctype )
106
113
end
107
114
108
115
return setmetatable (ft , {
You can’t perform that action at this time.
0 commit comments