FsAutoComplete icon indicating copy to clipboard operation
FsAutoComplete copied to clipboard

LSP requests fail with `null` when project uses the .net 6.0.100 SDK

Open razzmatazz opened this issue 2 years ago • 10 comments

Please see:

  • https://github.com/razzmatazz/csharp-language-server/tree/downgrade-to-dotnet5-for-fsac (works)
  • https://github.com/razzmatazz/csharp-language-server (fails)

The change that triggers the issue is:

diff --git a/global.json b/global.json                                                                                                                                                        
index 45fe540..3990743 100644                                                                                                                                                                 
--- a/global.json                                                                                                                                                                             
+++ b/global.json                                                                                                                                                                             
@@ -1,6 +1,6 @@                                                                                                                                                                               
 {                                                                                                                                                                                            
     "sdk": {                                                                                                                                                                                 
-        "version": "5.0.403",                                                                                                                                                                
+        "version": "6.0.100",                                                                                                                                                                
         "rollForward": "major"                                                                                                                                                               
     }                                                                                                                                                                                        
 }                                                                                                                                                                                            

When the project uses 6.0.100 I get this on lsp (all requests return null):

[Trace - 11:01:58 ] Sending request 'textDocument/codeAction - (208)'.                                                                                                                        
Params: {                                                                                                                                                                                     
  "textDocument": {                                                                                                                                                                           
    "uri": "file:///home/bob/src/csharp-language-server/src/CSharpLanguageServer/RoslynHelpers.fs"                                                                                            
  },                                                                                                                                                                                          
  "range": {                                                                                                                                                                                  
    "start": {                                                                                                                                                                                
      "line": 143,                                                                                                                                                                            
      "character": 6                                                                                                                                                                          
    },                                                                                                                                                                                        
    "end": {                                                                                                                                                                                  
      "line": 143,                                                                                                                                                                            
      "character": 6                                                                                                                                                                          
    }                                                                                                                                                                                         
  },                                                                                                                                                                                          
  "context": {                                                                                                                                                                                
    "diagnostics": []                                                                                                                                                                         
  }                                                                                                                                                                                           
}                                                                                                                                                                                             
                                                                                                                                                                                              
                                                                                                                                                                                              
[Trace - 11:01:58 ] Sending request 'textDocument/documentHighlight - (209)'.                                                                                                                 
Params: {                                                                                                                                                                                     
  "textDocument": {                                                                                                                                                                           
    "uri": "file:///home/bob/src/csharp-language-server/src/CSharpLanguageServer/RoslynHelpers.fs"                                                                                            
  },                                                                                                                                                                                          
  "position": {                                                                                                                                                                               
    "line": 143,                                                                                                                                                                              
    "character": 6                                                                                                                                                                            
  }                                                                                                                                                                                           
}                                                                                                                                                                                             
                                                                                                                                                                                              
                                                                                                                                                                                              
[Trace - 11:01:58 ] Received response 'textDocument/hover - (207)' in 83ms.                                                                                                                   
Result: null                                                                                                                                                                                  
                                                                                                                                                                                              
                                                                                                                                                                                              
[Trace - 11:01:59 ] Received response 'textDocument/codeAction - (208)' in 443ms.                                                                                                             
Result: null                                                                                                                                                                                  
                                                                                                                                                                                              
                                                                                                                                                                                              
[Trace - 11:01:59 ] Received response 'textDocument/documentHighlight - (209)' in 515ms.                                                                                                      
Result: null                                                                                                                                                                                  

Please tell me if I should investigate further

razzmatazz avatar Nov 28 '21 09:11 razzmatazz

Hey, it seems to be working for me: image

Are there any specific actions that make it crash or anything like that?

Krzysztof-Cieslak avatar Nov 29 '21 16:11 Krzysztof-Cieslak

ok, here is lsp conversation log.. I can't quiet grasp what is failing there, there is no crash trace and it seems to be alive at the begining and initializes ok.. however, at some point the server throws the towel and starts responding with null.. :)

fsac-log.txt

will check with ionide (currently I only have linux machines at hand and.. probably misconfigured by me(?) by installing several sdks at once -- will try to remove .net 5 sdk, and will leave .net 6

razzmatazz avatar Nov 29 '21 19:11 razzmatazz

ionide seems to be running fine on the same machine :+1: -- will try to debug what causes the issue on my machine for my lsp/emacs combo

razzmatazz avatar Nov 29 '21 19:11 razzmatazz

ok, removing .net 5 sdks (i had multiple installed) has helped, things work with just .net6 sdk installed:

[bob@fedora csharp-language-server]$ dotnet --list-sdks
6.0.100 [/home/bob/.dotnet/sdk]

after installing 5.0.403:

[bob@fedora csharp-language-server]$ dotnet-install.sh -v 5.0.403
dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.

dotnet-install: Downloading primary link https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.403/dotnet-sdk-5.0.403-linux-x64.tar.gz

dotnet --list-sdks
dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/5.0.403/dotnet-sdk-5.0.403-linux-x64.tar.gz
dotnet-install: Adding to current process PATH: `/home/bob/.dotnet`. Note: This change will be visible only when sourcing script.
dotnet-install: Note that the script does not resolve dependencies during installation.
dotnet-install: To check the list of dependencies, go to https://docs.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
dotnet-install: Installation finished successfully.
[bob@fedora csharp-language-server]$ 
[bob@fedora csharp-language-server]$ dotnet --list-sdks
5.0.403 [/home/bob/.dotnet/sdk]
6.0.100 [/home/bob/.dotnet/sdk]

..things broke again (I did read what the dotnet-install.sh script is suggesting to me, it's just it has worked well for me.. until now :) )


so to confirm, fsac somehow gets confused when there are both .net5+6 sdks installed, at least on my dev environment (fedora/linux)

@Krzysztof-Cieslak feel free to close this

razzmatazz avatar Nov 29 '21 20:11 razzmatazz

Reopening because @Gastove reported this on FSSF slack - what would be interesting in verbose FSAC logs (not just LSP protocol logs) from a situation where this occurs. it seems like the server itself is starting, but the message read loop is not working? also worth checking out with @razzmatazz's StreamJsonRpc work.

baronfel avatar Jan 17 '22 19:01 baronfel

OK, I got too frustrated with fsac not working with multiple SDKs installed and apparently the cause (for me) was that fsac/underlying libs do not recognize it when global.json is somewhere up the project tree and not on the root -- then it seems to ignore it for the project and the default (latest) SDK is used.

FYI, this is what fixed it for me:

  • https://github.com/razzmatazz/csharp-language-server/commit/78dcc6818a79c4af7384da357544afbcce4af9e6
  • the commit has multiple changes but the move of global.json to the root dir of the project fixes it

this behaviour is a bit different to how std C# projects behave where they (msbuild?) use the "closest" global.json down the project tree, not only the one at the root.. but it could also be related to how LSP works/which path is provided as root for the project; -- emacs-lsp uses git root as pwd for the LSP server (where available)

razzmatazz avatar Jun 19 '22 17:06 razzmatazz

How do you get a consistent SDK if your probing location varies per project? What you're describing sounds like a very confusing UX to me.

baronfel avatar Jun 19 '22 17:06 baronfel

I am not sure about how this can be represented on the UI in IDE, but I suspect this ability to have multiple global.json on subdirectories is supported on C# land so we can have monorepos with multiple unrelated projects having different SDKs/runtimes configured (we do this at our company too)

This ability to look for "closest" global.json is documented here:

  • https://docs.microsoft.com/en-us/dotnet/core/tools/global-json, in particular see the quote:
  • "The .NET SDK looks for a global.json file in the current working directory (which isn't necessarily the same as the project directory) or one of its parent directories."

razzmatazz avatar Jun 19 '22 18:06 razzmatazz

I'm very familiar with the global.json lookup algorithm, I mostly mean how should an IDE choose what the 'root' to spawn dotnet commands from should be? If a user types 'code .' from inside a project directory, then the IDE starts with a workspace of that project directory. But if I start a workspace from a solution level, or a top level folder, I have no idea what the root should be aside from that top level directory.

This is perhaps a place where we should fix the gaps in FSAC/Ionide's treatment of the LSP workspace concept - if we did that then the workspaces could be declared in that and we could use the LSP WorkspaceRoots as that starting point?

baronfel avatar Jun 19 '22 18:06 baronfel

I'm afraid I don't have an answer to the question how to resolve project root given we launch code . at some path.. but maybe this is a separate question from the question if f# tooling should consider global.json only at root of the project or hierarchically on the project tree?

razzmatazz avatar Jun 20 '22 05:06 razzmatazz

I am not getting this anymore. Closing

Although https://github.com/ionide/ionide-vscode-fsharp/issues/1758 sounds very much related, but could be another thing.

razzmatazz avatar Aug 26 '22 19:08 razzmatazz