From 5a2c435fa69b5b31385d9d39e13641f48db9c93b Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 8 May 2025 17:03:26 -0700 Subject: [PATCH] Throw instead of returning an empty result --- src/razor/src/mapping/razorMapSpansResponse.ts | 2 -- src/razor/src/razorLanguageServiceClient.ts | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/razor/src/mapping/razorMapSpansResponse.ts b/src/razor/src/mapping/razorMapSpansResponse.ts index c407db89ea..340b03d9c2 100644 --- a/src/razor/src/mapping/razorMapSpansResponse.ts +++ b/src/razor/src/mapping/razorMapSpansResponse.ts @@ -9,8 +9,6 @@ import { SerializableRange } from '../rpc/serializableRange'; // matches https://github.com/dotnet/razor/blob/main/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/RazorMapSpansResponse.cs export class RazorMapSpansResponse { - static empty: RazorMapSpansResponse = new RazorMapSpansResponse([], [], { uri: '' }); - constructor( public readonly ranges: SerializableRange[], public readonly spans: razorTextSpan[], diff --git a/src/razor/src/razorLanguageServiceClient.ts b/src/razor/src/razorLanguageServiceClient.ts index 0fb000df48..90f3194de7 100644 --- a/src/razor/src/razorLanguageServiceClient.ts +++ b/src/razor/src/razorLanguageServiceClient.ts @@ -68,7 +68,7 @@ export class RazorLanguageServiceClient { const document = await this.documentManager.getDocumentForCSharpUri(csharpUri); if (!document) { - return RazorMapSpansResponse.empty; + throw new Error(`Unable to find razor document for ${csharpUri}`); } const request = new RazorMapToDocumentRangesRequest(LanguageKind.CSharp, params.ranges, document.uri); @@ -78,7 +78,11 @@ export class RazorLanguageServiceClient { ); if (!result) { - return RazorMapSpansResponse.empty; + throw new Error(`Failed mapping spans`); + } + + if (result.spans.length !== params.ranges.length) { + throw new Error(`Expected ${params.ranges.length} mapped spans but got ${result.spans.length}`); } return new RazorMapSpansResponse(