razzmatazz / csharp-language-server

Roslyn-based LSP language server for C#
MIT License
577 stars 38 forks source link

Dotnet 8 #121

Closed BeauCranston closed 4 months ago

BeauCranston commented 10 months ago

Hopefully this is a quick and easy change but it would be nice to start working with new dotnet 8 projects

anthonwellsjo commented 10 months ago

Came here for this. Yes please đź‘Ť

granitrocky commented 10 months ago

Building locally and just changing the projects' TargetFramework key to net8.0 worked for me.

razzmatazz commented 10 months ago

hey everyone!

sorry for not being able to respond, have a lot of things going in my life

if someone would push a PR i'd gladly test it. especially if it's just platform tfm change

BeauCranston commented 10 months ago

hey everyone!

sorry for not being able to respond, have a lot of things going in my life

if someone would push a PR i'd gladly test it. especially if it's just platform tfm change

I have the changes for dotnet 8 locally. I looked at the dotnet 7 PR and made sure to change the exact same things except for dotnet 8. I would be happy to make a PR but I don't think I have rights to do that

razzmatazz commented 10 months ago

hey everyone!

sorry for not being able to respond, have a lot of things going in my life

if someone would push a PR i'd gladly test it. especially if it's just platform tfm change

I have the changes for dotnet 8 locally. I looked at the dotnet 7 PR and made sure to change the exact same things except for dotnet 8. I would be happy to make a PR but I don't think I have rights to do that

anyone with a github account can submit PR, unless there is something I don't know

or you could paste the patch here inline, unless it's more than 10 kb or so

BeauCranston commented 10 months ago

Didn't realize I had to fork the repo to pull request, first time contributing to an open source project. Pull request should be visible to you now

razzmatazz commented 10 months ago

thank you. I will take a look later to confirm this works for me as well.

voidpointer0 commented 9 months ago

csharp_ls stopped working for me in LunarVim after I installed 8.0 on MacOS. Tried removing Dotnet 8 manually and leaving only 7 and 6, but even afterwards it throws out an error and won't start:

Error executing vim.schedule lua callback: ...w/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/lsp.lua:1308: RPC[Error] code_name = InternalError, message = "System.InvalidOperationException: Fa
iled to find all versions of .NET Core MSBuild. Call to hostfxr_resolve_sdk2. There may be more details in stderr.\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetSdkFromGlobalSettings(String workingDirectory)\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetDotNetBasePaths(String workingDirectory)+MoveNext()\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory)+MoveNext()\
   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext()\
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\
   at Microsoft.FSharp.Collections.SeqModule.IsEmpty[T](IEnumerable`1 source) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\seq.fs:line 851\
   at CSharpLanguageServer.Server.handleInitialize@178-5.Invoke(Unit _arg8) in /home/runner/work/csharp-language-server/csharp-language-server/src/CSharpLanguageServer/Server.fs:line 180\
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 5
28\
   at Ionide.LanguageServerProtocol.Server.sendServerNotification@115-3.Invoke(AsyncActivation`1 ctxt) in /_//src/LanguageServerProtocol.fs:line 115\
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 112"
stack traceback:
        [C]: in function 'assert'
        ...w/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/lsp.lua:1308: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Hoping the update will fix this, as LunarVim + csharp_ls are my main dev tools. Thank you for your work!

BeauCranston commented 9 months ago

csharp_ls stopped working for me in LunarVim after I installed 8.0 on MacOS. Tried removing Dotnet 8 manually and leaving only 7 and 6, but even afterwards it throws out an error and won't start:

Error executing vim.schedule lua callback: ...w/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/lsp.lua:1308: RPC[Error] code_name = InternalError, message = "System.InvalidOperationException: Fa
iled to find all versions of .NET Core MSBuild. Call to hostfxr_resolve_sdk2. There may be more details in stderr.\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetSdkFromGlobalSettings(String workingDirectory)\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetDotNetBasePaths(String workingDirectory)+MoveNext()\
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory)+MoveNext()\
   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext()\
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\
   at Microsoft.FSharp.Collections.SeqModule.IsEmpty[T](IEnumerable`1 source) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\seq.fs:line 851\
   at CSharpLanguageServer.Server.handleInitialize@178-5.Invoke(Unit _arg8) in /home/runner/work/csharp-language-server/csharp-language-server/src/CSharpLanguageServer/Server.fs:line 180\
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 5
28\
   at Ionide.LanguageServerProtocol.Server.sendServerNotification@115-3.Invoke(AsyncActivation`1 ctxt) in /_//src/LanguageServerProtocol.fs:line 115\
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\\a\\_work\\1\\s\\src\\FSharp.Core\\async.fs:line 112"
stack traceback:
        [C]: in function 'assert'
        ...w/Cellar/neovim/0.9.4/share/nvim/runtime/lua/vim/lsp.lua:1308: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Hoping the update will fix this, as LunarVim + csharp_ls are my main dev tools. Thank you for your work!

You don’t need to uninstall dotnet 8. Just create a global.json file in some parent directory above your repo and you cans specify a dotnet version and that will be the “active dotnet version” within the subdirectories of the global.json. Also you can clone the repo in, change the dotnet version and run the lsp locally and it will work.

voidpointer0 commented 9 months ago

You don’t need to uninstall dotnet 8. Just create a global.json file in some parent directory above your repo and you cans specify a dotnet version and that will be the “active dotnet version” within the subdirectories of the global.json. Also you can clone the repo in, change the dotnet version and run the lsp locally and it will work.

So to be clear, here's what I did before I wrote my first message:

{
  "sdk": {
    "version": "7.0.404"
  }
}

But this doesn't change anything, the problem persists.

Could you give me some more info relating to the last sentence/possible solutions? Tried to ask people for help on different Vim discords, but no luck. Would appreciate a more step-by-step answer, if you find the time!

BeauCranston commented 9 months ago

Hmm sounds like something potentially went wrong when you removed the SDK's manually and there's some stuff hanging around. Have you run dotnet --list-sdks to see what comes up?

I would also try reinstalling csharp-ls in lunarvim if you havent already.

BeauCranston commented 9 months ago

The steps to make Dotnet 8 work locally:

Now the global tool csharp-ls is your local copy.

The neovim distro I am using is astronvim but I am sure you can port it to your own distro. Also if you noticed I named the server csharpls instead of csharp-ls, this was so I can know that I am using my local version instead of the one from Mason.

Hopefully this works for you all in the meantime.

If you find yourself having trouble with this solution and want to revert you just need to run dotnet tool uninstall csharp-ls -g, and reinstall through mason again if you use it.

JayLCypher commented 9 months ago

The steps to make Dotnet 8 work locally:

  • Clone/Fork the csharp-ls repo
  • Modify the repo to use dotnet 8 (look at the dotnet 8 branch to see what I changed)

    122

  • uninstall any existing csharp-ls in your tools with dotnet tool uninstall csharp-ls -g
  • if you are using Mason then ensure that csharp-ls is not an installed server in the lsp list
  • in the local csharp-ls repo at /src/CSharpLanguageServer run dotnet pack followed by dotnet tool install csharp-ls -g --add-source .\nupkg

Now the global tool csharp-ls is your local copy.

  • configure your lsp config to use your local copy here is my config:
    
    lsp={
      servers={
          "csharpls"
      },
    config = {
          csharpls = function()
              return {
                  cmd = {"csharp-ls"};
                  filetypes = {"cs", "razor", "csproj", "fs", "fsproj"};
                  root_dir = require("lspconfig").util.root_pattern("_.sln", "_.csproj", "packages.config");
              }
          end,
      },
    },

The neovim distro I am using is astronvim but I am sure you can port it to your own distro. Also if you noticed I named the server csharpls instead of csharp-ls, this was so I can know that I am using my local version instead of the one from Mason.

Hopefully this works for you all in the meantime.

If you find yourself having trouble with this solution and want to revert you just need to run dotnet tool uninstall csharp-ls -g, and reinstall through mason again if you use it.

Adding to this: If you want to use Mason (on Linux), you can go into .local/share/(your_nvim_appname)/mason/packages, delete whatever is in csharp-langauge-server folder and use the command:

dotnet tool install csharp-ls --add-source ./nupkg --tool-path $HOME/.local/share/{your_nvim_appname}/mason/packages/csharp-language-server

That should install your compiled version of csharp_ls to Mason with 8.0 update, following this guide.

Thanks @BeauCranston :)

Zeioth commented 8 months ago

Building locally and just changing the projects' TargetFramework key to net8.0 worked for me.

That doesn't do the trick on my end. Still fails with

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <OutputPath>bin</OutputPath>
    <OutputName>Program</OutputName>
    <OutputType>exe</OutputType>
  </PropertyGroup>
</Project>

With the LSP log error

:LspLog

[ERROR][2024-01-09 19:46:57] .../vim/lsp/rpc.lua:734    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/csharp-ls"    "stderr"    "You must install or update .NET to run this application.\n\nApp: /home/zeioth/.local/share/nvim/mason/packages/csharp-language-server/csharp-ls\nArchitecture: x64\nFramework: 'Microsoft.NETCore.App', version '7.0.0' (x64)\n.NET location: /usr/share/dotnet\n\nThe following frameworks were found:\n  8.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]\n\nLearn more:\nhttps://aka.ms/dotnet/app-launch-failed\n\nTo install missing framework, download:\nhttps://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0&arch=x64&rid=arch-x64&os=arch\n"

Dotnet log:

dotnet --version
8.0.100

C# code example here.

EDIT: On omnisharp everything seems to work as expected.

Tyler-Hoyt commented 8 months ago

Is there any progress on this? I don't want to be on visual studio anymore

anthonwellsjo commented 8 months ago

With the LSP log error

@Zeioth the log error probably indicates that you are still using the net7.0 version of csharp-ls.

Disabling any linter autoinstallation features, and then using JLCypher's suggestion above to point to your net8.0 version worked well for me.

razzmatazz commented 8 months ago

I have just upped v0.11.0 which contains @BeauCranston PR with update to dotnet 8, among other things. May take a couple of minutes to show up:

Zeioth commented 8 months ago

It works ok after the update thanks.

j0of commented 5 months ago

Hi there, I have run into a similar issue where I can't use some .NET 8 (or rather, C# 12) features within my project. For example, using primary constructors will give the error:

The feature 'primary constructors' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

I'm using Neovim with mason, mason-lspconfig, and nvim-lspconfig. I can open a new issue about this if necessary.

razzmatazz commented 4 months ago

@j0of please do! Thank you!

I will close this one