From 285d0dd579372de25305de0869ef559181f14bb8 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Mon, 25 Nov 2024 15:31:48 -0800 Subject: [PATCH] Add back null check to allow merge editor to load This change adds a null check to ProjectCapabilityResolver.ContainingProjectHasCapability(...) that was incorrectly removed by 6cd5bd4ba6fe57dee7454e8b4d6a33ddaea5514b. Without this null check, it is impossible to open a merge editor for a razor or cshtml file. The merge editor has a few editors within it, and some of them are not included in a project, so they have a null IVsHIerarchy. --- .../ProjectCapabilityResolver.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectCapabilityResolver.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectCapabilityResolver.cs index f80724946f..e86b92c603 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectCapabilityResolver.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectCapabilityResolver.cs @@ -111,6 +111,15 @@ internal sealed class ProjectCapabilityResolver : IProjectCapabilityResolver, ID return false; } + // vsHierarchy can be null here if the document is not included in a project. + // In this scenario, the IVsUIShellOpenDocument.IsDocumentInAProject(..., ..., ..., ..., out int pDocInProj) call succeeds, + // but pDocInProj == __VSDOCINPROJECT.DOCINPROJ_DocNotInProject. + if (vsHierarchy is null) + { + _logger.LogWarning($"LSP Editor is not supported for file because it is not in a project: {documentFilePath}"); + return false; + } + try { return vsHierarchy.IsCapabilityMatch(capability);