csharp-ls
0.12.0
See the version list below for details.
dotnet tool install --global csharp-ls --version 0.12.0
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local csharp-ls --version 0.12.0
#tool dotnet:?package=csharp-ls&version=0.12.0
nuke :add-package csharp-ls --version 0.12.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
Settings
csharp.solution
- solution to load, optional
Clients/Editor plugins
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
$ (cd src && 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.
Product | Versions 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. |
This package has no dependencies.
Version | Downloads | Last updated |
---|---|---|
0.15.0 | 35,355 | 8/15/2024 |
0.14.0 | 15,943 | 6/23/2024 |
0.13.0 | 17,481 | 5/8/2024 |
0.12.0 | 7,292 | 4/22/2024 |
0.11.0 | 28,182 | 1/21/2024 |
0.10.0 | 19,199 | 11/4/2023 |
0.9.0 | 18,583 | 8/12/2023 |
0.8.0 | 17,672 | 5/6/2023 |
0.7.1 | 6,483 | 4/8/2023 |
0.7.0 | 3,359 | 3/25/2023 |
0.6.1 | 6,132 | 2/26/2023 |
0.6.0 | 7,961 | 12/30/2022 |
0.5.7 | 8,969 | 10/9/2022 |
0.5.6 | 3,627 | 9/5/2022 |
0.5.5 | 2,882 | 8/23/2022 |
0.5.4 | 1,892 | 8/20/2022 |
0.5.3 | 3,645 | 7/29/2022 |
0.5.2 | 3,865 | 7/2/2022 |
0.5.1 | 4,617 | 5/19/2022 |
0.5.0 | 5,196 | 4/23/2022 |
0.4.3 | 2,636 | 4/4/2022 |
0.4.2 | 1,898 | 3/29/2022 |
0.4.1 | 1,798 | 3/23/2022 |
0.4.0 | 2,198 | 3/8/2022 |
0.3.0 | 2,489 | 2/4/2022 |
0.2.1 | 1,943 | 1/22/2022 |
0.2.0 | 1,885 | 1/17/2022 |
0.1.9 | 1,656 | 12/27/2021 |
0.1.8 | 1,914 | 12/8/2021 |
0.1.7 | 3,068 | 11/26/2021 |
0.1.6 | 1,706 | 11/9/2021 |
0.1.5 | 1,499 | 11/3/2021 |
0.1.4 | 1,630 | 10/20/2021 |
0.1.3 | 1,871 | 10/2/2021 |
0.1.2 | 1,909 | 9/14/2021 |
0.1.1-alpha | 1,648 | 9/11/2021 |