Skip to content

fix: remove nvim-treesitter dependency#15

Merged
qvalentin merged 1 commit intoqvalentin:mainfrom
koppchen:fix-remove-nvim-treesitter-dep
Sep 11, 2025
Merged

fix: remove nvim-treesitter dependency#15
qvalentin merged 1 commit intoqvalentin:mainfrom
koppchen:fix-remove-nvim-treesitter-dep

Conversation

@koppchen
Copy link
Copy Markdown
Contributor

@koppchen koppchen commented Sep 1, 2025

Fixes #14

Remove the nvim-treesitter dependency, so this doesn't error when the nvim-treesitter main branch is used. The has_parser() function has been removed in the newer nvim-treesitter main branch, so this fixes errors related to that change.

NOTE:

  • vim.treesitter.language.add() requires nvim 0.9+ (first released in April 2023)
  • Tested with both the nvim-treesitter master & main branches
  • Tested with nvim v0.11.4

Summary by CodeRabbit

  • Bug Fixes

    • Prevents errors by enabling features only when the Helm Tree‑sitter language is available.
    • Shows a clear warning if Helm support isn’t installed and skips related autocommands.
  • Refactor

    • Streamlined initialization with a single language availability check for more reliable startup behavior.

Remove the nvim-treesitter dependency. The has_parser() function has
been removed in the newer nvim-treesitter main branch, so this fixes
errors related to that.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 1, 2025

Walkthrough

Replaces the Treesitter parser existence check using nvim-treesitter parsers/has_parser with a direct availability check via vim.treesitter.language.add("helm"), returning early with a warning if unavailable. Retains existing setup steps: optional conceal/indent-hints loading, autocmd group creation, patterns, and CursorMoved/CursorMovedI updates.

Changes

Cohort / File(s) Summary
Treesitter availability check update
lua/helm-ls.lua
Replaced pcall(require("nvim-treesitter.parsers")) and has_parser("helm") with vim.treesitter.language.add("helm") to validate Helm parser availability; added early return with warning on false; preserved subsequent setup logic (conceal/indent-hints, augroup, autocmds).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User as User
  participant Neovim as Neovim
  participant Plugin as helm-ls.nvim
  participant TS as vim.treesitter.language

  User->>Neovim: Open Helm file
  Neovim->>Plugin: Setup()
  Plugin->>TS: add("helm")
  alt Language available
    TS-->>Plugin: true
    Plugin->>Plugin: Load conceal/indent-hints (if enabled)
    Plugin->>Neovim: Create augroup + autocmds (CursorMoved/Insert)
  else Language missing
    TS-->>Plugin: false
    Plugin->>Neovim: Warn "parser for helm not installed"
    Plugin-->>Neovim: Return early (no autocmds)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Replace deprecated Treesitter check causing "has_parser nil" error with supported API [#14]
Show warning and avoid error when Helm parser is not installed; no setup side effects [#14]

Possibly related PRs

Poem

I tap my paw on YAML seas,
"helm" I squeak, among the trees—
If parser sprouts, we hop along,
If not, a warning is my song.
With cursors moved and hints in sight,
I ship this chart by moonlit night. 🐇⛵️

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
lua/helm-ls.lua (2)

54-60: Guard for Neovim < 0.9 and surface the load error.

On older Neovim, vim.treesitter.language.add is absent and this will throw. Also, capturing the second return value lets you show why loading failed. (neovim.io)

Apply:

-  if not vim.treesitter.language.add("helm") then
-    vim.notify(
-      "Helm-ls.nvim: tree-sitter parser for helm not installed, some features will not work. Make sure you have nvim-treesitter and then install it with :TSInstall helm",
-      vim.log.levels.WARN
-    )
-    return
-  end
+  -- Neovim 0.9+ provides vim.treesitter.language.add()
+  local has_add = vim.treesitter and vim.treesitter.language and type(vim.treesitter.language.add) == "function"
+  if not has_add then
+    vim.notify("Helm-ls.nvim: Neovim >= 0.9 required for Tree-sitter features (missing vim.treesitter.language.add()).", vim.log.levels.WARN)
+    return
+  end
+  local ok, err = vim.treesitter.language.add("helm")
+  if not ok then
+    vim.notify(
+      ("Helm-ls.nvim: Helm Tree-sitter parser not found; features will be disabled. Install a Helm parser (e.g., via nvim-treesitter: :TSInstall helm) or place parser/helm.* on 'runtimepath'.%s")
+        :format(err and ("\nDetails: " .. err) or ""),
+      vim.log.levels.WARN
+    )
+    return
+  end

54-60: Option: don’t hard-return; let features auto-activate after on-the-fly :TSInstall.

If you omit the return on missing parser and instead short-circuit in the callback, users who install the parser during the session won’t need to reload Neovim.

Outside the selected range, inside the autocmd callback (around Line 71), add a one-time per-buffer guard:

if vim.bo.filetype ~= "helm" then return end
if not vim.b._helm_ls_has_parser then
  local ok = vim.treesitter and vim.treesitter.language and vim.treesitter.language.add and vim.treesitter.language.add("helm")
  if not ok then return end
  vim.b._helm_ls_has_parser = true
end
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6485095 and 8fda11e.

📒 Files selected for processing (1)
  • lua/helm-ls.lua (1 hunks)
🔇 Additional comments (1)
lua/helm-ls.lua (1)

54-60: Good swap to the built-in Treesitter check.

Using vim.treesitter.language.add("helm") removes the hard dependency on nvim-treesitter.parsers and is the documented way to check/load a parser before enabling features. Looks correct. (neovim.io)

@qvalentin qvalentin merged commit f95af41 into qvalentin:main Sep 11, 2025
4 checks passed
@qvalentin
Copy link
Copy Markdown
Owner

Thanks for the fix and the detailed description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: "attempt to call field 'has_parser' (a nil value)" when using nvim-treesitter main branch

2 participants