Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: example treesitter ensure_installed gets called twice which leads to install errors #628

Closed
3 tasks done
qwertzui11 opened this issue Apr 19, 2023 · 10 comments · Fixed by #630
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@qwertzui11
Copy link

Did you check docs and existing issues?

  • I have read all the LazyVim docs
  • I have searched the existing issues of LazyVim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.0 stable release

Operating system/version

Ubuntu 20.04 / OpenSuse Tumbleweed

Describe the bug

I'm trying to add languages to the Treesetter plugin according to the tutoral and plugins/example.lua, which leads to errors when installing them.

Steps To Reproduce

  1. set up a clean lazyvim environment
#/usr/bin/env bash
set -e
nvim --version
export NVIM_APPNAME="lazyvim-issue"
git clone 'https://github.com/LazyVim/starter' "${HOME}/.config/${NVIM_APPNAME}"

Note, the error occurs without NVIM_APPNAME too.

  1. change the ${HOME}/.config/${NVIM_APPNAME}/lua/plugins/example.lua so it starts with
if true then
  return {
    {
      "nvim-treesitter/nvim-treesitter",
      opts = function(_, opts)
        -- add tsx and treesitter
        vim.list_extend(opts.ensure_installed, {
          "tsx",
          "typescript",
        })
      end,
    },
  }
end

Note this code is taken from the plugins/example.lua.

  1. Now open nvim
export NVIM_APPNAME="lazyvim-issue"
nvim
  1. Open a file, to trigger the Treesitter installation

Everything will install just fine BUT it will bring you "dirty" errors looking like this

Error  02:01:15 PM msg_show.emsg nvim-treesitter[tsx]: Could not create tree-sitter-tsx-tmp
02:01:15 PM msg_show mkdir: cannot create directory ‘tree-sitter-tsx-tmp’: File exists

My research found that this happens because of

function(_, opts)
        -- add tsx and treesitter
        vim.list_extend(opts.ensure_installed, {
          "tsx",
          "typescript",
        })
      end

is getting called TWICE! Due to that, ensure_installed contains "tsx" and "typescript" TWICE! which leads to a parallel installation and error of "tsx"and"typescript"`.

A solution could be ensuring that every entry is unique, or to ensure the function is getting called only once.

Expected Behavior

No errors.

Thanks a lot for your time! I'm having a blast with this starter kit. I really love these defaults and clean keymaps! 😍

Repro

No response

@qwertzui11 qwertzui11 added the bug Something isn't working label Apr 19, 2023
@dpetka2001
Copy link
Contributor

I'm not sure why you need the if true then clause at the beginning of your spec. Just return the spec without it.

@qwertzui11
Copy link
Author

Thx for your respone!

I'm not sure why you need the if true then clause at the beginning of your spec. Just return the spec without it.

I added the if true then because I said

change the ${HOME}/.config/${NVIM_APPNAME}/lua/plugins/example.lua so it starts with [...]

If you don't prepend the file with that code, but replace the whole content, you can lose the if true then. However, this does not change the outcome.

@dpetka2001
Copy link
Contributor

  1. git clone https://github.com/LazyVim/starter ~/.config/lazyTest
  2. NVIM_APPNAME=lazyTest nvim
  3. Nvim installs all necessary plugins
  4. Create file test.lua in ~/.config/lazyTest/lua/plugins/ directory with following contents
return {
  {
    "nvim-treesitter/nvim-treesitter",
    opts = function(_, opts)
      -- add tsx and treesitter
      vim.list_extend(opts.ensure_installed, {
        "tsx",
        "typescript",
      })
    end,
  },
}
  1. Close Neovim and open again with NVIM_APPNAME=lazyTest nvim. tsx and typescript get installed as can be seen in :TSInstallInfo with no errors whatsoever.
    I don't know what you did wrong but I don't get any errors with this procedure which is simulating the steps you took.

@qwertzui11
Copy link
Author

qwertzui11 commented Apr 19, 2023

To ensure it's not somehow my system I re-created the issue in a docker:

  1. Create a Dockerfile with the content
FROM ubuntu:22.04

RUN apt-get update \
  && apt-get install -y \
    curl \
    git \
    ninja-build \
    g++ \
    gettext \
    cmake \
    unzip \
    curl

# https://github.com/neovim/neovim/wiki/Installing-Neovim#appimage-universal-linux-package
RUN curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage \
  && chmod u+x nvim.appimage \
  && ./nvim.appimage --appimage-extract \
  && ln -s /squashfs-root/AppRun /usr/bin/nvim

RUN mkdir -p /root/.config \
  && git clone https://github.com/LazyVim/starter /root/.config/nvim

COPY test.lua /root/.config/nvim/lua/plugins/
  1. next to the Dockerfile create a test.lua with the content
return {
  {
    "nvim-treesitter/nvim-treesitter",
    opts = function(_, opts)
      -- add tsx and treesitter
      vim.list_extend(opts.ensure_installed, {
        "tsx",
        "typescript",
      })
    end,
  },
}
  1. run the following
docker build -t lazyvim-issue . && docker run --rm -it lazyvim-issue
  1. in that container start nvim. this should install all plugins, with a minor issue (LuaSnip - let's ignore that one)
  2. close nvim using :q
  3. restart nvim with nvim /root/.bashrc

You should see a lot of errors.

Aside from the container, I'm able to produce it on two different linux systems (Ubuntu 20.04 and OpenSuse tumbleweed) on different hardware.

Can you can confirm it now? 😱

@qwertzui11
Copy link
Author

here is a screen capture of the issue https://calip.io/MxW6AeUZ#CYYVeBS4

I added g++ to the Dockerfile to get a cleaner issue

@dpetka2001
Copy link
Contributor

No i can't confirm it. As i did it there were no errors. I use neovim latest nightly build and i don't know what version the latest appimage is. Maybe an issue with Neovim version? I don't know what to tell you since i did not encounter the errors you're talking about.

@folke folke closed this as completed in 1d2c97c Apr 19, 2023
@folke
Copy link
Collaborator

folke commented Apr 19, 2023

Should be fixed now. I didn't have this issue since I just override the whole list

@dpetka2001
Copy link
Contributor

@folke Just out of curiosity I don't override the whole list myself, rather I vim.list_extend to ensure_installed table whatever I want. Why did this not happen to me? In my second post I also created a new instance of Neovim from the starter template seperate from the one I already have using the new NVIM_APPNAME variable to distinguish between the 2 and just extended the treesitter options again and did not encounter the problem either.

@folke
Copy link
Collaborator

folke commented Apr 19, 2023

No idea. I also didn't have this problem when testing regular LazyVim.
I think the problem doesn't always happen and should honestly also just be fixed in nvim-treesitter if that can indeed cause issues.

@qwertzui11
Copy link
Author

Tested. Works well. Thx for the fast responses and fix! 😍

I think the problem doesn't always happen and should honestly also just be fixed in nvim-treesitter if that can indeed cause issues.

I hear you. I tried to forward the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants