Skip to content

Commit 22c8394

Browse files
Add an assert to check that things ended up how we expected
I'm doing an assert here rather than throwing because although this is an expectation, I don't imagine anything will be terribly wrong for the user if it's violated. But throwing would definitely make things bad.
1 parent d10097e commit 22c8394

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectLoader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ private async Task<bool> ReloadProjectAsync(ProjectToLoad projectToLoad, ToastEr
281281
await primordialProjectFactory.ApplyChangeToWorkspaceAsync(workspace => workspace.OnProjectRemoved(projectId), cancellationToken);
282282
}
283283

284+
// At this point we expect that all the loaded projects are now in the project factory returned, and any previous ones have been removed.
285+
// this is a Debug.Assert() because if this expectation fails, the user's probably still in a state where things will work just fine;
286+
// throwing here would mean we don't remember the LoadedProjects we created, and the next update will create more and things will get really broken.
287+
Debug.Assert(newProjectTargets.All(target => target.ProjectFactory == projectFactory));
284288
_loadedProjects[projectPath] = new ProjectLoadState.LoadedTargets(newProjectTargets);
285289
}
286290

0 commit comments

Comments
 (0)