nvim-treesitter icon indicating copy to clipboard operation
nvim-treesitter copied to clipboard

Error during download, when updating the plugin

Open tunaflsh opened this issue 1 year ago • 13 comments

Describe the bug

  1. I always get error during download.
  2. Then it does things and seems like the paths aren't properly escaped when it calls external commands.

Image

To Reproduce

Using lazy.nvim Start nvim :Lazy build nvim-treesitter

Expected behavior

No error.

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.24.5 (722806d5d6911b598434a2a3d2de85f393ac65d0) (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.13.1 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc.exe (Rev2, Built by MSYS2 project) 14.2.0
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "10.0.26100",
  sysname = "MINGW32_NT-10.0",
  version = "Windows 11 Home"
} ~

Parser/Features         H L F I J
  - c                   ✓ ✓ ✓ ✓ ✓
  - json                ✓ ✓ ✓ ✓ .
  - json5               ✓ . . . ✓
  - jsonc               ✓ ✓ ✓ ✓ ✓
  - latex               ✓ . ✓ . ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

Output of nvim --version

NVIM v0.10.3
Build type: Release
LuaJIT 2.1.1734355927
Run "nvim -V1 -v" for more info

Additional context

No response

tunaflsh avatar Jan 07 '25 16:01 tunaflsh

We need exact and minimal (not involving lazy!) reproduction steps.

clason avatar Jan 07 '25 16:01 clason

I'm having a hard time understanding just where the error is originated. At first I thought it was a lazy.nvim issue, but they redirected me here. The issue arises everytime the plugin updates.

What is the equivalent of updating a plugin without lazy.nvim? If it's just git pull... well that's the whole point. I don't have problems git pulling manually, but either lazy.nvim or nvim-treesitter does something on its own.

tunaflsh avatar Jan 10 '25 00:01 tunaflsh

That's exactly what the minimal config is about. Just git clone this(!) plugin and set it up in a small minimal.lua which you run with nvim --clean -u minimal.lua. If there's an issue installing parsers, that should happen regardless; if it's an issue of updating the plugin, that is out of scope here and needs to be discussed with the plugin manager. Without more information, it's impossible to say more.

clason avatar Jan 10 '25 08:01 clason

Ok. It might be an issue with the parsers. Could you tell me where tree-sitter-python directory is supposed to be downloaded after I hit :TSInstall python?

tunaflsh avatar Jan 10 '25 09:01 tunaflsh

Not without a lot more details. By default, it's stdpath('data').

clason avatar Jan 10 '25 10:01 clason

Well, either way with my default setup or the minimal setup. I never get error after :TSInstall python it is something else then.

tunaflsh avatar Jan 10 '25 10:01 tunaflsh

But my lazy.nvim settings have require('nvim-treesitter.install').update({with_sync = true})() And testing :TSInstallSync python just now yields an error.

python parser already available: would you like to reinstall ? y/n: y

/usr/bin/bash: /s: No such file or directory
Failed to execute the following command:
{
  cmd = "cmd",
  opts = {
    args = { "/C", "if", "exist", "C:\\Users\\tuna\\AppData\\Local\\nvim-data\\tree-sitter-python", "rmdir", "/s", "/q", "C:\\Users\\tuna\\AppData\\Local\\nvim-data\\tree-sitter-python" }
  }
}
Press ENTER or type command to continue

The minimal setup I have is minimal.lua:

vim.opt.packpath:append{'C:/configs/nvim'}
vim.cmd.packadd('nvim-treesitter')

With nvim-treesitter cloned into C:/configs/nvim/pack/foo/opt. :echo stdpath('data') is C:\Users\tuna\AppData\Local\nvim-data.

I think I understand the problem now. Not looking into code yet, but if the plugin runs something like system('cmd /c ... /s /q ...'), there is a problem. I'm running nvim in msys2/mingw64 environment, which uses a unix shell. And all the flags /c /s /q are interpreted as paths.

This is confirmed, after I started minimal nvim in cmd and ran :TSInstallSync python. Everything works.

I've seen plugins like VimTeX save the user shell options, load their own default options to ensure shell is cmd for windows users and restore the user options after the operations are done.

tunaflsh avatar Jan 10 '25 10:01 tunaflsh

Or you could just check if shell contains sh which means the environment is unix, and let the plugin use linux code. That should work too. I never use cmd anyway.

tunaflsh avatar Jan 10 '25 10:01 tunaflsh

Can you test https://github.com/nvim-treesitter/nvim-treesitter/pull/7497?

clason avatar Jan 10 '25 10:01 clason

I think that pull request is related to my original issue with updating the plugin.

But after cloning the branch and running :TSInstallSync python I still get /usr/bin/bash: /s: No such file or directory. /s is supposed to be a cmd flag. So this is a separate issue.

tunaflsh avatar Jan 10 '25 11:01 tunaflsh

I believe this may be the exact error I am encountering (on Windows). Here are the steps I can use to replicate the error that hopefully can lead someone to a fix...

  1. Close all terminals that have been running nvim.
  2. Open folder %localappdata%\nvim-data. You should see several folders starting with tree-sitter-
  3. Delete all the folders to get a clean slate and ensure they are not currently locked
  4. Start a terminal and run nvim
  5. Verify that tree-sitter installs the parsers correctly
  6. Close nvim, but leave the terminal running
  7. Open a new nvim in either this terminal or another
  8. Tree-sitter should throw errors when it tries to reinstall the parsers

As identified elsewhere, the issue is the folders (and maybe files in the folders) are getting locked by Windows. This isn't something we can avoid. And it appears that on every start, nvim-tree-sitter wants to recreate the parsers.

One solution I can think of, is if this is Windows:

  1. Prior to loading each parser...before the rmdir step...check if the parser folder already exists
  2. If it exists, try to rename to something like tree-sitter-javascript-test
  3. If the rename fails, skip reloading the parser as the folders are locked and there is no sense in trying to reload
  4. If the rename is successful, delete or rename the folder back and proceed with the parser load

I'd be happy to work on this, but I have no experience building plugins and would need some direction on how to start.

GPetrites avatar Feb 07 '25 15:02 GPetrites

@clason This looks like it was addressed here:

https://github.com/nvim-treesitter/nvim-treesitter/commit/124efc

That commit is in the main branch. I am using LazyVim and the default configuration isn't compatible with that branch.

GPetrites avatar Feb 08 '25 20:02 GPetrites

Yes, sorry. Patience, please, while we get all the moving parts in order for the release.

clason avatar Feb 08 '25 20:02 clason