nvim-treesitter / nvim-treesitter/nvim-treesitter-context
feat: Lua API to get the status of treesitter context
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Janet
- Stars
- 3.2k
- Forks
- 241
- PR merge metrics
- No merged PRs in 30d
Description
Currently, there's no Lua API for knowing whether the plugin is enabled. I have to get the upvalue for tsc.toggle to query this.
-- Get up value for {func}'s {name} variable.
---@generic T
---@param func fun(...):T
---@param name string
---@return unknown?
---@nodiscard
function M.get_upvalue(func, name)
local i = 1
while true do
local n, v = debug.getupvalue(func, i)
if n == nil then
return nil
end
if n == name then
return v
end
i = i + 1
end
end
local function toggle_context()
local util = require("util")
local tsc = require("treesitter-context")
tsc.toggle()
if util.get_upvalue(tsc.toggle, "enabled") then
util.log.info("Enabled treesitter context", "Option")
else
util.log.warn("Disabled treesitter context", "Option")
end
end
Having a function like tsc.status() would be really helpful.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the public tsc.toggle entry point and the enabled upvalue shown in the issue. Trace how that state is maintained and expose a status query consistent with the requested tsc.status API. Done means callers can determine whether the plugin is enabled without inspecting an upvalue; verify both enabled and disabled states.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- api
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100