diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 777215a3e83..b50277c019b 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -346,7 +346,7 @@ type internal HackCpsCommandLineChanges /// This handles commandline change notifications from the Dotnet Project-system /// Prior to VS 15.7 path contained path to project file, post 15.7 contains target binpath /// binpath is more accurate because a project file can have multiple in memory projects based on configuration - member _.HandleCommandLineChanges(path:string, sources:ImmutableArray, _references:ImmutableArray, options:ImmutableArray) = + member _.HandleCommandLineChanges(path:string, sources:ImmutableArray, references:ImmutableArray, options:ImmutableArray) = use _logBlock = Logger.LogBlock(LogEditorFunctionId.LanguageService_HandleCommandLineArgs) let projectId = @@ -363,5 +363,11 @@ type internal HackCpsCommandLineChanges let sourcePaths = sources |> Seq.map(fun s -> getFullPath s.Path) |> Seq.toArray - let workspaceService = workspace.Services.GetRequiredService() - workspaceService.FSharpProjectOptionsManager.SetCommandLineOptions(projectId, sourcePaths, options) + /// Due to an issue in project system, when we close and reopen solution, it sends the CommandLineChanges twice for every project. + /// First time it sends a correct path, sources, references and options. + /// Second time it sends a correct path, empty sources, empty references and empty options, and we rewrite our cache, and fail to colourize the document later. + /// As a workaround, until we have a fix from PS or will move to Roslyn as a source of truth, we will not overwrite the cache in case of empty lists. + + if not (sources.IsEmpty && references.IsEmpty && options.IsEmpty) then + let workspaceService = workspace.Services.GetRequiredService() + workspaceService.FSharpProjectOptionsManager.SetCommandLineOptions(projectId, sourcePaths, options)