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

Omnisharp doesn't work on M1 Mac #1278

Open
4 tasks done
sonderistic opened this issue Nov 26, 2024 · 4 comments · May be fixed by #1279
Open
4 tasks done

Omnisharp doesn't work on M1 Mac #1278

sonderistic opened this issue Nov 26, 2024 · 4 comments · May be fixed by #1279
Labels
bug Something isn't working

Comments

@sonderistic
Copy link

sonderistic commented Nov 26, 2024

Checklist

  • I have searched through the AstroNvim documentation
  • I have searched through the existing issues of this project
  • I have searched the existing issues of plugins related to this issue
  • I can replicate the bug with the minimal repro.lua provided below

Neovim version (nvim -v)

v0.10.2

Operating system/version

macOS 15.0

Terminal/GUI

iTerm2

Describe the bug

Omnisharp simply does not work on the M1 Mac. Attempting to "go to definition" yields the error seen in the screencap. What's puzzling is that autocomplete suggestions seem to be present, but accepting a suggestion will yield the same error.

Screenshot 2024-11-26 at 2 47 01 PM

Steps to Reproduce

  1. Create directory
  2. Add repro.lua to directory
  3. Make a new dotnet project (dotnet new mvc via terminal)
  4. Run nvim -u repro.lua
  5. Open any cs file in the project
  6. Attempt to "Find References", "Go to definition", or any LSP-supported action.

Expected behavior

LSP should work.

Screenshots

No response

Additional Context

Looks like someone else has this exact problem on the Neovim repo:
neovim/neovim#30908

Minimal configuration

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	-- stylua: ignore
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable",
		lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

-- install plugins
local plugins = {
	{ "AstroNvim/AstroNvim",      import = "astronvim.plugins" },
	{ "AstroNvim/astrocommunity", import = "astrocommunity.pack.mdx" },
        { "AstroNvim/astrocommunity", import = "astrocommunity.pack.cs-omnisharp" },
	-- add any other plugins/customizations here
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- add anything else here (autocommands, vim.filetype, etc.)

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

-- install plugins
local plugins = {
  { "AstroNvim/AstroNvim", import = "astronvim.plugins" },
  { "AstroNvim/astrocommunity" },

  -- add any other plugins/customizations here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here (autocommands, vim.filetype, etc.)
@sonderistic sonderistic added the bug Something isn't working label Nov 26, 2024
@gepbird
Copy link

gepbird commented Nov 27, 2024

Hi @sonderistic, I'm coming from the neovim issue you linked, thanks for that! The reason why the workaround didn't work for you, because the workaround is to not use Custom handlers (marked as suboptimal), but use Custom commands / keymaps (marked as optimal) instead: https://github.com/Hoffs/omnisharp-extended-lsp.nvim?tab=readme-ov-file#how-to-use.

However AstroNvim uses custom handlers at

["textDocument/definition"] = function(...) require("omnisharp_extended").definition_handler(...) end,
, I advise the developers to use custom commands instead for nvim 0.11+ compatibility.

As a user I'm not sure what's the best solution as I haven't used a nvim distro, if you cant find a way to turn off the built in omnisharp-extended plugin or config, or override that, you can make a fork where that is removed and use that in your config until it's fixed.

@sonderistic
Copy link
Author

sonderistic commented Nov 27, 2024

Hello @gepbird, thanks for your input. I have replaced the suboptimal solution with the one you prescribed (I think- I ChatGPT'd it), but am still getting the same error so it must be wrongly implemented:

return {
  -- CSharp support
  {
    "nvim-treesitter/nvim-treesitter",
    optional = true,
    opts = function(_, opts)
      if opts.ensure_installed ~= "all" then
        opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "c_sharp" })
      end
    end,
  },
  {
    "jay-babu/mason-null-ls.nvim",
    optional = true,
    opts = function(_, opts)
      opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "csharpier" })
    end,
  },
  {
    "williamboman/mason-lspconfig.nvim",
    optional = true,
    opts = function(_, opts)
      opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "omnisharp" })
    end,
  },
  {
    "Hoffs/omnisharp-extended-lsp.nvim",
    dependencies = {
      {
        "AstroNvim/astrolsp",
        opts = {
          config = {
            csharp_ls = {
              on_attach = function(_, bufnr)
                -- Helper function for setting key mappings
                local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
                local opts = { noremap = true, silent = true }
                
                -- All mappings
                buf_set_keymap("n", "gd", "<cmd>lua require('omnisharp_extended').lsp_definition()<cr>", opts)
                buf_set_keymap("n", "<leader>D", "<cmd>lua require('omnisharp_extended').lsp_type_definition()<cr>", opts)
                buf_set_keymap("n", "gr", "<cmd>lua require('omnisharp_extended').lsp_references()<cr>", opts)
                buf_set_keymap("n", "gi", "<cmd>lua require('omnisharp_extended').lsp_implementation()<cr>", opts)
                buf_set_keymap("n", "gr", "<cmd>lua require('omnisharp_extended').telescope_lsp_references()<cr>", opts)
                buf_set_keymap("n", "gd", "<cmd>lua require('omnisharp_extended').telescope_lsp_definition({ jump_type = 'vsplit' })<cr>", opts)
                buf_set_keymap("n", "<leader>D", "<cmd>lua require('omnisharp_extended').telescope_lsp_type_definition()<cr>", opts)
                buf_set_keymap("n", "gi", "<cmd>lua require('omnisharp_extended').telescope_lsp_implementation()<cr>", opts)
              end,
            },
          },
        },
      },
    },
  },
  {
    "jay-babu/mason-nvim-dap.nvim",
    optional = true,
    opts = function(_, opts)
      opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "coreclr" })
    end,
  },
  {
    "WhoIsSethDaniel/mason-tool-installer.nvim",
    optional = true,
    opts = function(_, opts)
      opts.ensure_installed =
        require("astrocore").list_insert_unique(opts.ensure_installed, { "omnisharp", "csharpier", "netcoredbg" })
    end,
  },
  {
    "nvim-neotest/neotest",
    optional = true,
    dependencies = { "Issafalcon/neotest-dotnet", config = function() end },
    opts = function(_, opts)
      if not opts.adapters then opts.adapters = {} end
      table.insert(opts.adapters, require "neotest-dotnet"(require("astrocore").plugin_opts "neotest-dotnet"))
    end,
  },
}

Could you please advise me on how to properly use the optimal solution?

@gepbird
Copy link

gepbird commented Nov 27, 2024

@sonderistic at first sight that looks good, are you sure that configuration is being used and not the default AstroVim?

Also "downgrading" to the latest stable nvim release (0.10.2) should also get rid of the error.

If you still want to use the nightly nvim, please share more context (like another minimal reproduction) with your modified/overridden AstroNvim config (or wait for maintainers to fix it)

@ahmtsen
Copy link
Contributor

ahmtsen commented Nov 29, 2024

created a PR that solves the issue. the problem was that the language server name was csharp_ls instead of omnisharp. as the author of the pack I apologise for the inconvenience.

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

Successfully merging a pull request may close this issue.

3 participants