Giter Site home page Giter Site logo

csharpls-extended-lsp.nvim's Introduction

csharpls-extended-lsp.nvim

Extended textDocument/definition handler that handles assembly/decompilation loading for $metadata$ documents.

How it works

By providing an alternate handler for textDocument/definition the plugin listens to all responses and if it receives URI with $metadata$ it will call custom omnisharp endpoint o#/metadata which returns full document source. This source is then loaded as a scratch buffer with name set to /$metadata$/... This allows then allows jumping to the buffer based on name or from quickfix list, because it's loaded.

csharpls use ILSpy/ICSharpCode.Decompiler to decompile code. So just get the uri and We can receive decompile sources from csahrpls

api

The api is "csharp/metadata", in neovim ,you can request it like

  local result, err = client.request_sync("csharp/metadata", params, 10000)

sender

You need to send a uri, it is like

csharp:/metadata/projects/trainning2/assemblies/System.Console/symbols/System.Console.cs

In neovim, it will be result(s) from vim.lsp.handles["textDocument/definition"]

and the key of uri is the key,

The key to send is like

local params = {
	timeout = 5000,
	textDocument = {
		uri = uri,
	}
}

The key of textDocument is needed. And timeout is just for neovim. It is the same if is expressed by json.

receiver

The object received is like

{
	projectName = "csharp-test",
	assemblyName = "System.Runtime",
	symbolName = "System.String",
	source = "using System.Buffers;\n ...."
}

And In neovim, You receive the "result" above, you can get the decompile source from

local result, err = client.request_sync("csharp/metadata", params, 10000)
local source
if not err then
	source = result.result.source	
end

Usage

For Neovim >= 0.5

To use this plugin all that needs to be done is for the nvim lsp handler for textDocument/definition be overriden with one provided by this plugin.

If using lspconfig this can be done like this:

First configure omnisharp as per nvim-lspconfig.

Then to that config add handlers with custom handler from this plugin.

local pid = vim.fn.getpid()
-- On linux/darwin if using a release build, otherwise under scripts/OmniSharp(.Core)(.cmd)
-- on Windows
-- local omnisharp_bin = "/path/to/omnisharp/OmniSharp.exe"

local config = {
  handlers = {
    ["textDocument/definition"] = require('csharpls_extended').handler,
  },
  cmd = { csharpls },
  -- rest of your settings
}

require'lspconfig'.csharp_ls.setup(config)

For Neovim 0.5.1

Due to the fact that in 0.5.1 request params are not available is handler response a function to go to definitions has to be invoked manually. One option is to use telescope method explained in the next section or to use lsp_definitions() function which mimics standard definitions behavior.

nnoremap gd <cmd>lua require('csharp_ls_extended').lsp_definitions()<cr>

Thanks to the help of csharp-language-server

csharpls-extended-lsp.nvim's People

Contributors

decodetalkers avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.