14
14
namespace Microsoft . AspNetCore . Razor . LanguageServer . Mapping ;
15
15
16
16
[ RazorLanguageServerEndpoint ( LanguageServerConstants . RazorMapToDocumentRangesEndpoint ) ]
17
- internal sealed class RazorMapToDocumentRangesEndpoint :
18
- IRazorDocumentlessRequestHandler < RazorMapToDocumentRangesParams , RazorMapToDocumentRangesResponse ? > ,
19
- ITextDocumentIdentifierHandler < RazorMapToDocumentRangesParams , Uri >
17
+ internal sealed class RazorMapToDocumentRangesEndpoint ( IDocumentMappingService documentMappingService )
18
+ : IRazorDocumentlessRequestHandler < RazorMapToDocumentRangesParams , RazorMapToDocumentRangesResponse ? > , ITextDocumentIdentifierHandler < RazorMapToDocumentRangesParams , Uri >
20
19
{
21
- private readonly IDocumentMappingService _documentMappingService ;
22
-
23
- public RazorMapToDocumentRangesEndpoint ( IDocumentMappingService documentMappingService )
24
- {
25
- _documentMappingService = documentMappingService ;
26
- }
20
+ private readonly IDocumentMappingService _documentMappingService = documentMappingService ;
27
21
28
22
public bool MutatesSolutionState { get ; } = false ;
29
23
@@ -46,29 +40,23 @@ public Uri GetTextDocumentIdentifier(RazorMapToDocumentRangesParams request)
46
40
}
47
41
48
42
var codeDocument = await documentContext . GetCodeDocumentAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
49
- IRazorGeneratedDocument ? generatedDocument = request . Kind switch
50
- {
51
- RazorLanguageKind . CSharp => codeDocument . GetRequiredCSharpDocument ( ) ,
52
- RazorLanguageKind . Html => codeDocument . GetHtmlDocument ( ) ,
53
- _ => throw new NotSupportedException ( $ "Unsupported language kind '{ request . Kind } '.") ,
54
- } ;
55
-
56
- if ( generatedDocument is null )
57
- {
58
- return null ;
59
- }
43
+ var csharpDocument = codeDocument . GetRequiredCSharpDocument ( ) ;
60
44
61
45
var ranges = new LspRange [ request . ProjectedRanges . Length ] ;
62
46
var spans = new RazorTextSpan [ request . ProjectedRanges . Length ] ;
63
47
64
48
for ( var i = 0 ; i < request . ProjectedRanges . Length ; i ++ )
65
49
{
66
- var projectedRange = request . ProjectedRanges [ i ] ;
67
- if ( ! _documentMappingService . TryMapToHostDocumentRange ( generatedDocument , projectedRange , request . MappingBehavior , out var originalRange ) )
50
+ var originalRange = request . ProjectedRanges [ i ] ;
51
+ if ( request . Kind is RazorLanguageKind . CSharp )
68
52
{
69
- // All language queries on unsupported documents return Html. This is equivalent to what pre-VSCode Razor was capable of.
70
- ranges [ i ] = LspFactory . UndefinedRange ;
71
- continue ;
53
+ var projectedRange = request . ProjectedRanges [ i ] ;
54
+ if ( ! _documentMappingService . TryMapToHostDocumentRange ( csharpDocument , projectedRange , request . MappingBehavior , out originalRange ) )
55
+ {
56
+ // All language queries on unsupported documents return Html. This is equivalent to what pre-VSCode Razor was capable of.
57
+ ranges [ i ] = LspFactory . UndefinedRange ;
58
+ continue ;
59
+ }
72
60
}
73
61
74
62
ranges [ i ] = originalRange ;
0 commit comments