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

Error launching MATLAB on Neovim #33

Open
MiuKaShi opened this issue Dec 8, 2023 · 16 comments
Open

Error launching MATLAB on Neovim #33

MiuKaShi opened this issue Dec 8, 2023 · 16 comments
Labels
bug Something isn't working

Comments

@MiuKaShi
Copy link

MiuKaShi commented Dec 8, 2023

System: ArchLinux

Editor: nvim with matlab_ls

Matlab version: R2023b

Matlab-language-server version: 1.1.7

Problem:

fail to launch matlab

(18:50:03) matlabls: Log Directory: /tmp/matlabls_10926
(18:50:03) matlabls: Launching MATLAB...
(18:50:03) matlabls - ERROR: Error launching MATLAB: spawn matlab ENOENT
(18:50:03) matlabls - ERROR: Error launching MATLAB: Error
(18:50:03) matlabls - ERROR: Error launching MATLAB: Error: spawn matlab ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
(18:50:03) matlabls: MATLAB process terminated

Works fine 2 months ago, but failed after updating Matlab-language-server

@MiuKaShi MiuKaShi added the bug Something isn't working label Dec 8, 2023
@byfarm
Copy link

byfarm commented Dec 8, 2023

I am getting a similar error

(08:12:50) matlabls: Launching MATLAB...
(08:12:50) matlabls - ERROR: Error launching MATLAB: spawn matlab ENOENT
(08:12:50) matlabls - ERROR: Error launching MATLAB: Error
(08:12:50) matlabls - ERROR: Error launching MATLAB: Error: spawn matlab ENOENT\n    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)\n    at onErrorNT (node:internal/child_process:478:16)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)
(08:12:50) matlabls: MATLAB process terminated
[DEBUG][2023-12-08 08:12:50] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  jsonrpc = "2.0",  method = "matlab/connection/update/server",  params = {    connectionStatus = "disconnected"  }}

I am using matlab version R2023a
I am running WSL2 with Ubuntu
Editor: Neovim with matlab_ls
`

@dklilley dklilley changed the title Error launching MATLAB Error launching MATLAB on Neovim Dec 13, 2023
@rkmiec
Copy link

rkmiec commented Jan 3, 2024

Can you try to open terminal inside of your nvim session (enter :terminal in neovim) and then execute matlab -nodisplay?
Are you using mason.nvim for LSP configuration or lspconfig directly?
Could you paste relevant configuration part of your neovim config?

@byfarm
Copy link

byfarm commented Jan 5, 2024

Thank you so much!!!!
The problem was that I am using MATLAB in WSL, so I had matlab installed on windows, but not on wsl. I downloaded and installed the Linux version of matlab on wsl, and it worked! I had to change my installation path to the one bellow.

' installPath = "/usr/local/MATLAB/R2023a",'

Thank you!

@MiuKaShi
Copy link
Author

MiuKaShi commented Jan 6, 2024

I can

Can you try to open terminal inside of your nvim session (enter :terminal in neovim) and then execute matlab -nodisplay? Are you using mason.nvim for LSP configuration or lspconfig directly? Could you paste relevant configuration part of your neovim config?

I can successfully run matlab -nodisplay in neovim terminal.

I configured lsp directly with the following configuration

  require("lspconfig").matlab_ls.setup {
    on_attach = on_attach,
    capabilities = capabilities,
    cmd = { "matlab_ls", "--stdio" },
    filetypes = { "matlab" },
    single_file_support = true,
    settings = {
      matlab = {
        indexWorkspace = false,
        installPath = "/home/miuka/.local/MATLAB/R2024a",
        matlabConnectionTiming = "onStart",
        telemetry = true,
      },
    },
  }

for matlab_ls is a bash shell

exec node "/home/miuka/github/MATLAB-language-server/out/index.js" "$@"

I tried to switch to the nvim-nightly version, but it still doesn't work and get

(18:43:51) matlabls - ERROR: Error launching MATLAB: Error
(18:43:51) matlabls - ERROR: Error launching MATLAB: Error: spawn matlab ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
(18:43:51) matlabls: MATLAB process terminated

@rkmiec
Copy link

rkmiec commented Jan 23, 2024

I tried to switch to the nvim-nightly version, but it still doesn't work and get

(18:43:51) matlabls - ERROR: Error launching MATLAB: Error
(18:43:51) matlabls - ERROR: Error launching MATLAB: Error: spawn matlab ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
(18:43:51) matlabls: MATLAB process terminated

I have tried to reproduce your issue on my system (native Linux), but I couldn't.
My setup was very similar to yours.
I have intentionally skipped a few steps or messed up my config but every time I get a different error.

Could you start with a clean repo once again? This is what I'm doing to have this language server working:

git clean -fdX
git pull --rebase
npm install webpack
npm run-script vscode:prepublish

@MiuKaShi
Copy link
Author

MiuKaShi commented Jan 25, 2024

git clean -fdX
git pull --rebase
npm install webpack
npm run-script vscode:prepublish

I have try above and even clone a clean master source, but it still failed and get same error.
I also try Helix, almost same config it work on helix, but switch to neovim get error.
How about node version, my current node version is V21.6.1.

@rkmiec
Copy link

rkmiec commented Jan 27, 2024

I'm using the same node version and npm 10.2.4. Which Matlab version are you running? Currently, I'm on R2022b.

@MiuKaShi
Copy link
Author

MiuKaShi commented Jan 30, 2024

I'm using the same node version and npm 10.2.4. Which Matlab version are you running? Currently, I'm on R2022b.

I switched the npm version to 10.2.4 and tested matlab R2022b R2023b R2024a, and neovim-nightly version, but they all failed!
I even tested other people's nvim configurations on github , but also got the same error as before.

@a1gituser
Copy link

a1gituser commented Feb 15, 2024

Hello,

I"m using neovim nightly v0.9.5 via WSL 2 on Arch Linux. I have gone through most of the issues above, but have been able to resolve most by installing Matlab locally in the Linux WSL. I can see from the logs that the server goes up, and it connects to it after I open a matlab file. The issue I have is that a few seconds later I get a message that the client quit:

image

and the lsp.log file contains a very large output, but the top of the error there is

[ERROR][2024-02-15 11:31:46] .../vim/lsp/rpc.lua:734 "rpc" "/home/rln/.local/share/nvim/mason/bin/matlab-language-server" "stderr" '),function(e){e.fromPlainText=function(e){return e.replace(/[\\`*_{}\ --- output truncated

:LspInfo looks healthy enough for me
image

I should add I tested Matlab R2021b and R2023b. Both have the same behavior.

Any suggestions on how to do next to fix this?

thanks!

@a1gituser
Copy link

a1gituser commented Mar 12, 2024

Hello,

I"m using neovim nightly v0.9.5 via WSL 2 on Arch Linux. I have gone through most of the issues above, but have been able to resolve most by installing Matlab locally in the Linux WSL. I can see from the logs that the server goes up, and it connects to it after I open a matlab file. The issue I have is that a few seconds later I get a message that the client quit:

image

and the lsp.log file contains a very large output, but the top of the error there is

[ERROR][2024-02-15 11:31:46] .../vim/lsp/rpc.lua:734 "rpc" "/home/rln/.local/share/nvim/mason/bin/matlab-language-server" "stderr" '),function(e){e.fromPlainText=function(e){return e.replace(/[\`*_{}\ --- output truncated

:LspInfo looks healthy enough for me image

I should add I tested Matlab R2021b and R2023b. Both have the same behavior.

Any suggestions on how to do next to fix this?

thanks!

I was able to get this going on my side by using mason-lspconfig, installing matlab locally on my wsl linux install, and executing neovim disabling the proxies (I'm using a corporate laptop) using the alias mvim='(unset http_proxy && unset https_proxy && nvim)'

my config (using lazyvim) looks like this. This could probably be cleaner, but this is working for me. I'm no expert on this, unfortunately, but just posting what I did that got things going for me. I also installed matlab_ls via Mason manually, but could've probably added it to the config below.

    {
        "neovim/nvim-lspconfig",
        dependencies = {
            "williamboman/mason.nvim",
            "williamboman/mason-lspconfig.nvim",
            "hrsh7th/cmp-nvim-lsp",
            "hrsh7th/cmp-buffer",
            "hrsh7th/cmp-path",
            "hrsh7th/cmp-cmdline",
            "hrsh7th/nvim-cmp",
            "L3MON4D3/LuaSnip",
            "saadparwaiz1/cmp_luasnip",
            "j-hui/fidget.nvim",
        },

        config = function()
            local cmp = require('cmp')
            local cmp_lsp = require("cmp_nvim_lsp")
            local capabilities = vim.tbl_deep_extend(
            "force",
            {},
            vim.lsp.protocol.make_client_capabilities(),
            cmp_lsp.default_capabilities())

            require("fidget").setup({})
            require("mason").setup()
            require("mason-lspconfig").setup({
                ensure_installed = {
                    "lua_ls",
                    "rust_analyzer",
                    "clangd",
                    --"tsserver",
                    --"codelldb",
                    --"jedi-language-server",
                    --"pyright",
                },
                handlers = {
                    function(server_name) -- default handler (optional)

                        require("lspconfig")[server_name].setup {
                            capabilities = capabilities
                        }
                    end,

                    ["lua_ls"] = function()
                        local lspconfig = require("lspconfig")
                        lspconfig.lua_ls.setup {
                            capabilities = capabilities,
                            settings = {
                                Lua = {
                                    diagnostics = {
                                        globals = { "vim", "it", "describe", "before_each", "after_each" },
                                    }
                                }
                            }
                        }
                    end,
                }
            })

            local cmp_select = { behavior = cmp.SelectBehavior.Select }

            cmp.setup({
                snippet = {
                    expand = function(args)
                        require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
                    end,
                },
                mapping = cmp.mapping.preset.insert({
                    ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
                    ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
                    ['<Tab>'] = cmp.mapping.confirm({ select = true }),
                    ["<C-Space>"] = cmp.mapping.complete(),
                }),
                sources = cmp.config.sources({
                    { name = 'nvim_lsp' },
                    { name = 'luasnip' }, -- For luasnip users.
                }, {
                    { name = 'buffer' },
                })
            })

            vim.diagnostic.config({
                -- update_in_insert = true,
                float = {
                    focusable = false,
                    style = "minimal",
                    border = "rounded",
                    source = "always",
                    header = "",
                    prefix = "",
                },
            })
        end
    },

@Budali11
Copy link

I encountered this error too.
my environment:

  1. matlab R2023a student version installed.
  2. nvim version v0.11.0
    image
  3. nvim plugins:
    mason.nvim
    mason-lspconfig.nvim
    neovim/nvim-lspconfig
    hrsh7th/cmp-nvim-lsp
    hrsh7th/cmp-buffer
    hrsh7th/cmp-path
    hrsh7th/cmp-cmdline
    hrsh7th/nvim-cmp

my error:
image

my procedure to solve:

  1. MATLAB may should be correctly installed and licensed.
  2. use mason to install matlab-language-server
  3. setup nvim-lspconfig(but this seems no effect, because when i modify the settings such as "require(...).matlab_ls..." to "require(...)matlab_s...", matlab_ls is still attach to language server and work properly)
    image
  4. comment the mason.nvim and mason-lspconfig.nvim in .config/nvim/lua/plugins.lua, namely unload these two plugins, and then the matlab_ls works.

it sounds weird but it really works for me.

diningPhilosopher64 pushed a commit to diningPhilosopher64/MATLAB-language-server that referenced this issue Jul 2, 2024
@MiuKaShi
Copy link
Author

@Budali11 Thank you for your sharing.
After several tests I probably know what the problem is, it seems that the installPath setting just doesn't work.
I have matlab installed under $HOME/.local/Matalb/R2024a, and despite setting installPath, it still didn't work.
After adding matlab to my system path, lsp worked.
Here is my config file hope it helps someone with the same problem.

  1. create script named 'matlab' and add to system path
#!/bin/bash
matlab="$HOME/.local/MATLAB/R2024a/bin/matlab"
$matlab "$@"
  1. create script named 'matlab_ls' and add to system path
#!/bin/bash
exec /usr/bin/node "$HOME/github/MATLAB-language-server/out/index.js" "$@"
  1. configure matlab_ls.setup
M.setup = function(on_attach, capabilities)
 require("lspconfig").matlab_ls.setup {
   on_attach = on_attach,
   capabilities = capabilities,
   cmd = { "matlab_ls", "--stdio" },
   filetypes = { "matlab" },
   -- root_dir = require("lspconfig.util").root_pattern "*.m",
   root_dir = function(fname) return require("lspconfig.util").find_git_ancestor(fname) or vim.fn.getcwd() end,
   settings = {
     matlab = {
       indexWorkspace = true,
       matlabConnectionTiming = "onStart",
       telemetry = true,
     },
   },
   single_file_support = true,
   handlers = {
     ["textDocument/publishDiagnostics"] = function() end, -- disable diagnostics, null_ls handles this
   },
 }
end

@yassiezar
Copy link

@MiuKaShi It seems you're right and the installPath setting is ignored for some reason. The LSP started up perfectly after I added a symlink to MATLAB R2024a (installed under my /home/ dir) to /usr/local/bin

@dklilley
Copy link
Member

Can you try launching the desired MATLAB normally, run the matlabroot command, and confirm that this value is exactly the same as what you had the installPath to?

If these do match and still does not work, can you share the value?

@yassiezar
Copy link

Hey @dklilley, I did as you asked and opened my R2024a installation, ran matlabroot and got the exact same output as my installPath setting (/home/jlock/MATLAB/R2024a). My NVim LSP config below for reference:

require('mason-lspconfig').setup({
  ensure_installed = {
    'rust_analyzer',
    'clangd',
    'pylsp',
    'texlab',
    'lua_ls',
    'matlab_ls',
  },
  handlers = {
    lsp.default_setup,
    matlab_ls = function()
      require('lspconfig').matlab_ls.setup({
        capabilities = require('cmp_nvim_lsp').default_capabilities(),
        settings = {
          matlab = {
            installPath = '/home/jlock/MATLAB/R2024a',
          },
        },
        root_dir = function(fname)
          return require('lspconfig.util').find_git_ancestor(fname)
        end,
        single_file_support = true,
      })
    end,
    lua_ls = function()
      require('lspconfig').lua_ls.setup({
        settings = {
          Lua = {
            diagnostics = {
              -- Get the language server to recognize the `vim` global
              globals = { 'vim' }
            }
          }
        }
      })
    end,
    pylsp = function()
      require('lspconfig').pylsp.setup({})
    end
  },
})

@dklilley
Copy link
Member

The installPath should work, but I'm not very familiar with the Neovim setup.

@tiagovla , do you have any ideas on this?

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

No branches or pull requests

7 participants