Operating system/version
Linux Ubuntu 22
Terminal/GUI
GNOME Terminal
AstroNvim Health
astronvim: require("astronvim.health").check()
AstroNvim ~
- AstroNvim Version: unknown
- Neovim Version: v0.9.5
- OK Using stable Neovim >= 0.8.0
- OK `git` is installed: Used for core functionality such as updater and plugin management
- OK `xdg-open` is installed: Used for `gx` mapping for opening files with system opener (Optional)
- OK `lazygit` is installed: Used for mappings to pull up git TUI (Optional)
- OK `node` is installed: Used for mappings to pull up node REPL (Optional)
- WARNING `gdu` is not installed: Used for mappings to pull up disk usage analyzer (Optional)
- WARNING `btm` is not installed: Used for mappings to pull up system monitor (Optional)
- OK `python3` is installed: Used for mappings to pull up python REPL (Optional)
What is the goal
To try to go to definition on an external library code in C# dotnet project.
The go to definition in omnisharp's Mason LSP works but only for my local code, not library code. This is not ideal for working in production environment for my job.
To do this, I found the following "omnisharp-extended-lsp.nvim" plugin which enhances Neovim's ability to navigate to the definitions of C# code, even those defined in external libraries, by decompiling and displaying their source code in a temporary buffer.
Changes I've made to my Astronvim config:
In ~/.config/nvim/lua/plugins/ folder, I've added the following file:
-- file name "omni-extended.lua"
return { "Hoffs/omnisharp-extended-lsp.nvim" }
In ~/.config/nvim/init.lua, I've added the following code to setup custom omnisharp-roslyn LSP server:
local on_attach = require("astronvim.utils.lsp").on_attach
local capabilities = require("astronvim.utils.lsp").capabilities
local pid = vim.fn.getpid()
local omnisharp_dll_path = "/home/rampage/Downloads/omnisharp-roslyn-net6/OmniSharp.dll"
local config = {
on_attach = on_attach,
capabilities = capabilities,
handlers = {
["textDocument/definition"] = require("omnisharp_extended").handler,
},
cmd = { "dotnet", omnisharp_dll_path, "--languageserver", "--hostPID", tostring(pid) },
-- Enables support for reading code style, naming convention and analyzer
-- settings from .editorconfig.
enable_editorconfig_support = true,
-- If true, MSBuild project system will only load projects for files that
-- were opened in the editor. This setting is useful for big C# codebases
-- and allows for faster initialization of code navigation features only
-- for projects that are relevant to code that is being edited. With this
-- setting enabled OmniSharp may load fewer projects and may thus display
-- incomplete reference lists for symbols.
enable_ms_build_load_projects_on_demand = false,
-- Enables support for roslyn analyzers, code fixes and rulesets.
enable_roslyn_analyzers = false,
-- Specifies whether 'using' directives should be grouped and sorted during
-- document formatting.
organize_imports_on_format = true,
-- Enables support for showing unimported types and unimported extension
-- methods in completion lists. When committed, the appropriate using
-- directive will be added at the top of the current file. This option can
-- have a negative impact on initial completion responsiveness,
-- particularly for the first few completion sessions after opening a
-- solution.
enable_import_completion = true,
-- Specifies whether to include preview versions of the .NET SDK when
-- determining which version to use for project loading.
sdk_include_prereleases = true,
-- Only run analyzers against open files when 'enableRoslynAnalyzers' is
-- true
analyze_open_documents_only = false,
}
require("lspconfig").omnisharp.setup(config)
The above custom LSP config works Except For Go To Definition for external library code.
When I press gd for a external C# library code, I get the following error:
Error executing vim.schedule lua callback: /usr/local/share/nvim/runtime/lua/vim/lsp/util.lua:1157: Cursor position outside buffer stack traceback: [C]: in function 'nvim_win_set_cursor' /usr/local/share/nvim/runtime/lua/vim/lsp/util.lua:1157: in function 'jump_to_location' ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:176: in function 'handler' /usr/local/share/nvim/runtime/lua/vim/lsp.lua:1393: in function '' vim/_editor.lua: in function <vim/_editor.lua:0> Press ENTER or type command to continue
Additional Information
I came across the following issues which may provide more information but given that I'm new to neovim, I'm not sure if these may help:
- https://github.com/Hoffs/omnisharp-extended-lsp.nvim/issues/27
- https://github.com/Hoffs/omnisharp-extended-lsp.nvim/issues/14
For the above 2 issues, from my understanding I gathered this Cursor position outside buffer possibily may be a telescope issue after using the omnisharp-extended-lsp.nvim plugin.
Not sure if this is the correct way but I changed ~/.config/nvim/lua/astronvim/utils/lsp.lua code from:
if client.supports_method "textDocument/declaration" then
lsp_mappings.n["gD"] = {
function() vim.lsp.buf.declaration() end,
desc = "Declaration of current symbol",
}
end
To this:
if client.supports_method "textDocument/declaration" then
lsp_mappings.n["gD"] = {
"<cmd> lua require('omnisharp_extended').telescope_lsp_definitions()<CR>",
desc = "Declaration of current symbol",
}
end
But that did not work. Same Cursor position outside buffer issue persisted.
My Astronvim config: https://github.com/rampaged/nvim2
Steps to Reproduce
Prerequisite
Install .NET 6 SDK and Runtime
- Clone a fresh copy of Astronvim config
- Install the omnisharp-extended-lsp.nvim plugin
- Follow the omnisharp-extended-lsp.nvim plugin readme
- Create or clone a simple dotnet project that contains external library code. I've created this small C# project for testing.
git clone https://github.com/rampaged/echo-bot.gitcd echo-bot- run
dotnet buildon the "echo-bot" root directory
- cd to
~/.../echo-bot/Bots/EchoBot.csfile - on line 12,
gdonActivityHandlercode which is a external library code:
7. Notice the error:
Error executing vim.schedule lua callback: /usr/local/share/nvim/runtime/lua/vim/lsp/util.lua:1157: Cursor position outside buffer stack traceback: [C]: in function 'nvim_win_set_cursor' /usr/local/share/nvim/runtime/lua/vim/lsp/util.lua:1157: in function 'jump_to_location' ...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:176: in function 'handler' /usr/local/share/nvim/runtime/lua/vim/lsp.lua:1393: in function '' vim/_editor.lua: in function <vim/_editor.lua:0> Press ENTER or type command to continue
Expected behavior
The expected behavior is that when pressing gd on any external library code using the omnisharp-extended-lsp.nvim plugin, Neovim should seamlessly navigate to the definition of the code, displaying the decompiled source or relevant definition in a new buffer, without encountering any errors or issues with cursor positioning.
I've also opened this issue in AstroNvim github but it got closed without an answer.
https://github.com/AstroNvim/AstroNvim/issues/2463
Please let me know if you have any questions. Happy to provide more information as needed.
Thanks.