-
Notifications
You must be signed in to change notification settings - Fork 8
Add Support for Roslyn LSP (Csharp Language Server) #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
CC @fminkowski, @dibarbet, @CyrusNajmabadi, and @maxbrunsfeld since they were involved in the initial implementation of the Zed C# extension and thus might or might not have thoughts |
Seems like I made that PR to early... I did try Completion, Code Action etc.
Via intercepting the notification and adding it, but that did not work. So I think here we need the support from the Zed Team. |
I also get no diagnostics. A simple way to reproduce is overriding the path for omnisharp:
Do you know if zed supports pull diagnostics? |
I do not, but my guess at the moment seems no. Just tried dotrush to see if the diagnostics are working with that, but its the same. No Diagnostics |
ruby configuration states that pull diagnostics are not supported, under setting up |
You are right, here is the issue tracking that: zed-industries/zed#13107 |
The tool only utilises code from Roslyn which is licensed under MIT Licence. It does do use anything from C# DevKit. C# DevKit utilises the same underlying language server from Roslyn, |
@SofusA was quicker to respond. And that is true, the server uses the |
Co-authored-by: Dylan Hackworth <[email protected]>
Ah okay looks like a misinterpretation of csharp-language-server and the DevKit license. Love it so far! Great work. |
@Digni any chance that this can be run alongside omnisharp? to have the diagnostics. Right now the omnisharp ls doesn't work when decompiling sources (go to definition) |
Yeah, Zed supports running several lsp's for one language. "languages": {
"CSharp": {
"language_servers": ["roslyn", "omnisharp", "..."]
}
} But as written in the ruby extension (https://zed.dev/docs/languages/ruby) they would provide similar functionality. So we probably need to turn off autocompletion, code-actions from omnisharp. https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options I did not look into that yet. |
@Digni i tried this but I couldn't make the go to definition with decompiling work. Do you know if that should work? E.g go to the definition of a installed package |
I get working decompiling using the the config mentioned in my previous comment. |
I did just test it and go-to definition works for me with decompilation (using the updated extension). In this case it would be best if we could ask the user which solution to open, but that seems not possible at the moment with the extension api. @SofusA We could maybe follow the method used by DotRush and pass options along to the language server which contains the path to the solution. The user could provide this in the project specific settings. "roslyn": {
// Paths to project or solution files to load
"projectOrSolutionFiles": [
"/path/to/your/solution.sln"
]
} |
Hmm this does sound weird. The solution file is searched for from the directory that the
I have just added a release which provide arguments for specifying solution or project paths. |
Hey, sorry for the late reply. |
Hey, But it is working as is and we could merge it, while this update is done separately. |
Alright, I'm unfortunately OOO soon and got some other stuff on my list but I'll do my best to get back to you regardless over the next few days/weeks so we can have this merged sooner than later. I'll leave some comments in the code as well, the biggest question I have prior to merging is regarding the LSP settings part:
Not insisting, you have more context here and I might also be missing something, but could we do it any better than this? Especially, if I am to understand this corrrectly, this is needed for inlay hints to work, right? Can we
Regarding the
IIRC we have this issue for some other LSPs currently and I believe there is some ongoing work in the core to better tackle this. Ultimatively, I think this should be easy to do with the extension API. Let's skip it for now and revisit this later once the work is completed there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, overall looks good, just some style and other minor concerns.
src/language_servers/roslyn.rs
Outdated
let asset_name = format!( | ||
"csharp-language-server-{arch}-{os}.{extension}", | ||
os = match platform { | ||
zed::Os::Mac => "apple-darwin", | ||
zed::Os::Linux => "unknown-linux-gnu", | ||
zed::Os::Windows => "pc-windows-msvc", | ||
}, | ||
arch = match arch { | ||
zed::Architecture::Aarch64 => "aarch64", | ||
zed::Architecture::X8664 => "x86_64", | ||
zed::Architecture::X86 => "unsupported", | ||
}, | ||
extension = match platform { | ||
zed::Os::Mac | zed::Os::Linux => "tar.gz", | ||
zed::Os::Windows => "zip", | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious - for which operating systems did you test this? Just so I can take a look at the other systems if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for mac with arch. I don't have a set up linux system right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, thanks for the information. I'll make sure to test it on the other platforms just to be sure.
That is a valid point, but as commented this is kinda how the Roslyn LSP expects its configuration. IMO the defaults of roslyn are quite good as is. This is really only for the inline/inlay hints to work. |
Co-authored-by: Finn Evers <[email protected]>
Suggestion for dedup Co-authored-by: Finn Evers <[email protected]>
Co-authored-by: Finn Evers <[email protected]>
If you have the time and are willing to take another look in that regard, I'd highly appreciate it. Ultimately, I'd just like to make it as easy for users as possible. I think it is fine if we increase the maintenance burdon slightly in general if that increases usability a lot - it's obviously Microsoft's fault, but I'd like if we find a way to not directly throw this at users and at least try to make it just a bit better. At least, better documentation both in the official docs and in this repo would already be a good start if we don't find any better solution.
Failed to explain myself here, I guess, sorry for that - what I meant is that optimally I'd like inlay hints to also work out of the box without any additional configuration. Also, thanks a lot for following up that quickly! Edit: And sorry for mistyping on the suggestion! 😅 |
How about using these inlay settings as the default. If the user decides to add a custom config, his config will take precedence. |
I think this sounds like a sensible and the most straightforward approach - feel free to go forward with this. Please also note that I'll now be OOO as mentioned for about two weeks (technically I already am OOO right now, but given your fast follow up, I decided to give a quick reply) so there might be a slight delay in responses from me from now on. That said, if you have time and interest to play around with this some more beyond this approach, feel free to and I'll take a look! I'll make Roslyn the default for C# once this is in. Especially with official Windows support just around the corner, I wanna make sure that we hit the mark with this once it's merged. |
Okay, will see what I can do. |
Thank you! 🙂 |
Hey, checking back in - how are things looking? Did you find time to play with different approaches or do we just wanna go with the "inlay hints enabled by default" route for now? I don't wanna bother you too long with this (really thankful for you getting this up and ready in the first place), so if you prefer, let's just get this ready to be merged and follow up with anything we find later. |
@MrSubidubi With the amount of value this provides in comparison to the other C# LSP we should have it shipped and then worry about breaking changes in the next major version of the plugin. |
This adds support for the (newer) Roslyn LSP from Microsoft (Microsoft.CodeAnalysis.LanguageServer).
The current Implementation is using a wrapper provided by: https://github.com/SofusA/csharp-language-server.
This is because the Roslyn LSP expects one of the following notifications after "initialize":
The
csharp-language-server
reacts on the initialize notification to get the working directory and then scans it for solution and project files.If it finds a solution file it picks the first one it finds, this could lead to some unintended reference issues if there are more than one solution file in the working directory.
The VsCode Extension handles this by asking the user which solution should be opened.
I would like to implement something similar and run the roslyn lsp directly (
dotnet Microsoft.CodeAnalysis.LanguageServer.dll
).But for that to work I need to be able to send these notifications to the lsp server (and if possible ask the user which solution he wants to open) and I currently don't know how this would be possible with the extension api.
Maybe someone could help me with that.
Update
Added Workspace Configuration Options for Roslyn lsp.
Server expects the following format:
{language}|{grouping}.name
for language specific options or{grouping}.{name}
for general options.Example
In the settings json I made it nested:
This will get translated to the valid format described above.
Which leads to something like this (configured inlay_hints):