Skip to content

Commit 0c6c9de

Browse files
committed
Don't return a result for an unmappable generated location
1 parent ae22e33 commit 0c6c9de

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/FindAllReferences/RemoteFindAllReferencesService.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Razor.Language;
7+
using Microsoft.AspNetCore.Razor.PooledObjects;
78
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
89
using Microsoft.CodeAnalysis.Razor;
910
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
@@ -30,6 +31,7 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
3031

3132
private readonly IClientCapabilitiesService _clientCapabilitiesService = args.ExportProvider.GetExportedValue<IClientCapabilitiesService>();
3233
private readonly IWorkspaceProvider _workspaceProvider = args.WorkspaceProvider;
34+
private readonly IFilePathService _filePathService = args.ExportProvider.GetExportedValue<IFilePathService>();
3335

3436
protected override IDocumentPositionInfoStrategy DocumentPositionInfoStrategy => PreferAttributeNameDocumentPositionInfoStrategy.Instance;
3537

@@ -86,6 +88,8 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
8688
return NoFurtherHandling;
8789
}
8890

91+
using var mappedResults = new PooledArrayBuilder<SumType<VSInternalReferenceItem, LspLocation>>(results.Length);
92+
8993
// Map the C# locations back to the Razor file.
9094
foreach (var result in results)
9195
{
@@ -100,6 +104,12 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
100104

101105
var (mappedUri, mappedRange) = await DocumentMappingService.MapToHostDocumentUriAndRangeAsync(context.Snapshot, location.DocumentUri.GetRequiredParsedUri(), location.Range.ToLinePositionSpan(), cancellationToken).ConfigureAwait(false);
102106

107+
if (_filePathService.IsVirtualCSharpFile(mappedUri))
108+
{
109+
// Couldn't map, so probably a hidden part of the code-gen, let's skip it.
110+
continue;
111+
}
112+
103113
if (referenceItem is not null)
104114
{
105115
// Indicates the reference item is directly available in the code
@@ -118,8 +128,10 @@ protected override IRemoteFindAllReferencesService CreateService(in ServiceArgs
118128

119129
location.DocumentUri = new(mappedUri);
120130
location.Range = mappedRange.ToRange();
131+
132+
mappedResults.Add(result);
121133
}
122134

123-
return Results(results);
135+
return Results(mappedResults.ToArrayAndClear());
124136
}
125137
}

0 commit comments

Comments
 (0)