dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.82k stars 773 forks source link

AddReturnType refactoring occasionally throws #16844

Open psfinaki opened 3 months ago

psfinaki commented 3 months ago

I cannot come up with a definitive repo but this sometimes happens when I just copy a file in the solution explorer.

Here is the stack trace:

System.Exception : The file 'C:\code\fsharp3\tests\benchmarks\FCSBenchmarks\CompilerServiceBenchmarks\GraphTypeCheckingBenchmarks - Copy.fs' was not part of the project. Did you call InvalidateConfiguration when the list of files in the project changed?
   at FSharp.Compiler.CodeAnalysis.IncrementalBuilder.GetSlotOfFileName(String fileName)
   at <StartupCode$FSharp-Compiler-Service>.$BackgroundCompiler.ParseAndCheckFileInProject@919-3.Invoke(FSharpOption`1 cachedResults)
   at FSharp.Compiler.BuildGraph.Bind@63-1.Invoke(T x)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt,b result1,FSharpFunc`2 userCode)
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions.CheckerExtensions.FSharpChecker-ParseAndCheckDocumentWithPossibleStaleResults@388-3(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions.CheckerExtensions.FSharpChecker-ParseAndCheckDocumentWithPossibleStaleResults@378(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions.CheckerExtensions.FSharpChecker-ParseAndCheckDocument@449(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions.Document-GetFSharpParseAndCheckResultsAsync@539(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async StartupCode$FSharp-Editor(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.<>c__DisplayClass12_0.<GetRefactoringFromProviderAsync>b__0(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
kerams commented 3 months ago

Every time I create a new fs file (Add above - Add new item).

vzarytovskii commented 3 months ago

This likely happens because project system doesn't send us new command line options fast enough and we ask for tc results for file which is not in the project yet.

psfinaki commented 3 months ago

Every time I create a new fs file (Add above - Add new item).

Hah indeed, as easy as that, thanks.

The way I usually add files to the project is that I copypaste an existing file (I don't know why actually) - and that doesn't throw, or at least doesn't throw in the repeatable fashion.