csharp-ls 0.15.0

dotnet tool install --global csharp-ls --version 0.15.0                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local csharp-ls --version 0.15.0                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=csharp-ls&version=0.15.0                
nuke :add-package csharp-ls --version 0.15.0                

Description

This is a hacky Roslyn-based LSP server for C#, as an alternative to omnisharp-roslyn.

csharp-ls requires .NET 8 SDK to be installed. However it has been reported to work with projects using older versions of dotnet SDK, including .NET Core 3, .NET Framework 4.8 and possibly older ones too as it uses the standard Roslyn/MSBuild libs that Visual Studio & omnisharp does.

See CHANGELOG.md for the list of recent improvements/fixes.

Acknowledgements

  • csharp-ls is not affiliated with Microsoft Corp;
  • csharp-ls uses LSP interface from Ionide.LanguageServerProtocol;
  • csharp-ls uses Roslyn to parse and update code; Roslyn maps really nicely to LSP w/relatively little impedance mismatch;
  • csharp-ls uses ILSpy/ICSharpCode.Decompiler to decompile types in assemblies to C# source.

Installation

dotnet tool install --global csharp-ls

See csharp-ls nuget page

Settings

  • csharp.solution - solution to load, optional

Clients

csharp-ls implements the standard LSP protocol to interact with your editor. However there are some features that need a non-standard implementation and this is where editor-specific plugins can be helpful.

Emacs

emacs/lsp-mode

Supports automatic installation, go-to-metatada (can view code from nuget/compiled dlls) and some additional features.

See emacs/lsp-mode.

Visual Studio Code

vytautassurvila/vscode-csharp-ls

  • Supports code decompilation from metadata

See csharp-ls and vscode-csharp-ls @ github.

statiolake/vscode-csharp-ls

See vscode-csharp-ls.

Building

On Linux/macOS

$ dotnet build

Features

  • symbol rename;
  • code refactorings from roslyn;
  • go-to-definition;
  • find references;
  • document/workspace symbol search;
  • textDocument/documentHighlight support:
    • highlighting other symbol references in the document on hover;
  • codeAction/resolve support for better performance when invoking code actions;
  • semantic token support (thanks to @tcx4c70);
  • inlay hint support (thanks to @tcx4c70);
  • go-to-definition in metadata support (needs integration from your LSP client).

TODO list

  • check we're not doing lense stuff or other funny things on metadata code (emacs-lsp/lsp-mode issue?);
  • find-refs is blocking r/w operations, request scheduling needs smarter refactoring;
    • should we cancel existing ones? -- where cancellable? how to know?
  • support for pull diagnostics (lsp 3.17);
  • go-to-def in metadata does not work for Attribute as those have Attribute suffix;
  • progress support;
  • properly escape docxml text, e.g. backquote is a special character in markdown;
  • selection range provider
  • ability to run tests / test browser support like fsac has?
  • razorls integration (server-side)
  • analyzer support
  • code generator support
  • vscode plugin

FAQ

decompile for your editor , with the example of neovim

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

And there is a plugin of neovim for you to decompile it.

csharpls-extended-lsp.nvim

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.15.0 37,971 8/15/2024
0.14.0 15,963 6/23/2024
0.13.0 17,488 5/8/2024
0.12.0 7,293 4/22/2024
0.11.0 28,329 1/21/2024
0.10.0 19,207 11/4/2023
0.9.0 18,584 8/12/2023
0.8.0 17,673 5/6/2023
0.7.1 6,484 4/8/2023
0.7.0 3,360 3/25/2023
0.6.1 6,133 2/26/2023
0.6.0 7,962 12/30/2022
0.5.7 8,978 10/9/2022
0.5.6 3,628 9/5/2022
0.5.5 2,883 8/23/2022
0.5.4 1,893 8/20/2022
0.5.3 3,646 7/29/2022
0.5.2 3,866 7/2/2022
0.5.1 4,626 5/19/2022
0.5.0 5,197 4/23/2022
0.4.3 2,641 4/4/2022
0.4.2 1,899 3/29/2022
0.4.1 1,799 3/23/2022
0.4.0 2,199 3/8/2022
0.3.0 2,490 2/4/2022
0.2.1 1,944 1/22/2022
0.2.0 1,886 1/17/2022
0.1.9 1,657 12/27/2021
0.1.8 1,915 12/8/2021
0.1.7 3,069 11/26/2021
0.1.6 1,711 11/9/2021
0.1.5 1,500 11/3/2021
0.1.4 1,631 10/20/2021
0.1.3 1,872 10/2/2021
0.1.2 1,910 9/14/2021
0.1.1-alpha 1,649 9/11/2021