razzmatazz / csharp-language-server Goto Github PK
View Code? Open in Web Editor NEWRoslyn-based LSP language server for C#
License: MIT License
Roslyn-based LSP language server for C#
License: MIT License
I'm using lsp-mode and installed csharp-ls automatically. I've added the relevant mode hooks to my lsp-mode
config. When I visit a C# file, I see that lsp-mode
emits LSP :: Connected to [csharp-ls:71243/starting].
to *Messages*
buffer, but I never see a success message that the startup succeeded, and none of the expected LS functionality (symbol rename, goto definition, etc) works in the C# file's buffer.
*lsp-log*
Command "csharp-ls" is present on the path.
Command "csharp-ls" is present on the path.
Found the following clients for /Users/johanan/Developer/learning/csharp/hello-world/hello-world/Program.cs: (server-id csharp-ls, priority -2)
The following clients were selected based on priority: (server-id csharp-ls, priority -2)
Enabled lsp-toggle-trace-io
:
[Trace - 03:33:14 pm] Sending request 'initialize - (1)'.
Params: {
"processId": null,
"rootPath": "/Users/johanan/Developer/learning/csharp/hello-world/hello-world",
"clientInfo": {
"name": "emacs",
"version": "GNU Emacs 28.1 (build 2, aarch64-apple-darwin21.4.0, NS appkit-2113.40 Version 12.3.1 (Build 21E258))\n of 2022-04-07"
},
"rootUri": "file:///Users/johanan/Developer/learning/csharp/hello-world/hello-world",
"capabilities": {
"workspace": {
"workspaceEdit": {
"documentChanges": true,
"resourceOperations": [
"create",
"rename",
"delete"
]
},
"applyEdit": true,
"symbol": {
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
}
},
"executeCommand": {
"dynamicRegistration": false
},
"didChangeWatchedFiles": {
"dynamicRegistration": true
},
"workspaceFolders": true,
"configuration": true,
"codeLens": {
"refreshSupport": true
},
"fileOperations": {
"didCreate": false,
"willCreate": false,
"didRename": false,
"willRename": false,
"didDelete": false,
"willDelete": false
}
},
"textDocument": {
"declaration": {
"linkSupport": true
},
"definition": {
"linkSupport": true
},
"implementation": {
"linkSupport": true
},
"typeDefinition": {
"linkSupport": true
},
"synchronization": {
"willSave": true,
"didSave": true,
"willSaveWaitUntil": true
},
"documentSymbol": {
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
},
"hierarchicalDocumentSymbolSupport": true
},
"formatting": {
"dynamicRegistration": true
},
"rangeFormatting": {
"dynamicRegistration": true
},
"rename": {
"dynamicRegistration": true,
"prepareSupport": true
},
"codeAction": {
"dynamicRegistration": true,
"isPreferredSupport": true,
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports"
]
}
},
"resolveSupport": {
"properties": [
"edit",
"command"
]
},
"dataSupport": true
},
"completion": {
"completionItem": {
"snippetSupport": true,
"documentationFormat": [
"markdown",
"plaintext"
],
"resolveAdditionalTextEditsSupport": true,
"insertReplaceSupport": true,
"deprecatedSupport": true,
"resolveSupport": {
"properties": [
"documentation",
"details",
"additionalTextEdits",
"command"
]
},
"insertTextModeSupport": {
"valueSet": [
1,
2
]
}
},
"contextSupport": true
},
"signatureHelp": {
"signatureInformation": {
"parameterInformation": {
"labelOffsetSupport": true
}
}
},
"documentLink": {
"dynamicRegistration": true,
"tooltipSupport": true
},
"hover": {
"contentFormat": [
"markdown",
"plaintext"
]
},
"foldingRange": {
"dynamicRegistration": true
},
"callHierarchy": {
"dynamicRegistration": false
},
"publishDiagnostics": {
"relatedInformation": true,
"tagSupport": {
"valueSet": [
1,
2
]
},
"versionSupport": true
},
"linkedEditingRange": {
"dynamicRegistration": true
}
},
"window": {
"workDoneProgress": true,
"showMessage": null,
"showDocument": {
"support": true
}
}
},
"initializationOptions": null,
"workDoneToken": "1"
}
I also see that it spawns *csharp-ls::stderr*
and *csharp-ls*
buffers but those remain empty.
I'm assuming that it's stuck in startup but to be honest I'm not 100% sure this is the case, and I'm not sure how to verify.
Unfortunately this language server does not seem to support inlay hints.
Below is an example image from google on inlay hints in Rust with neovim:
Here is an ongoing issue on omnisharp supporting this as well.
When I use csharpls, and use the jump of nvimlsp, it do not return a decompile file.
I see that you have support decompile, I think it should work
On vscode I get inconsistent completion results. I depends on how auto-completion was invoked - by trigger character or invoked via shortcut. Wild guess would be that autocompletion is done based on code that was before typing trigger character (trigger character is not accounted).
Sample file I tested on
namespace tests.proj._2
{
public class Tests
{
public void Setup()
{
}
public void Proj2_Test1()
{
this.
}
}
}
When I type this.
I get autocompletion with items as
, is
, switch
, with
. Note that these options are valid for this
(with space after it). Messages that are being sent to csharp-ls:
[LSP - 8:12:37 PM] {"isLSPMessage":true,"type":"send-notification","message":{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///home/vytas/code/vscode/dotnettests/tests.proj.2/UnitTest1.cs","version":127},"contentChanges":[{"range":{"start":{"line":10,"character":16},"end":{"line":10,"character":16}},"rangeLength":0,"text":"."}]}},"timestamp":1648833157228}
[LSP - 8:12:37 PM] {"isLSPMessage":true,"type":"send-request","message":{"jsonrpc":"2.0","id":603,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///home/vytas/code/vscode/dotnettests/tests.proj.2/UnitTest1.cs"},"position":{"line":10,"character":17},"context":{"triggerKind":2,"triggerCharacter":"."}}},"timestamp":1648833157229}
[LSP - 8:12:37 PM] {"isLSPMessage":true,"type":"receive-notification","message":{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/vytas/code/vscode/dotnettests/tests.proj.2/UnitTest1.cs","diagnostics":[{"range":{"start":{"line":10,"character":17,"debuggerDisplay":"(10,17)"},"end":{"line":10,"character":17,"debuggerDisplay":"(10,17)"},"debuggerDisplay":"(10,17)-(10,17)"},"severity":1,"source":"lsp","message":"Identifier expected","debuggerDisplay":"[Error] ((10,17)-(10,17)) Identifier expected ()"},{"range":{"start":{"line":10,"character":17,"debuggerDisplay":"(10,17)"},"end":{"line":10,"character":17,"debuggerDisplay":"(10,17)"},"debuggerDisplay":"(10,17)-(10,17)"},"severity":1,"source":"lsp","message":"; expected","debuggerDisplay":"[Error] ((10,17)-(10,17)) ; expected ()"}]}},"timestamp":1648833157235}
[LSP - 8:12:37 PM] {"isLSPMessage":true,"type":"receive-response","message":{"jsonrpc":"2.0","id":603,"result":{"isIncomplete":false,"items":[{"label":"as","kind":14,"insertTextFormat":1},{"label":"is","kind":14,"insertTextFormat":1},{"label":"switch","kind":14,"insertTextFormat":1},{"label":"with","kind":14,"insertTextFormat":1}]}},"timestamp":1648833157236}
But if I close autocompletion and trigger it via shortcut then I get correct items Equals
, Setup
, ToString
and others. csharp-ls messages:
[LSP - 8:15:39 PM] {"isLSPMessage":true,"type":"send-request","message":{"jsonrpc":"2.0","id":620,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///home/vytas/code/vscode/dotnettests/tests.proj.2/UnitTest1.cs"},"position":{"line":10,"character":17},"context":{"triggerKind":1}}},"timestamp":1648833339323}
[LSP - 8:15:39 PM] {"isLSPMessage":true,"type":"receive-response","message":{"jsonrpc":"2.0","id":620,"result":{"isIncomplete":false,"items":[{"label":"Equals","kind":2,"insertTextFormat":1},{"label":"GetHashCode","kind":2,"insertTextFormat":1},{"label":"GetType","kind":2,"insertTextFormat":1},{"label":"MemberwiseClone","kind":2,"insertTextFormat":1},{"label":"Proj2_Test1","kind":2,"insertTextFormat":1},{"label":"Setup","kind":2,"insertTextFormat":1},{"label":"ToString","kind":2,"insertTextFormat":1}]}},"timestamp":1648833339332}
Note that it's not always reproducible. I guess it somehow depends on file size too. As when working with big files it happens more often than with this sample program.
The question is can you reproduce that on other clients? If needed I probably could implement some hack/fix on vscode language client to wait for textDocument/didChange response (maybe event add some delay) and only then emit textDocument/completion
When requesting "workspace/symbol", lsp-mode receives Classes
and Structs
as File
. I don't know if this happens with other kinds, as well. Methods, Properties and Fields seems to be working as intended.
I tried to use the c-sharp-server in neovim, but I ran into a error.
So I tried to run the server just by itself and I got:
You must install or update .NET to run this application.
App: /home/USER/.local/share/nvim/mason/packages/csharp-language-server/csharp-ls
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '7.0.0' (x64)
.NET location: /usr/lib/dotnet
No frameworks were found.
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0&arch=x64&rid=pop.22.04-x64
But my I have 7.0 installed but it is at /usr/share/dotnet/sdk and not at /usr/lib/dotnet
I tried adding a symlink but it wouldn't help.
Then I realized I missed the runtime and installed it but I still got:
You must install .NET to run this application.
App: /home/notomoro/.local/share/nvim/mason/packages/csharp-language-server/csharp-ls
Architecture: x64
App host version: 7.0.2
.NET location: Not found
Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed
Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=pop.22.04-x64&apphost_version=7.0.2
I am not sure if this is a installation problem of
I am using Pop-Os 22.04
dotnet --list-sdks
7.0.102 [/usr/share/dotnet/sdk]
dotnet --list-runtimes
Microsoft.AspNetCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
I installed csharp-language-server via https://github.com/williamboman/mason.nvim
Maybe this is a package problem on my side?
I'm trying to get csharp-ls to work with nvim coc within a Unity project. I'm getting the following error:
[coc.nvim] csharp-ls: No parent project could be resolved to add file "/c%3A/Users/blasc/Projects/path/in/project/assemblies/UnityEngine.CoreModule/symbols/UnityEngine.Vector3.cs" to workspace
Any idea if there is a way to make it work? Is this a known issue?
When running csharp-ls
I am presented with this error:
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '6.0.0' (x64) was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x64&rid=fedora.35-x64
However my dotnet --info
output is this:
.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff
Runtime Environment:
OS Name: fedora
OS Version: 35
OS Platform: Linux
RID: fedora.35-x64
Base Path: /home/wizardlink/.dotnet/sdk/6.0.100/
Host (useful for support):
Version: 6.0.0
Commit: 4822e3c3aa
.NET SDKs installed:
5.0.403 [/home/wizardlink/.dotnet/sdk]
6.0.100 [/home/wizardlink/.dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.12 [/home/wizardlink/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/home/wizardlink/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.12 [/home/wizardlink/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/home/wizardlink/.dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
For reference, dotnet
was installed manually following their documentation, I don't see why this issue is ocurring so I decided to open an issue as I'm not that knowledgeable with the dotnet
toolchain.
I'm using csharp-ls 0.6.1 via neovim and nvim-lspconfig.
I can reproduce the problem with a project with a single .cs file:
using System;
namespace dotnet
{
class Program
{
static void Main(string[] args)
{
var a = args;
}
}
}
If my .csproj
file contains this:
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
then the LSP appears to initialise fine - I do not see anything that looks problematic in the logs, but none of the functionality works. Eg. if I have my cursor on the args
in var a = args
and try go-to-definition, nothing happens, and the logs say that the language server reported "No location found".
However if I replace the TargetFrameworks
line in the csproj with any of the following, everything works fine:
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
And use the new https://github.com/ionide/LanguageServerProtocol nuget which was just extracted from FSAC
When csharp-language-server is used with vscode-languageclient then client crashes with error Unhandled method client/registerCapability
. If I read code right culprit is in following two lines
csharp-language-server/src/CSharpLanguageServer/Server.fs
Lines 583 to 584 in 520ef35
client/registerCapability
to client immediately before emitting initialize result.
According to Lsp initialize
request
In addition the server is not allowed to send any requests or notifications to the client until it has responded with an InitializeResult, with the exception that during the initialize request the server is allowed to send the notifications window/showMessage, window/logMessage and telemetry/event as well as the window/showMessageRequest request to the client
https://microsoft.github.io/language-server-protocol/specification#initialize
In order to register dynamic capabilities initialized
notification should be used instead:
The server can use the initialized notification for example to dynamically register capabilities
https://microsoft.github.io/language-server-protocol/specification#initialized
And the vscode-languageclient code that starts listening on client/registerCapability only after successful initialization (first and last lines are relevant) https://github.com/microsoft/vscode-languageserver-node/blob/d9eeaf626fd9362eec69fe63322d15760f6794d1/client/src/common/client.ts#L3402-L3430
After updating to 0.5.4 csharp-ls crashes not long after initialization.
I don't know where to get a log, so if you need one please tell me where I can find it. The only error I get in stderr is Process csharp-ls stderr<1> finished
It crashes while moving the cursor, so my suspicion are either highlight or documentation.
Consider the following code:
[Route("Demo")]
public class DemoController : Controller
{
[HttpGet]
[Router("DemoOperation")]
public IActionResult DemoOperation()
{
// some logic
}
}
Now try chaning the [HttpGet]
attribute into a [HttpPost]
attribute, by deleting Get
, entering P
and wait for auto-completion to kick in.
Observed that:
HttpPost
is not suggestedHttpPostAttribute
is suggested[HttpPost]
than without auto-completion. Oops?Basically, unless you are willing to live with the needlessly verbose attribute-name, auto-completion now kinda works against you.
Since attribute-completion is somewhat context-sensitive, I'm not sure if there are any simple solutions here... But if there is, that would really be appreciated ๐
I tried to use the c-sharp-server in neovim, but I ran into a error.
So I tried to run the server just by itself and I got:
You must install or update .NET to run this application.
App: /home/USER/.local/share/nvim/mason/packages/csharp-language-server/csharp-ls
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '7.0.0' (x64)
.NET location: /usr/lib/dotnet
No frameworks were found.
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0&arch=x64&rid=pop.22.04-x64
But my I have 7.0 installed but it is at /usr/share/dotnet/sdk and not at /usr/lib/dotnet
I tried adding a symlink but it wouldn't help.
Then I realized I missed the runtime and installed it but I still got:
You must install .NET to run this application.
App: /home/notomoro/.local/share/nvim/mason/packages/csharp-language-server/csharp-ls
Architecture: x64
App host version: 7.0.2
.NET location: Not found
Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed
Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=pop.22.04-x64&apphost_version=7.0.2
I am not sure if this is a installation problem of
I am using Pop-Os 22.04
dotnet --list-sdks
7.0.102 [/usr/share/dotnet/sdk]
dotnet --list-runtimes
Microsoft.AspNetCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Maybe this is a package problem on my side?
I am accustomed to using 2 spaces of indentation, and I would like to know whether there is a variable to keep the indentation to 2 spaces or if there is any way to keep these 2 spaces of indentation. When I input a `;', the code becomes 4 spaces of indentation automatically, and I want to avoid this happening.
I was using version 0.3.x and when loading a new project, lsp-mode was able to show that the project/solution was loading. Now in version 0.5.3 lsp-mode gives no indication of loading, it thinks the project loaded instantly, which is not true. So I have to wait and arbitrarily try to use commands until something works showing that the solution was actually loaded.
In vscode extension output window receives focus way to often. When it becomes focused then vscode hides terminal window.
At the moment csharp-ls returns error code 32000 for canceled request via $/cancelRequest
. According to specs it should be 32800.
If the request returns an error response on cancellation it is advised to set the error code to ErrorCodes.RequestCancelled.
export const RequestCancelled: integer = -32800;
Logs:
[LSP - 8:47:00 AM] {"isLSPMessage":true,"type":"send-request","message":{"jsonrpc":"2.0","id":436,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"file:///home/REDACTED.cs"},"range":{"start":{"line":868,"character":32},"end":{"line":868,"character":37}},"context":{"diagnostics":[{"range":{"start":{"line":868,"character":32},"end":{"line":868,"character":37}},"message":"The name 'order' does not exist in the current context","severity":1,"source":"lsp"}]}}},"timestamp":1650520020837}
[LSP - 8:47:01 AM] {"isLSPMessage":true,"type":"send-notification","message":{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///home/REDACTED.cs","version":199},"contentChanges":[{"range":{"start":{"line":868,"character":32},"end":{"line":868,"character":37}},"rangeLength":5,"text":"shoppingBasket"}]}},"timestamp":1650520021012}
[LSP - 8:47:01 AM] {"isLSPMessage":true,"type":"send-notification","message":{"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":436}},"timestamp":1650520021015}
[LSP - 8:47:01 AM] {"isLSPMessage":true,"type":"receive-response","message":{"jsonrpc":"2.0","id":436,"error":{"data":{"type":"System.Threading.Tasks.TaskCanceledException","message":"A task was canceled.","code":-2146233029},"code":-32000,"message":"A task was canceled."}},"timestamp":1650520021023}
[Error - 8:47:01 AM] Request textDocument/codeAction failed.
Message: A task was canceled.
Code: -32000
[object Object]
Hi,
I am using csharp-ls with coc.nvim. My indentation settings are:
shiftwidth = 4, tabstop = 4, expandtab = false,
Passed on by coc.nvim as the following... looks fine to me.
[Trace - 1:36:19 PM] Sending request 'textDocument/formatting - (1)'. Params: { "textDocument": { "uri": "file:///Users/fl0kng/dev/Test.cs" }, "options": { "tabSize": 4, "insertSpaces": false, "insertFinalNewline": true } }
#
Does csharp-ls handle formatting options? I had a quick look, and it seems as if it does not do anything... ;)
Thanks in advance and kind regards,
Florian
I've tried to configure the language server in Coc as follows:
{
"languageserver": {
"csharp-ls": {
"command": "csharp-ls",
"filetypes": ["cs"],
"rootPatterns": ["*.csproj", ".vim/", ".git/", ".hg/"]
}
}
}
But it doesn't return snippets during completion
Does this language server currently support snippets?
Hi,
I've tested v0.1.5 of csharp-ls and still unable to jump to metadata.
Steps to reproduce:
Expected Result:
Actual Behavior:
System:
I keep getting this exception in message buffer when scrolling/navigating in 0.5.5
:
LSP :: Error from the Language Server: System.AggregateException: One or more errors occurred. (Service of type 'Microsoft.CodeAnalysis.Options.ILegacyGlobalOptionsWorkspaceService' is required to accomplish the task but is not available from the workspace.)
---> System.InvalidOperationException: Service of type 'Microsoft.CodeAnalysis.Options.ILegacyGlobalOptionsWorkspaceService' is required to accomplish the task but is not available from the workspace.
at Microsoft.CodeAnalysis.Host.HostWorkspaceServices.GetRequiredService[TWorkspaceService]()
at Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers.GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.CreateCodeActionWithDialogAsync(Document document, SyntaxNode typeDeclaration, INamedTypeSymbol containingType, ImmutableArray`1 members, CleanCodeGenerationOptionsProvider fallbackOptions, Boolean generateEquals, Boolean generateGetHashCode, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers.GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.CreateActionsAsync(Document document, SyntaxNode typeDeclaration, INamedTypeSymbol containingType, ImmutableArray`1 selectedMembers, CleanCodeGenerationOptionsProvider fallbackOptions, Boolean hasEquals, Boolean hasGetHashCode, Boolean withDialog, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers.GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.HandleNonSelectionAsync(CodeRefactoringContext context, CleanCodeGenerationOptionsProvider fallbackOptions)
at Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers.GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.ComputeRefactoringsAsync(CodeRefactoringContext context)
--- End of inner exception stack trace --- (Internal Error)
It doesn't crash or anything. But it is kinda distracting.
csharp_ls: -32000: Failed to resolve assembly: 'Microsoft.ML.DataView, Version=1.0.0.0, Culture=neutral, PublicKeyToken
=cc7b13ffcd2ddd51'
Is it a bug?
I use neovim with csharp-ls and it suddenly stopped working. I really don't understand why.
Every time I startup the lsp I get an error on startup.
LSP[csharp_ls][Info] csharp-ls: initializing, csharp-ls version 0.4.0.0; options are: {
"logLevel": 4
}
LSP[csharp_ls][Info] csharp-ls: csharp-ls is released under MIT license and is not affiliated with Microsoft Corp.; see https://github.com/razzmatazz/csharp-language-server
LSP[csharp_ls][Log] csharp-ls: attempting to find and load solution based on cwd: "/home/nikolai/repos/astar_maze"..
LSP[csharp_ls][Log] csharp-ls: looking for .csproj/fsproj files on /home/nikolai/repos/astar_maze..
LSP[csharp_ls][Log] csharp-ls: 0 solution(s) found: []
LSP[csharp_ls][Log] csharp-ls: no or multiple .sln files found on /home/nikolai/repos/astar_maze
LSP[csharp_ls][Log] csharp-ls: loading proj file /home/nikolai/repos/astar_maze/AStarMaze.csproj..
LSP[csharp_ls][Log] csharp-ls: could not OpenProjectAsync('/home/nikolai/repos/astar_maze/AStarMaze.csproj'): System.AggregateException: One or more errors occurred. (Could not load file or assembly 'System.Conf
iguration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621))
---> System.IO.FileLoadException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specifi
c file. (0x80131621)
File name: 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
---> System.IO.FileLoadException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>g__TryLoadAssembly|3(AssemblyName assemblyName)
at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>b__2(AssemblyLoadContext _, AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
at Microsoft.Build.Evaluation.ToolsetReader.ReadAllToolsets(Dictionary`2 toolsets, ToolsetConfigurationReader configurationReader, PropertyDictionary`1 environmentProperties, PropertyDictionary`1 globalProper
ties, ToolsetDefinitionLocations locations)
at Microsoft.Build.Evaluation.ProjectCollection.InitializeToolsetCollection(ToolsetConfigurationReader configReader)
at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, IEnumerable`1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCo
unt, Boolean onlyLogCriticalEvents, Boolean loadProjectsReadOnly, Boolean useAsynchronousLogging)
at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties)
at Microsoft.CodeAnalysis.MSBuild.Build.ProjectBuildManager.StartBatchBuild(IDictionary`2 globalProperties)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadAsync(CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadProjectInfoAsync(String projectFilePath, ProjectMap projectMap, IProgress`1 progress, ILogger msbuildLogger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenProjectAsync(String projectFilePath, ILogger msbuildLogger, IProgress`1 progress, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
LSP[csharp_ls][Log] csharp-ls: OK, 1 project files loaded
Non of the lsp commands work
I found emacs-lsp/lsp-mode#3198 and #3
But I feel the issue should be fixed after those issues
I am on the latest version of csharp-ls
I am on the correct version of dotnet (6) Like I said it suddenly stopped working (I probably did a sudo apt upgrade
)
I feel like I am missing something obvious but I cannot seem to find the issue here
I think I would better also mention this here. I am confused.. Before 0.7 it works well. I cannot figure out how it comes.
neovim/neovim#18147
When I do "gi" which is mapped to vim.lsp.buf.implementation nothing happens, there is a way to debug this?? I see no errors but my cursor is not moving to the class where that method is implemented, declaration goes fine but in C# projects it's often used Interfaces so I get stuck there.
Hello! Possibly related to #33.
I had to install the x64 distributions of the .NET SDK for things to work. It was weird because csharp-ls
was not crashing when I ran it from the CLI, but it would hang in Emacs.
Once the x64 is installed, don't forget to reconfigure the DOTNET_ROOT
environment variable to /usr/local/share/dotnet/x64
in Emacs.
Consider the following code:
a/Class1.cs
namespace A
{
public class Class1
{
// code
}
}
b/Class2.cs
namespace B
{
public class Class2
{
var instance = new Class1();
}
}
Then put your cursor on Class1()
and invoke M-x lsp-execute-code-action
in Emacs, or similar action in other editor.
Observed that
You will be provided several different options:
(Screenshot for demonstrationg-purposes. Does not match example code 1-to-1)
Expected that
Generally, in my experience, some actions are almost always "more" preferred than others.
In this particular case I almost always want to have using
-statements as first suggestion, explicit-namespacing as second and create new class as third and expect to find code-fixes in that order.
Does the LSP protocol provide any sort of ... priority for the code actions or is it up to the LSP-client itself to determine how to present them?
The README clearly states:
csharp-ls
unapologetically requires .NET 6 SDK to work and (probably) does not support .NET 3/4.x projects (.NET Framework)
Just wanted to let you know that I've now tested the latest csharp-ls
and it works just fine with projects in other .NET Core versions (3.x, 5.0).
I even tried it on some regular .NET Framework projects (.net 4.8) with SDK-format CSPROJ-files, and that worked fine too.
So yeah... Now you know. Feel free to update the README based on that info... Or don't ๐
Is code formatting on the roadmap? Its the one thing I miss from omnisharp-roslyn
This is a kinda of ... opaque bug, I know, but I just recently rebuild my Emacs from latest git sources with "everything" enabled:
cd build/emacs
git checkout master
git pull
make distclean
./configure --with-imagemagick --with-json ^Cwith-native-compilation --with-xwidgets -with-xinput2
make -j6
I've nuked my $HOME/.emacs.d/elpa
and reinstalled all packages.
And now everything works nicely... Except csharp-ls
.
That is, other lsp-mode
backends seems to work correctly (even omnisharp
!), but csharp-ls
fails to start and never provides any completions or anything. I've reinstalled csharp-ls
(0.1.8) but to no avail. I've also tried downgrading to 0.1.7, but with no difference in behaviour.
So so far, the only significant change seems to be my Emacs build itself.
Could this be an issue with csharp-ls
? Could this be an issue with how csharp-ls
is registered/used in lsp-csharp
? Anyone have any ideas?
Can anyone else reproduce this at all? ๐
Hi, first of all thank you for your amazing work! I am really loving it! Today, I upgrade dotnet to 6.0.100, unfortunately I didn't find csharp_ls server working as it supposed to be, in contrast it working like a charm before dotnet upgrade.
I haven't been able to find a workaround except downgrading dotnet. Do you have any clues?
client:
[START][2021-11-09 09:54:51] LSP logging initiated
[ERROR][2021-11-09 09:54:52] .../vim/lsp/rpc.lua:412 "rpc" "csharp-ls" "stderr" "It was not possible to find any compatible framework version\nThe framework 'Microsoft.NETCore.App', version '5.0.0' (arm64) was not found.\n - The following frameworks were found:\n 6.0.0 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]\n\nYou can resolve the problem by installing the specified framework and/or SDK.\n\nThe specified framework can be found at:\n - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=arm64&rid=osx.11.1-arm64\n"
[ERROR][2021-11-09 09:55:05] .../vim/lsp/rpc.lua:412 "rpc" "csharp-ls" "stderr" "It was not possible to find any compatible framework version\nThe framework 'Microsoft.NETCore.App', version '5.0.0' (arm64) was not found.\n - The following frameworks were found:\n 6.0.0 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]\n\nYou can resolve the problem by installing the specified framework and/or SDK.\n\nThe specified framework can be found at:\n - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=arm64&rid=osx.11.1-arm64\n"
[START][2021-11-09 09:55:52] LSP logging initiated
[ERROR][2021-11-09 09:55:53] .../vim/lsp/rpc.lua:412 "rpc" "csharp-ls" "stderr" "It was not possible to find any compatible framework version\nThe framework 'Microsoft.NETCore.App', version '5.0.0' (arm64) was not found.\n - The following frameworks were found:\n 6.0.0 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]\n\nYou can resolve the problem by installing the specified framework and/or SDK.\n\nThe specified framework can be found at:\n - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=arm64&rid=osx.11.1-arm64\n"
[START][2021-11-09 09:57:26] LSP logging initiated
If I create a cs file in neovim(with Neotree), csharp-ls will print "No parent project could be resolved to add file" message.
It looks like changed "E:" to "e%3A" and fail to read. But it will read succeed by quit and restart neovim. I don't know why.
How do I fix it? This problem will cause lsp feature failed.
Hi !
I may have missed something but I feel like currently there is no way to handle Release/Debug configurations.
The main point of this request is for stuff like #if DEBUG
.
I'm using this language server with NeoVim (lspconfig / csharp-ls) and it behaves only as a debug configuration. Looking into the code of this repository, I can't find an option to change the build configuration.
Is this something I've missed or is it not implemented ?
Hi, thanks for the great project!
I'm having issues with exclusion of some directories. I'm using direnv (with nix on linux)
which puts, in the project directory, a .direnv
directory where cached files are stored. It stores there *.sln
and *.csproj
files, too. Which is a problem, since csharp-ls detects them and thinks that there is a solution in there.
Currently, I'm using a custom patch to deal with this issue, but I was thinking maybe there is a better solution.
Does csharp-ls have a generic mechanism for exclusion of certain directories?
I presume it doesn't, because there is a hardcoded exclusion of node_modules
directory. Should csharp-ls provide this generic mechanism?
In case you might need it, here is the patch:
diff --git a/src/CSharpLanguageServer/RoslynHelpers.fs b/src/CSharpLanguageServer/RoslynHelpers.fs
index 2cd6c9c..68f5e53 100644
--- a/src/CSharpLanguageServer/RoslynHelpers.fs
+++ b/src/CSharpLanguageServer/RoslynHelpers.fs
@@ -865,9 +865,15 @@ let findAndLoadSolutionOnDir logMessage dir = async {
|> Seq.contains "node_modules"
|> not
+ let fileNotOnDotDirenv (filename: string) =
+ filename.Split(Path.DirectorySeparatorChar)
+ |> Seq.contains ".direnv"
+ |> not
+
let solutionFiles =
Directory.GetFiles(dir, "*.sln", SearchOption.AllDirectories)
|> Seq.filter fileNotOnNodeModules
+ |> Seq.filter fileNotOnDotDirenv
|> Seq.toList
logMessage (sprintf "%d solution(s) found: [%s]" solutionFiles.Length (String.Join(", ", solutionFiles)) )
See example below:
The cursor is on a call to the Url.Action(string action, string controller, object values)
overload.
The documentation provided seems to be for this overload and is quite good.
The expanded parameter-list however is very confusing because:
As a user I would expect the following order:
Are there any particular reason the parameters are currently presented as they are?
When I opend a cs file, it prints so many information and need I press key to display them.
Is it meens some problem happend? If not, it's so inconvenient:
This is the config in my coc config file:
{
"languageserver": {
"csharp-ls": {
"command": "csharp-ls",
"filetypes": ["cs"],
"rootPatterns": ["*.csproj", ".vim/", ".git/", ".hg/"]
}
}
}
I have a .sln that consists multiple .csproj
But whenever i load a single .cs file, it attempts to find the .csproj but won't understand other connected .csproj within the solution. How do make it work?
I dont think document formatting picks up the .editorconfig. is this planned? I could take a stab at it
Apologies if this doesn't belong to csharp-ls, but I have no idea where to start looking and would appreciate any hints.
I'm trying to get Unity projects to work with Emacs and LSP, and I've gotten to a point where csharp-ls is starting, clearly understands the project and offers type information and references. However, I'm only getting completions for method names. So, instead of tabbable variable placeholders such as (typing "foo.")
foo.MyMethod(int bar)
it only offers
foo.MyMethod
The full method signature is shown in the echo area when I move over it, so the issue seems to be on the completion side.
The good old obsolete omnisharp-mode has been working perfectly in the same project. I'm testing this with Emacs 28.1, csharp-ls 0.4.3 and the latest lsp-mode from MELPA. lsp-mode is using the default :capf as the completion provider.
Hi there,
Thanks for your work! It's very nice and addressed the annoying metadata
of ' omnisharp-roslyn
.
Here's my issue:
When I try to run csharp-ls
on my M1 Chip with 'dotnet` at 6.0.103.
I run as: $HOME/.dotnet/tools/csharp-ls --loglevel log -s $HOME//csharp/src/setup/setup.sln
There isn't any log string printed.
Is there a preferred .Net version for csharp-ls
? Or I'm missing something else.
Workspace Symbol works perfectly by showing the signature, but Document Symbol doesn't. It can be confusing because of methods overloads, so it would be nice if the Name of the symbol included the signature.
I'm using archlinux and dotnet has been updating. Even if I install dotnet-sdk-6.0 (v 6.0.11) I get the following error.
"rpc" "csharp-ls" "stderr" "You must install or update .NET to run this application.
App: /home/jlaunay/.local/share/nvim/mason/packages/csharp-language-server/csharp-ls
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (x64)
.NET location: /usr/share/dotnet
The following frameworks were found:
7.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x64&rid=arch-x64
# /usr/share/dotnet/dotnet --list-sdks
6.0.111 [/usr/share/dotnet/sdk]
7.0.100 [/usr/share/dotnet/sdk]
I'm trying to use coc.nvim with C#, and this appears to be new only supported LSP.
I'm on linux and I have the latest Mono SDKs and .NET core 5 & 6 installed, but I'm getting this when trying to use csharp-ls:
lies for .NETFramework,Version=v4.7.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpack
Loaded server for /home/tshannon/workspace/cold/cold.sln in 4.9s
So csharp-ls is running via .net 6, but the solution needs .net 4.7.2 which is supplied via mono. Anyone know how I work around this?
Not sure if this is the fault of csharp-ls
or not, but it seems like a good place to start ๐
Consider the following c# code:
interface IDemo
{
void Foo();
}
class Demo : IDemo
{
void Foo()
{
Console.WriteLine("Bar");
}
}
When positioning the cursor at IDemo
(line 6) and selecting (in Emacs) lsp-find-definition
I'm taken to line 1, where the interface is defined. This makes sense.
However when I use lsp-find-implementation
at IDemo
(line 1), I expect to be given the implementations of that interface (line 6). Instead the behaviour seems to be just like lsp-find-definition
, and I remain at line 1.
Are these two functions implemented the same way inside csharp-ls
? Or is this a lsp-mode
issue? Or have I simply misunderstood something about what the current C# LSP providers are capable of?
First of all, thanks so much for this amazing hack! I've been using it for a few weeks now.
This timeout happens when using lsp-ui-peek-find-definitions
to go into a metadata file but it doesn't happen on regular lsp-find-definition
. Other than the error itself, Emacs also hangs. It seems I can mash C-g to get out of a little earlier.
I'm more than happy to blame something in my config, but I haven't been able to find a workaround so far. Do you have any clues?
When I attempt to us go to definition, I get the following error:
Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1047: Cursor position outside buffer
stack traceback:
[C]: in function 'nvim_win_set_cursor'
/usr/share/nvim/runtime/lua/vim/lsp/util.lua:1047: in function 'jump_to_location'
/usr/share/nvim/runtime/lua/vim/lsp/handlers.lua:345: in function 'handler'
/usr/share/nvim/runtime/lua/vim/lsp.lua:1173: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
Im on paternity leave starting Wednesday so ill pick up implementing code generator support unless its already in progress
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.