fix(provider): Handle tree-sitter not being installed or parser not installed
This commit is contained in:
@@ -1,27 +1,34 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local parsers = require 'nvim-treesitter.parsers'
|
|
||||||
|
|
||||||
local SYMBOL_COMPONENT = 27
|
local SYMBOL_COMPONENT = 27
|
||||||
local SYMBOL_FRAGMENT = 28
|
local SYMBOL_FRAGMENT = 28
|
||||||
|
|
||||||
function M.should_use_provider(bufnr)
|
function M.should_use_provider(bufnr)
|
||||||
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft')
|
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft')
|
||||||
|
local has_ts, parsers = pcall(require, 'nvim-treesitter.parsers')
|
||||||
|
local _, has_parser = pcall(function()
|
||||||
|
if has_ts then
|
||||||
|
return parsers.get_parser(bufnr) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
return string.match(ft, 'typescriptreact')
|
return false
|
||||||
|
end)
|
||||||
|
|
||||||
|
return has_ts
|
||||||
|
and has_parser
|
||||||
|
and (
|
||||||
|
string.match(ft, 'typescriptreact')
|
||||||
or string.match(ft, 'javascriptreact')
|
or string.match(ft, 'javascriptreact')
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.hover_info(_, _, on_info)
|
function M.hover_info(_, _, on_info)
|
||||||
on_info(
|
on_info(nil, {
|
||||||
nil,
|
|
||||||
{
|
|
||||||
contents = {
|
contents = {
|
||||||
kind = 'nvim-lsp-jsx',
|
kind = 'nvim-lsp-jsx',
|
||||||
contents = { 'No extra information availaible!' },
|
contents = { 'No extra information availaible!' },
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_open_tag(node)
|
local function get_open_tag(node)
|
||||||
@@ -123,6 +130,7 @@ local function parse_ts(root, children, bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.request_symbols(on_symbols)
|
function M.request_symbols(on_symbols)
|
||||||
|
local parsers = require 'nvim-treesitter.parsers'
|
||||||
local bufnr = 0
|
local bufnr = 0
|
||||||
|
|
||||||
local parser = parsers.get_parser(bufnr)
|
local parser = parsers.get_parser(bufnr)
|
||||||
|
|||||||
Reference in New Issue
Block a user