kabouzeid / nvim-lspinstall

Provides the missing :LspInstall for nvim-lspconfig
MIT License
526 stars 67 forks source link

Headless install #83

Open kradalby opened 3 years ago

kradalby commented 3 years ago

Hi

Great project, I have a couple of scenarios were using this package in a headless fashion would be neat, but the confirm (Yes/Cancel) seem to break that, any tips on how I can get that working?

Example command:

nvim --headless +"LspInstall go" +qa

Also, any plans on allowing multiple servers in one go? (LspInstall go elm css)

kabouzeid commented 3 years ago

It's currently not possible to skip the confirm dialog but it sure would be nice. Now that I think about it, should we even have a confirm dialog at all? I can't remember right now why I decided to do this.

To install multiple servers at once, you can write a small lua function (see https://github.com/kabouzeid/nvim-lspinstall/issues/26#issuecomment-813345606). eg something like this:

--- install multiple language servers at once
function install_servers(servers)
  for _, server in pairs(servers) do
    require'lspinstall'.install_server(server)
  end
end

-- call it like this
install_servers({ "go", "elm", "css" })

Out of curiosity, what is your usecase for this? Sounds interesting.

petertriho commented 3 years ago

Would also love to see this but it would probably need have an autocmd for when the server install is complete in a similar way to how Packer does it (PackerComplete https://github.com/wbthomason/packer.nvim#user-autocommands)

That way you write a update script (https://github.com/petertriho/dotfiles/blob/main/scripts/.local/bin/update) like this:

nvim +"autocmd User PackerComplete sleep 100m | qall" +PackerSync
kradalby commented 3 years ago

@kabouzeid I have a similar usecase to @petertriho.

I have a CI/CD job that "builds" or packs my plugins and dotfiles so I can bring in everything to my company in one package.

Will have a look at the install script, but that also would be more useful without the confirmation :)

kabouzeid commented 3 years ago

I'll think about what the best way to approach this would be. I don't want to overcomplicate things. Ideas are welcome

kradalby commented 3 years ago

@kabouzeid How about something like #84 ?

qwelyt commented 2 years ago

I am interested in being able to do this as well. My goal is to have a docker or podman container with my IDE that I can just pull to w/e machine I'm on (and for that matter, share with others). The manual steps and not being able to do LspInstall in headless is a hurdle for this.

So I'm interested in the progress for this. I can see that https://github.com/kabouzeid/nvim-lspinstall/pull/84 was closed due to a commit in main already fixing the confirmation dialog. But how is work going with the headless bit?
So far all I get is

% nvim --headless +"LspInstall go" +qa
Error detected while processing command line:
E492: Not an editor command: LspInstall g
jrodal98 commented 2 years ago
% nvim --headless +"LspInstall go" +qa
Error detected while processing command line:
E492: Not an editor command: LspInstall g

@qwelyt I have the same goal as you and ran into the same issue. I figured out that I could add a sleep before and after the lsp install command:

nvim --headless +"sleep 5" +"LspInstall go" +"sleep 5" +qa

This is what I have in my Dockerfile:

RUN nvim --headless -c 'autocmd User PackerComplete quitall' -c 'silent PackerSync'
RUN nvim --headless +"sleep 5" +"silent TSInstall python bash" +"silent LspInstall python" +"silent LspInstall bash" +"sleep 60" +qa

and the output:

Step 5/8 : RUN nvim --headless -c 'autocmd User PackerComplete quitall' -c 'silent PackerSync'
 ---> Running in 85c732194a44
[nvim-treesitter] [0/1] Downloading...Removing intermediate container 85c732194a44
 ---> 3fd2c1c11bba
Step 6/8 : RUN nvim --headless +"sleep 5" +"silent TSInstall python bash" +"silent LspInstall python" +"silent LspInstall bash" +"sleep 60" +qa
 ---> Running in 9f6a4ac94400
[nvim-treesitter] [0/1] Downloading...
[nvim-treesitter] [0/1] Creating temporary directory
[nvim-treesitter] [0/1] Extracting...
[nvim-treesitter] [0/1] Compiling...
[nvim-treesitter] [1/1] Treesitter parser for lua has been installed
[nvim-treesitter] [0/2] Downloading...
[nvim-treesitter] [0/2] Downloading...
[nvim-treesitter] [0/2] Creating temporary directory
[nvim-treesitter] [0/2] Extracting...
[nvim-treesitter] [0/2] Compiling...
[nvim-treesitter] [0/2] Creating temporary directory
[nvim-treesitter] [0/2] Extracting...
[nvim-treesitter] [0/2] Compiling...
[nvim-lspinstall] Successfully installed language server for python
/root/.config/nvim/lua/plugins/configs/lspconfig.lua:111: Vim(edit):E32: No file name
[nvim-treesitter] [1/2] Treesitter parser for python has been installed
[nvim-treesitter] [2/2] Treesitter parser for bash has been installed
[nvim-lspinstall] Successfully installed language server for bash
/root/.config/nvim/lua/plugins/configs/lspconfig.lua:111: Vim(edit):E32: No file name function: builtin#19 /root/.config/nvim/lua/plugins/configs/lspconfig.lua:111: Vim(edit):E32: No file name

You might need to bump the sleep duration, particularly the one after the LspInstall.

Far from ideal, but it works.