Skip to content

Commit

Permalink
Really remove dependency on nvim-treesitter
Browse files Browse the repository at this point in the history
  • Loading branch information
theHamsta committed Dec 28, 2023
1 parent d630b9b commit 018e93e
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lua/nvim-dap-virtual-text/virtual_text.lua
Expand Up @@ -9,7 +9,6 @@ local M = {}

local api = vim.api

local require_ok, parsers = pcall(require, 'nvim-treesitter.parsers')
local ts = vim.treesitter
local tsq = ts.query

Expand Down Expand Up @@ -80,29 +79,36 @@ function M.set_virtual_text(stackframe, options, clear)
if not stackframe.scopes then
return
end
if not require_ok then
return
end
if not stackframe.source then
return
end
if not stackframe.source.path then
return
end
local buf = vim.uri_to_bufnr(vim.uri_from_fname(stackframe.source.path))
local lang = parsers.get_buf_lang(buf)

if not parsers.has_parser(lang) or not get_query(lang, 'locals') then
return
local parser
local lang
if vim.treesitter.get_parser and vim.treesitter.language and vim.treesitter.language.get_lang then
lang = vim.treesitter.language.get_lang(vim.bo[buf].ft)
parser = vim.treesitter.get_parser(buf)
else
local require_ok, parsers = pcall(require, 'nvim-treesitter.parsers')
if not require_ok then
return
end
lang = parsers.get_buf_lang(buf)
parser = parsers.get_parser(buf, lang)
end

local scope_nodes = {}
local definition_nodes = {}

local parser = vim.treesitter.get_parser(buf)
if not parser then
return
end
parser:parse()
parser:for_each_tree(function(tree, _)
local query = get_query(lang, 'locals')
parser:for_each_tree(function(tree, ltree)
local query = get_query(ltree:lang(), 'locals')
if query then
for _, match, _ in query:iter_matches(tree:root(), buf, 0, -1) do
for id, node in pairs(match) do
Expand Down

0 comments on commit 018e93e

Please sign in to comment.