kabouzeid/nvim-lspinstall

Unable to add graphql-language-server

akinsho opened this issue ยท 5 comments

Hey thanks for your work on this plugins ๐Ÿ‘๐Ÿฟ .

I've just tried to add in an installer for graphql using the custom installer setup instructions and hit a blocking issue.

function as_utils.lsp.add_custom_installer()
  -- npm install -g graphql-language-service-cli
  local config = require('lspconfig').graphql.document_config
  require('lspconfig.configs').graphql = {default_config = {}} --This errors if nil is set <-------------
  config.default_config.cmd[1] = "./node_modules/.bin/graphql-language-service-cli"

  require('lspinstall.servers').graphql = vim.tbl_extend('error', config, {
      install_script = [[
      ! -f package.json && npm init -y --scope=lspinstall || true
      npm install graphql-language-service-cli@latest
      ]],
      uninstall_script = nil
    })
end

I do this before calling setup of the lspinstall plugin or doing any setup of the lsp itself using lspconfig however I /packer/opt/nvim-lspconfig/lua/lspconfig/configs.lua:10: attempt to index local 'config_def' (a nil value)
Looking at the code in lspconfig it seems to have a validation and looks like expects this field to not be nil so throws errors.
I tried setting it to an empty object which silences the error but doesn't give me the option to install the server

Took me some time to debug. You need to change:
lspconfig.configs -> lspconfig/configs
lspinstall.servers -> lspinstall/servers

Don't ask me why. This could be a bug in neovim, but I'm not a lua expert.

Internally nvim-lspinstall uses require("lspinstall/servers"). When you require("lspinstall.servers") it seems to compare the literal string values of the require call. Since they don't match, the module is loaded twice. Again, I'm not sure if this is a bug or expected behavior in Lua.

@kabouzeid that's quite strange seems like an nvim bug potentially since I don't the choice of separators in a require should cause code to behave differently. Anyway that helped. It seems to work fine now. Just a couple of non blocking issues I noticed.

the -f flag in the example seems to cause an error if run from zsh so maybe somehow the shell used needs to be set explicitly to bash rather than the user's ๐Ÿคท๐Ÿฟ not sure what that flag does anyway.

Also the script can be reloaded more than once without causing errors. I use packer and automatically reload my configs on change but if the custom installer setup is called more than once it seems to throw errors about the require('lspconfig').<langserver>. that access returns nil tbh this is probably just a packer related obscure bug so feel free to ignore that one.

I'm happy to contribute the gql installer if you'd like it's not particular different from any of the other npm installers

This was a typo in the README, I fixed it now.

Replace ! -f package.json with [[ ! -f package.json ]] and also [[ with [=[ for the string literal delimiters.

This tests whether the file exists, and if not npm init -y --scope=lspinstall is executed. This works in any POSIX shell such as bash and zsh.

Not sure about the issue with packer, I'm still using Plug. If you send me a small packer config where this is happening, I can look into that.

How to add a bundled npm installer, see diagnosticls in this commit 94eb787