-
Notifications
You must be signed in to change notification settings - Fork 9
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
Neovim support #4
Comments
@tiagovla - Thanks for letting us know! It's exciting to see this being used in other IDEs! Can you open a pull request to add this new support to the README under "Clients"? |
@tiagovla - This is really great! as a new person to neovim, I tried to set it up and I got this now working on my windows machine! it took some pain but I have the functionality working (more in below) I do however like the visuals and controls that you have in your setup. It would be great if there was a blog post or introduction by experts for new folks that want to adopt neovim and develop matlab code. Please consider contributing more to this cause. My system and configuration for reference: init.vim:call plug#begin() Plug 'nvim-lua/planetary.nvim' Plug 'hrsh7th/nvim-cmp' Plug 'VonHeikemen/lsp-zero.nvim', {'branch': 'v2.x'} call plug#end() lua << EOF local lsp = require('lsp-zero').preset({}) lsp.setup() require'lspconfig'.matlab_ls.setup { EOF |
@dklilley maybe a good place to put a minimal config setup would be in the wiki section? |
@tiagovla , Thanks for the idea. we appreciate your help. if you provide such information, we can host it under the wiki so others can follow the steps to set up Neovim. |
why can't I use it? I have tried various methods for a long time, but I still can't find the reason.Please you can tell me. I use Lazyvim as configuration manager and install matlab_ls by Mason. Then here is my configuration: return {
"neovim/nvim-lspconfig",
opts = {
servers = {
-- Ensure mason installs the server
clangd = {
keys = {
{ "<leader>cR", "<cmd>ClangdSwitchSourceHeader<cr>", desc = "Switch Source/Header (C/C++)" },
},
root_dir = function(fname)
return require("lspconfig.util").find_git_ancestor(fname)
or require("lspconfig.util").root_pattern("compile_commands.json")(fname)
or require("lspconfig.util").root_pattern("Makefile")(fname)
or require("lspconfig.util").root_pattern("xmake.lua")(fname)
end,
capabilities = {
offsetEncoding = { "utf-16" },
},
cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--header-insertion=iwyu",
"--completion-style=detailed",
"--function-arg-placeholders",
"--fallback-style=llvm",
"--log=verbose",
"--all-scopes-completion",
"--query-driver=/usr/bin/g++-*",
},
init_options = {
usePlaceholders = true,
completeUnimported = true,
clangdFileStatus = true,
},
},
matlab_ls = {
cmd = { "matlab-language-server", "--stdio" },
matlab = {
indexWorkspace = true,
installPath = "/opt/matlab2021b/",
},
root_dir = function(fname)
return require("lspconfig.util").find_git_ancestor(fname)
or require("lspconfig.util").root_pattern("compile_commands.json")(fname)
or require("lspconfig.util").root_pattern("Makefile")(fname)
or require("lspconfig.util").root_pattern("xmake.lua")(fname)
end,
single_file_support = true,
},
},
setup = {
clangd = function(_, opts)
local clangd_ext_opts = require("lazyvim.util").opts("clangd_extensions.nvim")
require("clangd_extensions").setup(vim.tbl_deep_extend("force", clangd_ext_opts or {}, { server = opts }))
return true
end,
},
},
} |
@ZZT-console I am running into a very similar issue. I have configured the LSP more or less identically but it does not seem to attach to the buffer upon opening a matlab file. Biggest difference seems to be that I am using matlab2023a |
Here's a minimal config with the lazy.nvim plugin manager: -- ~/.config/$NVIM_APPNAME/init.lua
vim.lsp.set_log_level "debug"
-- Install the lazy.nvim plugin manager
vim.g.mapleader = " "
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system {
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
}
end
vim.opt.rtp:prepend(lazypath)
-- Install plugins: mason.nvim, nvim-lspconfig, nvim-cmp
require("lazy").setup {
{ "williamboman/mason.nvim", config = true },
{
"neovim/nvim-lspconfig",
dependencies = {
"hrsh7th/nvim-cmp",
},
config = function()
require("lspconfig")["matlab_ls"].setup {
capabilities = require("cmp_nvim_lsp").default_capabilities(),
settings = {
MATLAB = {
indexWorkspace = true,
installPath = "/usr/local/MATLAB/R2023a", -- might need to change this
matlabConnectionTiming = "onStart",
telemetry = true,
},
},
}
end,
},
{
"hrsh7th/nvim-cmp",
dependencies = {
{ "hrsh7th/cmp-nvim-lsp" },
{ "hrsh7th/cmp-path" }, --optional
},
opts = {
sources = {
{ name = "nvim_lsp" },
{ name = "path" }, --optional
},
},
},
}
-- Mappings
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local buffer = args.buf
vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = buffer, desc = "Hover" })
vim.keymap.set("n", "ga", vim.lsp.buf.code_action, { buffer = buffer, desc = "Code action" })
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { buffer = buffer, desc = "Go to declaration" })
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = buffer, desc = "Go to definition" })
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { buffer = buffer, desc = "Go to inplementation" })
vim.keymap.set("n", "gr", vim.lsp.buf.rename, { buffer = buffer, desc = "Rename" })
vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, { buffer = buffer, desc = "Type definition" })
vim.keymap.set("n", "gR", vim.lsp.buf.references, { buffer = buffer, desc = "References" })
vim.keymap.set("n", "gk", vim.lsp.buf.signature_help, { buffer = buffer, desc = "Signature help" })
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { buffer = buffer, desc = "Next diagnostic" })
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { buffer = buffer, desc = "Prev diagnostic" })
vim.keymap.set("n", "gf", function()
vim.lsp.buf.format {
timeout_ms = 5000,
}
end, { buffer = 0, desc = "Format buffer" })
end,
}) An example of how use it:
|
@tiagovla I tried doing this but still no luck. The LSP is not even starting as no log seems to be created at It seems like no matlab session is being launched either which vscode does do when it launches the matlab lsp. Any idea as to what might be happening? |
What's your neovim version? I'm using nightly 0.10. Check if the matlab-language-server is installed after
Check if all plugins were installed using After opening a matlab
|
@tiagovla return {
{
"neovim/nvim-lspconfig",
opts = {
servers = {
-- Ensure mason installs the server
clangd = {
root_dir = function(fname)
return require("lspconfig.util").find_git_ancestor(fname)
or require("lspconfig.util").root_pattern("compile_commands.json")(fname)
or require("lspconfig.util").root_pattern("Makefile")(fname)
or require("lspconfig.util").root_pattern("xmake.lua")(fname)
end,
cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--header-insertion=iwyu",
"--completion-style=detailed",
"--function-arg-placeholders",
"--fallback-style=llvm",
"--log=verbose",
"--all-scopes-completion",
"--query-driver=/usr/bin/g++-*",
},
},
matlab_ls = {
settings = {
matlab = {
capabilities = require("cmp_nvim_lsp").default_capabilities(),
indexWorkspace = true,
installPath = "/opt/matlab2021b/",
matlabConnectionTiming = "onStart",
telemetry = true,
},
},
-- root_dir = function(fname)
-- return require("lspconfig.util").find_git_ancestor(fname)
-- or require("lspconfig.util").root_pattern("xmake.lua")(fname)
-- or require("lspconfig.util").root_pattern("compile_commands.json")(fname)
-- or require("lspconfig.util").root_pattern("Makefile")(fname)
-- end,
single_file_support = true,
},
},
},
},
{
"hrsh7th/nvim-cmp",
dependencies = {
{ "hrsh7th/cmp-nvim-lsp" },
{ "hrsh7th/cmp-path" }, --optional
},
opts = {
sources = {
{ name = "nvim_lsp" },
{ name = "path" }, --optional
},
},
},
} The result is still the same. I try to use command:LspInfo and get this result. |
@dklilley |
@tiagovla So the issue turned out to be that my files were not contained inside a git repository, thank you very much for your help! Didn't know about this particular detail regarding lspconfig. |
Glad you found the issue! That's usually the default behavior of most servers on lspconfig https://github.com/neovim/nvim-lspconfig/blob/a27356f1ef9c11e1f459cc96a3fcac5c265e72d6/lua/lspconfig/server_configurations/matlab_ls.lua#L7 . You can also change it to detect the root on custom conditions. |
@ZZT-console, you're facing the same issue as mentioned above. Your screenshot indicates that the root directory wasn't detected. Previously, your configuration looked like this: root_dir = function(fname)
return require("lspconfig.util").find_git_ancestor(fname)
or require("lspconfig.util").root_pattern("xmake.lua")(fname)
or require("lspconfig.util").root_pattern("compile_commands.json")(fname)
or require("lspconfig.util").root_pattern("Makefile")(fname)
end, In this setup, Neovim checks if your current working directory is a Git repository, if it contains an xmake.lua file, if there's a compile_commands.json file, or if it has a Makefile. If any of these conditions are met, Neovim launches the LSP server using that root directory. This configuration is suitable for C/C++ LSP servers. The default configuration for the matlab-language-server only checks if it's inside a Git repository (as mentioned in my previous comment). To resolve your issue, you can initialize a Git repository within your folder using |
@tiagovla |
@ZZT-console Hi, can you try directly run the ls cmd from console? To make sure the ls can work independly. I only found that the git repo is necessary. Very strange.... |
@ArtisticZhao Hi, I have done what you said, it seems that it really does not work, please how can I do it? |
Try to install it manually: git clone https://github.com/mathworks/MATLAB-language-server
cd MATLAB-language-server
npm install . && npm run package
node out/index.js --stdio Also what's your node version? |
@tiagovla , I finally found the reason, it was indeed my version of node, it is too old. Thank you for solving my confusion for so long. |
I have the same issue,
node --version
v20.8.1
nvim --version
NVIM v0.9.4
require("mason").setup()
require("mason-lspconfig").setup()
local lsp = require('lsp-zero').preset({})
lsp.on_attach(function(client, bufnr)
lsp.default_keymaps({buffer = bufnr})
end)
lsp.setup()
require 'lspconfig'.matlab_ls.setup {
settings = {
matlab = {
indexWorkspace=true,
installPath = "C:\\Program Files\\Polyspace\\R2020b",
matlabConnectionTiming = "onStart",
telemetry = true
}
}
}
|
@ZZT-console hope you share some ideas for solve the problem |
@jueqingsizhe66 check issue #10. |
Got it, try to update matlab to 2021b version |
I would try to downgrade your node version first. I'm sure 16.x works, I have not tested the other ones. |
@jueqingsizhe66 I believe you will need to update your version of MATLAB. It appears that you are using R2020b, but the language server requires R2021a or later. This is noted in the README for the MATLAB extension for Visual Studio Code, but is missing from the language server's README - I will add a note. @tiagovla The language server should now work with Node.js v18 and later (#10). If you notice that it isn't working with a particular verison, please feel free to open a new issue. |
I update the matlab version to MATLAB2021b with node 20.8.1, it works fluently |
Yes, also works with Node21.0.0 and MATALB2023a. |
@jueqingsizhe66 .It is simple. I deleted the old nodejs, whose version only was 12.x.x. Then, I download the LTS version of nodejs from the offical website. |
Try setting |
It seems to have randomly started working now, idk why. There do seem to be some errors/warnings in the log though so here it is anyways.
Is there anything I can do to fix those errors? If not then sorry for bothering you 😅 |
The first error is just a deprecated warning; you can ignore it. |
Ok thank you! |
@Shock9616 |
The issue with maci64 vs maca64 is a known bug, and is currently captured in mathworks/MATLAB-extension-for-vscode#53. Unfortunately, we do not have a recommended workaround at this time. |
@YUSIO I don't, sorry. Here's my matlab_ls config if it helps 🤷♂️ require("lspconfig").matlab_ls.setup({
settings = {
matlab = {
capabilities = require("cmp_nvim_lsp").default_capabilities(),
indexWorkspace = true,
installPath = "/Applications/MATLAB_R2023b.app",
telemetry = false,
},
},
single_file_support = true,
}) |
That seems to be hard coded here. You could probably just create that folder and symlink |
Hi @tiagovla any plan to support the MATLAB code execution in neovim? |
Hi I seem to be having trouble getting the lsp to run within neovim. It fails and exits with exit code 1 and signal 0. Running it in the terminal with the --stdio flag works however when it attempts to attach within neovim it fails. I've attached the lsp log below however I cannot make any sense of it, it appears to be an excerpt from the index.js file. any help would be appreciated |
For anyone interested maybe @Twisty9656 & @Shock9616:
|
…gnostic_suppression Fix diagnostic suppression insertion Fixes mathworks#4
@Twisty9656 what is the node version you are using? |
version 20.10.0 |
wait, its working now |
Hello, I'm having this error:
My MATLAB MATLAB version is R2024b, Node version is v20.17.0, and neovim is v0.9.5 My LSP configs can be found here (Note that I have tried using absolute path for EDITED: so I needed |
Neovim users can now use it with nvim-lspconfig and mason.nvim.
The text was updated successfully, but these errors were encountered: