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

Can I run :LspInstallServer with no interaction? #654

Open
Itto1992 opened this issue Jan 27, 2023 · 4 comments
Open

Can I run :LspInstallServer with no interaction? #654

Itto1992 opened this issue Jan 27, 2023 · 4 comments

Comments

@Itto1992
Copy link

Thank you for creating this nice repo!
I use this repo every my vim-environment.

I am creating a docker environment for neovim.
And I want to install some servers in the Dockerfile like below.

RUN nvim tmp.py -c 'LspInstallServer' -c 'qa!'

However, :LspInstallServer requires a confirmation before installation, which blocks the installation.
This phenomenon cannot be solved by declaring ENV DEBIAN_FRONTEND noninteractive.

If there is any solution to run installation command without interaction, could you tell me how to do it?
Thank you in advance.

@rmartine-ias
Copy link

not perfect, but here's what I ended up with for typescript @Itto1992 :

vim -c ':LspUninstallServer typescript-language-server' -c ':qa'
vim /tmp/file.ts -S <(echo -e "LspInstallServer! \n while index(lsp_settings#installed_servers(), {'version': '', 'name': 'typescript-language-server'}) == -1 \n sleep 1 \n endwhile \n :qa")

@dbarnett
Copy link
Contributor

I wanted to do the same kind of scripted install. Still no simple recommended solution?

In my case I'm trying to install 3 (bash, markdown, yaml), and the interactive prompting isn't so bad but trying to get it to block until ALL the installs are finished seems like it's going to be a pain. @rmartine-ias it looks like that waiting for completion is the part your workaround is for?

@rmartine-ias
Copy link

@dbarnett yep, it wakes up every second to check if it's done.
This would do it for you probably (works on my machine):

#!/usr/bin/env bash

vim -c ':LspUninstallServer bash-language-server' -c ':qa'
vim /tmp/file.sh -S <(echo -e "LspInstallServer! \n while index(lsp_settings#installed_servers(), {'version': '', 'name': 'bash-language-server'}) == -1 \n sleep 1 \n endwhile \n :qa")

vim -c ':LspUninstallServer marksman' -c ':qa'
vim /tmp/file.md -S <(echo -e "LspInstallServer! \n while index(lsp_settings#installed_servers(), {'version': '', 'name': 'marksman'}) == -1 \n sleep 1 \n endwhile \n :qa")

vim -c ':LspUninstallServer yaml-language-server' -c ':qa'
vim /tmp/file.yaml -S <(echo -e "LspInstallServer! \n while index(lsp_settings#installed_servers(), {'version': '', 'name': 'yaml-language-server'}) == -1 \n sleep 1 \n endwhile \n :qa")

@dbarnett
Copy link
Contributor

FYI I used a variation on this using timer_start() instead of :sleep, because it was bugging me having the UI frozen during the install.

I defined a function in my vimrc:

" Helper for installing servers programmatically
func LspInstallServerThenQuit(name) abort
  let s:lsp_server_installing = a:name
  execute 'LspInstallServer!' a:name
  call timer_start(500, funcref('s:QuitIfLspServerInstalled'), { 'repeat': 100 })
endfunc

func s:QuitIfLspServerInstalled(...) abort
  for l:s in lsp_settings#installed_servers()
    if l:s.name ==# s:lsp_server_installing | qa | endif
  endfor
endfunc

then called it from cli:

$ vim +'set ft=sh' +'augroup lsp_auto_enable | autocmd!' +'call LspInstallServerThenQuit("bash-language-server")'

Without the lsp_auto_enable thing I kept getting some weird error like

Error detected while processing VimEnter Autocommands for "*"..function lsp#enable[22]..<SNR>167_register_events[20]..<SNR>167_on_text_document_did_open[12]..<SNR>167_ensure_flush[1]..lsp#utils#step#start[1]..<SNR>197_next[9]..<lambda>29[1]..<SNR>167_ensure_start[54]..lsp#client#start[28]..<SNR>198_lsp_start[12]..lsp#utils#job#start[1]..<SNR>199_job_start:
line   75:
E474: Invalid argument

that kept blocking the commands from finishing.

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

No branches or pull requests

3 participants