ionide / ionide-vscode-fsharp

VS Code plugin for F# development
http://ionide.io
MIT License
858 stars 277 forks source link

Resolving Nuget references unreliable in .fsx files when starting VS Code #2005

Closed beyon closed 5 months ago

beyon commented 5 months ago

Describe the bug

When opening workspaces with .fsx files open in VS Code I often get

The namespace or module 'packagename' is not defined

for packages referenced with

r "nuget: packagename"

Running the Developer: Reload Window command from the Command Palette can make the error go away after one or more attempts.

I just noticed that having multiple (as little as two) different .fsx files open in split editor (both files visible at the same time) makes it much more frequent, to the point of one file/editor causing an error almost every time. Not entirely sure I was seeing the same issue without split editor, I thought I was but it seems hard to reproduce so could be I'm just imagining.

Steps to reproduce

Create two .fsx files both referencing some nuget packages. View: Split Editor command from Command Palette or keyboard shortcut Arrange so both files are open/visible at the same time in the different halves of the editor. Developer: Reload Window command from the Command Palette (or close and restart VS Code opening the same workspace) On my machine one of the files will fail to resolve the dependency (almost?) every time.

bild

Expected behavior

Dependencies resolving for script files upon starting VS Code (or reloading window) even if multiple editors and files are open.

Workaround

Make sure only one .fsx file is open and visible in workspace. Reload window until it works.

Machine infos

TheAngryByrd commented 5 months ago

Thank you for a good repro! I've had this happen so often but difficult to see it repro it was difficult to find time to try to fix it.

TheAngryByrd commented 5 months ago

I added https://github.com/ionide/FsAutoComplete/pull/1248 a bit ago to help diagnose this and I end up with:

C:\Program Files\dotnet\sdk\8.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1004: Assets file 'C:\Users\jimmy.packagemanagement\nuget\Projects\251972--31cbe924-5124-4242-968f-17358f43591c\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Users\jimmy.packagemanagement\nuget\Projects\251972--31cbe924-5124-4242-968f-17358f43591c\Project.fsproj]F#

I'm guessing there's some restore not happening on F# Compiler Service side, probably can't handle parallel requests.

beyon commented 5 months ago

@TheAngryByrd I'm glad that my repro was helpful and great work in solving the issue so quickly!