AstroNvim / astrocommunity

A community repository of common plugin specifications
https://astronvim.github.io/astrocommunity/
GNU General Public License v3.0
1.23k stars 241 forks source link

Omnisharp doesn't work on M1 Mac #1278

Open sonderistic opened 4 days ago

sonderistic commented 4 days ago

Checklist

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: https://github.com/neovim/neovim/issues/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.)
gepbird commented 3 days ago

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 https://github.com/AstroNvim/astrocommunity/blob/bb7988ac0efe0c17936c350c6da19051765f0e71/lua/astrocommunity/pack/cs-omnisharp/init.lua#L35, 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 commented 3 days ago

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 commented 3 days ago

@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 commented 1 day ago

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.