Skip to content

Conversation

@jship
Copy link
Contributor

@jship jship commented Jan 14, 2026

pcall-ing vim.treesitter.language.add would always return true as its first result value, as add uses the style of returning nil and an error message when it can't add the language rather than aborting via error or assert. This causes an issue when a Conjure user opens a Python buffer but doesn't have a Python treesitter parser installed. Conjure thinks they do have a parser installed and tries to start the stdio client. The user would see an error from Neovim's treesitter code like vim.schedule: No parser for language "python", and not the stdio client's intended log messages for this case (reproduced below) which made it difficult to identify that the error was originating from Conjure.

(error) The python client requires a python treesitter parser in order to function.
(error) See https://github.com/nvim-treesitter/nvim-treesitter
(error) for installation instructions.

The style of return nil plus error message is a change from the now-deprecated require_language functions that Conjure's add-language also wraps for backwards-compatiblity. The pcall was previously around the add-language wrapper call in the Python stdio client's start function. These changes move the choice to pcall or not into the add-language wrapper itself. This lets add skip a pcall while the deprecated require_language functions still get a pcall.

(let [add (case vim.treesitter
{:language {:add f}} f
{:language {:require_language f}} (partial pcall f)
{:require_language f} (partial pcall f))]
Copy link
Contributor

@russtoku russtoku Jan 17, 2026

Choose a reason for hiding this comment

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

It doesn't appear that the clause on L.196 would ever match because :require_language isn't a key in vim.treesitter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It no longer exists in more current versions of Neovim, but I preserved this case since the old version of the Conjure code was falling back to it too. Here's the 2020 Neovim commit where it was introduced and here's the (also 2020) commit where it was moved from top-level vim.treesitter to be under vim.treesitter.language. For completeness' sake, here's the 2024 commit where it was renamed from require_language to add.

Copy link
Owner

Choose a reason for hiding this comment

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

Nice, I would also point out that our minimum version is v0.10 so we should try to be backwards compatible to there but if someone's on <0.10 Conjure will error anyway. I didn't look into the version numbers these changes correspond to but I'm okay with this backwards compatibility regardless, just thought I'd mention the version threshold anyway.

I also didn't know Fennel case statements could be used like this, I really like it!

@russtoku
Copy link
Contributor

Good catch!

Your changes make it clear what a user needs to do if they don't have a Tree-sitter parser for Python.

Without your changes, the user has to suffer these error messages:

  • When first editing a Python source file.
Error executing vim.schedule lua callback: ...5/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:125: No
 parser for language "python"
stack traceback:
        [builtin#19]: at 0x0104f597c4
  • When trying to evaluate a line of Python code from a buffer.
E5108: Error executing lua: Vim:Error executing Lua callback: ...5/share/nvim/runtime/lua/vim/treesitter/langu
agetree.lua:125: No parser for language "python"
stack traceback:
        [C]: in function 'assert'
        ...5/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:125: in function 'get_string_parser'
        ...lugins/start/conjure/lua/conjure/client/python/stdio.lua:76: in function 'str-is-python-expr?'
        ...lugins/start/conjure/lua/conjure/client/python/stdio.lua:86: in function 'prep_code'
        ...lugins/start/conjure/lua/conjure/client/python/stdio.lua:157: in function <...lugins/start/conjure/
lua/conjure/client/python/stdio.lua:146>
        ...vim/site/pack/plugins/start/conjure/lua/conjure/eval.lua:150: in function <...vim/site/pack/plugins
/start/conjure/lua/conjure/eval.lua:138>
        [C]: at 0x0102ad13d4
stack traceback:
        [C]: at 0x0102ad13d4

(let [add (case vim.treesitter
{:language {:add f}} f
{:language {:require_language f}} (partial pcall f)
{:require_language f} (partial pcall f))]
Copy link
Owner

Choose a reason for hiding this comment

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

Nice, I would also point out that our minimum version is v0.10 so we should try to be backwards compatible to there but if someone's on <0.10 Conjure will error anyway. I didn't look into the version numbers these changes correspond to but I'm okay with this backwards compatibility regardless, just thought I'd mention the version threshold anyway.

I also didn't know Fennel case statements could be used like this, I really like it!

@Olical Olical merged commit 85954f9 into Olical:main Jan 18, 2026
6 checks passed
@jship jship deleted the ts-python-error branch January 18, 2026 18:22
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.

3 participants