fix(#52): lazy setup tree-sitter related features#55
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts Neopyter’s initialization flow to lazily set up tree-sitter-dependent functionality, aiming to avoid doing parser/query setup until a matching buffer is opened.
Changes:
- Delay tree-sitter parser/query setup (and highlight/textobject/injection setup) until the first matching
BufReadPost. - Expand
:checkhealth neopytertree-sitter reporting to include query setup status. - Update the repro example to explicitly load/configure
nvim-treesitterbefore Neopyter.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lua/neopyter.lua | Moves tree-sitter-related setup behind a new delay_setup() invoked on first matching buffer read. |
| lua/neopyter/health.lua | Updates health messages and adds checks for whether Neopyter tree-sitter queries are set up. |
| example/repro.lua | Adjusts Lazy.nvim repro spec to ensure nvim-treesitter is loaded/configured ahead of Neopyter. |
| example/main.ju.py | Minor example output text change. |
| function neopyter.delay_setup() | ||
| if neopyter.delay_setuped then | ||
| return | ||
| end | ||
| neopyter.load_parser() | ||
| highlight.setup() | ||
| textobject.setup() | ||
| injection.setup() | ||
| neopyter.delay_setuped = true | ||
| end |
There was a problem hiding this comment.
neopyter.delay_setup() is now exported as part of the module API (it’s a non-local function on the returned table). If this is intended to be internal-only, mark it ---@nodoc and/or make it local to avoid committing to it as a supported public API surface.
| priority = 1001, -- make sure `nvim-treesitter` is loaded before `neopyter` | ||
| lazy = false, | ||
| config = function() | ||
| require('nvim-treesitter.configs').setup { |
There was a problem hiding this comment.
This file uses Stylua with quote_style = "AutoPreferDouble", but the new require('nvim-treesitter.configs') line introduces single quotes. Switch to double quotes to match the repo’s formatting settings and avoid unnecessary churn when running Stylua.
| require('nvim-treesitter.configs').setup { | |
| require("nvim-treesitter.configs").setup { |
| if neopyter.parser[lang] then | ||
| health.ok(string.format("tree-sitter query: %s is set up", lang)) | ||
| else | ||
| health.warn(string.format("tree-sitter query: %s is not set up; please setup neopyter after loading tree-sitter's parser", lang)) |
There was a problem hiding this comment.
neopyter.parser is now initialized in delay_setup(), so it can be nil when users run :checkhealth neopyter before opening a matching buffer. Accessing neopyter.parser[lang] will then throw an error. Guard against neopyter.parser == nil (or call neopyter.delay_setup() before this check) so checkhealth never crashes.
88938ce to
d13c399
Compare
No description provided.