Skip to content

Commit f3b516a

Browse files
KevinRansomvzarytovskiipsfinaki
authored
Workaround for emptying FSharp.Editor cache due to duplicate ProjectSystem events (#13313) (#13396)
Co-authored-by: Petr Semkin <psfinaki@users.noreply.github.com> Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com> Co-authored-by: Petr Semkin <psfinaki@users.noreply.github.com>
1 parent cc7016a commit f3b516a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ type internal HackCpsCommandLineChanges
346346
/// This handles commandline change notifications from the Dotnet Project-system
347347
/// Prior to VS 15.7 path contained path to project file, post 15.7 contains target binpath
348348
/// binpath is more accurate because a project file can have multiple in memory projects based on configuration
349-
member _.HandleCommandLineChanges(path:string, sources:ImmutableArray<CommandLineSourceFile>, _references:ImmutableArray<CommandLineReference>, options:ImmutableArray<string>) =
349+
member _.HandleCommandLineChanges(path:string, sources:ImmutableArray<CommandLineSourceFile>, references:ImmutableArray<CommandLineReference>, options:ImmutableArray<string>) =
350350
use _logBlock = Logger.LogBlock(LogEditorFunctionId.LanguageService_HandleCommandLineArgs)
351351

352352
let projectId =
@@ -363,5 +363,11 @@ type internal HackCpsCommandLineChanges
363363

364364
let sourcePaths = sources |> Seq.map(fun s -> getFullPath s.Path) |> Seq.toArray
365365

366-
let workspaceService = workspace.Services.GetRequiredService<IFSharpWorkspaceService>()
367-
workspaceService.FSharpProjectOptionsManager.SetCommandLineOptions(projectId, sourcePaths, options)
366+
/// Due to an issue in project system, when we close and reopen solution, it sends the CommandLineChanges twice for every project.
367+
/// First time it sends a correct path, sources, references and options.
368+
/// 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.
369+
/// 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.
370+
371+
if not (sources.IsEmpty && references.IsEmpty && options.IsEmpty) then
372+
let workspaceService = workspace.Services.GetRequiredService<IFSharpWorkspaceService>()
373+
workspaceService.FSharpProjectOptionsManager.SetCommandLineOptions(projectId, sourcePaths, options)

0 commit comments

Comments
 (0)