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

Using with neovim's built in LSP #53

Open
physicophilic opened this issue May 28, 2021 · 6 comments
Open

Using with neovim's built in LSP #53

physicophilic opened this issue May 28, 2021 · 6 comments

Comments

@physicophilic
Copy link

Hi.

I am trying to configure neovim's built in LSP for this server. I have been able to get neovim to detect the language server, but it is crashing on launch.

I am getting the same error as in #36, but this is happening even when I am running the language server inside of neovim.

The neovim log shows same thing as commnad line:

Expand
[ ERROR ] 2021-05-28T14:12:39+0530 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]	"rpc"	"wolfram"	"stderr"	"[INFO  2021-05-28T14:12:39] Initializing Wolfram Language Server\n"
[ ERROR ] 2021-05-28T14:12:40+0530 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]	"rpc"	"wolfram"	"stderr"	"[INFO  2021-05-28T14:12:40] Language server is connecting the client through\nsocket.\n"
[ ERROR ] 2021-05-28T14:12:40+0530 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]	"rpc"	"wolfram"	"stderr"	"\n"
[ ERROR ] 2021-05-28T14:12:40+0530 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]	"rpc"	"wolfram"	"stderr"	"SocketConnect::zmqexception: \n   A ZeroMQLink exception was thrown - Connection refused (code 111)\n"
[ ERROR ] 2021-05-28T14:12:40+0530 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:457 ]	"rpc"	"wolfram"	"stderr"	"[ERROR 2021-05-28T14:12:40] Cannot connect to client via socket.\n"

I am able to run the server from Mathematica itself using

initfile = "/path/to/lsp-wl/init.wls";
args = {};
Block[{$ScriptCommandLine = Prepend[args, initfile], Quit = Function[{}, Throw[Null]]},
    Catch[<< (initfile)]
];

Although I don't know if it will help, here's my neovim config for lsp-wl.

Expand
local lspconfig = require "lspconfig"
local configs = require "lspconfig/configs"
local util = require "lspconfig/util"

if not lspconfig.lsp_wl then
  configs.lsp_wl = {
    default_config = {
      cmd = {"wolfram", "-script", "/home/manish/lsp-wl/init.wls"},
      filetypes = {"mma", "wl"},
      root_dir = util.path.dirname,
      settings = {}
    }
  }
end

lspconfig.lsp_wl.setup {}

In #36 it was recommended to look at the vs-code client with claim that it would not run into this issue.
Should I try that out to figure out what I can do?

@kenkangxgwe
Copy link
Owner

It seems that you didn't tell neovim to start a socket connection. Maybe try adding transport in the settings (or port if lspconfig doesn't automatically assign one).

@physicophilic
Copy link
Author

Sorry, can you please explain? I am a novice.

I see from your vs code client that you require three things: wolfram path, lsp-wl/init.wls path, and the port. Looking at config file of coc-lsp-wl (from where I got the keys) and what you said I did this, which I am not sure is the thing you asked for:

local lspconfig = require "lspconfig"
local configs = require "lspconfig/configs"
local util = require "lspconfig/util"

if not lspconfig.lsp_wl then
  configs.lsp_wl = {
    default_config = {
      cmd = {"wolfram", "-script", "/home/manish/lsp-wl/init.wls"},
      filetypes = {"mma", "wl"},
      root_dir = util.path.dirname,
    -- additions
      settings = {
         lsp_wl = {
            port = 6536,
            wolframExecutablePath = "/home/manish/Software/Mathematica/Executables/wolfram",
            wolframLanguageServerPath = "/home/manish/lsp-wl/init.wls"
         }
       }
   --
    }
  }
end

lspconfig.lsp_wl.setup {}

This is giving the same error as before. I tried to add the port value in lsp_wl.setup {} as well, if that's what you meant by 'settings' but that also gives the same result.

The code above is mainly relying on cmd to do everything it appears, and because that command doesn't work from terminal, it is not working from here either.

@kenkangxgwe
Copy link
Owner

I wonder if the socket is already supported by neovim lsp, but from this issue neovim/neovim#11911, it seems not. Godot has made a workaround using nc to redirect the socket reads/writes as the example linked in that issue. In that case, you have to manually start a wolfram language server externally by wolfram -script /path/to/lsp-wl/init.wls --tcp-server=<port>, and let neovim connect to that server.

@physicophilic
Copy link
Author

Thanks, it worked once but somehow now its not working. I will check and report later !

@physicophilic
Copy link
Author

physicophilic commented Jun 4, 2021

Thank you. I checked and have got the hover and signature help working fine. The autocomplete however is not working for now.

Here's my config file:

local lspconfig = require "lspconfig"
local configs = require "lspconfig/configs"
local util = require "lspconfig/util"


if not lspconfig.lsp_wl then

  configs.lsp_wl = {
    default_config = {
      cmd = {"nc", "localhost", "6536"},
      filetypes = {"mma", "wl"},
      root_dir = util.path.dirname,
      settings = { }
    }
  }
end

which I have placed in nvim-lspconfig/lua/lspconfig/lsp_wl.lua and I do

lua require'lspconfig'.lsp_wl.setup{on_attach=require'completion'.on_attach}

in my init.vim.

In mathematica I do as you say:

  1. !wolfram -script ~/path/to/lsp-wl.wls --tcp-server=6536
  2. LspStart

to get going.

For autocomplete, I use completion-nvim.. and I tried to see why its not working.

I looked at the default bashls config for comparison (below), which looks surprisingly the same, yet completion works for it. That makes me think this is a problem with completion-nvim - I just wanted your thoughts on that. I will raise issue with the plugin in that case.

Expand
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'

local server_name = "bashls"

configs[server_name] = {
  default_config = {
    cmd = {"bash-language-server", "start"};
    cmd_env = {
      -- Prevent recursive scanning which will cause issues when opening a file
      -- directly in the home directory (e.g. ~/foo.sh).
      --
      -- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)".
      GLOB_PATTERN = vim.env.GLOB_PATTERN or "*@(.sh|.inc|.bash|.command)"
    },
    filetypes = {"sh"};
    root_dir = util.path.dirname;
  };
  docs = {
    description = [[
https://github.com/mads-hartmann/bash-language-server

Language server for bash, written using tree sitter in typescript.
]];
    default_config = {
      root_dir = "vim's starting directory";
    };
  };
};

@yqwu905
Copy link

yqwu905 commented Dec 31, 2021

I try your config with nvim-cmp, the autocomplete work fine.
For your information, here's my config for reference:

local enhance_attach = function(client,bufnr)
  api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
end

vim.notify("Config lsp_wl")
configs.lsp_wl = {
  default_config = {
    cmd = {"nc", "localhost", "6536"},
    filetypes = {"mma", "wl"},
    root_dir = util.path.dirname,
  }
}

lspconfig.lsp_wl.setup {
  on_attach = enhance_attach
}

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