@@ -20,13 +20,13 @@ internal abstract class AbstractRazorDelegatingEndpoint<TRequest, TResponse> : I
2020 where TRequest : ITextDocumentPositionParams
2121{
2222 private readonly LanguageServerFeatureOptions _languageServerFeatureOptions ;
23- private readonly RazorDocumentMappingService _documentMappingService ;
23+ private readonly IRazorDocumentMappingService _documentMappingService ;
2424 private readonly ClientNotifierServiceBase _languageServer ;
2525 protected readonly ILogger Logger ;
2626
2727 protected AbstractRazorDelegatingEndpoint (
2828 LanguageServerFeatureOptions languageServerFeatureOptions ,
29- RazorDocumentMappingService documentMappingService ,
29+ IRazorDocumentMappingService documentMappingService ,
3030 ClientNotifierServiceBase languageServer ,
3131 ILogger logger )
3232 {
@@ -40,7 +40,7 @@ protected AbstractRazorDelegatingEndpoint(
4040 /// <summary>
4141 /// The strategy to use to project the incoming caret position onto the generated C#/Html document
4242 /// </summary>
43- protected virtual IProjectionStrategy ProjectionStrategy { get ; } = DefaultProjectionStrategy . Instance ;
43+ protected virtual IDocumentPositionInfoStrategy DocumentPositionInfoStrategy { get ; } = DefaultDocumentPositionInfoStrategy . Instance ;
4444
4545 protected bool SingleServerSupport => _languageServerFeatureOptions . SingleServerSupport ;
4646
@@ -67,20 +67,20 @@ protected AbstractRazorDelegatingEndpoint(
6767 /// <summary>
6868 /// The delegated object to send to the <see cref="CustomMessageTarget"/>
6969 /// </summary>
70- protected abstract Task < IDelegatedParams ? > CreateDelegatedParamsAsync ( TRequest request , RazorRequestContext requestContext , Projection projection , CancellationToken cancellationToken ) ;
70+ protected abstract Task < IDelegatedParams ? > CreateDelegatedParamsAsync ( TRequest request , RazorRequestContext requestContext , DocumentPositionInfo positionInfo , CancellationToken cancellationToken ) ;
7171
7272 /// <summary>
7373 /// If the response needs to be handled, such as for remapping positions back, override and handle here
7474 /// </summary>
75- protected virtual Task < TResponse > HandleDelegatedResponseAsync ( TResponse delegatedResponse , TRequest originalRequest , RazorRequestContext requestContext , Projection projection , CancellationToken cancellationToken )
75+ protected virtual Task < TResponse > HandleDelegatedResponseAsync ( TResponse delegatedResponse , TRequest originalRequest , RazorRequestContext requestContext , DocumentPositionInfo positionInfo , CancellationToken cancellationToken )
7676 => Task . FromResult ( delegatedResponse ) ;
7777
7878 /// <summary>
7979 /// If the request can be handled without delegation, override this to provide a response. If a null
8080 /// value is returned the request will be delegated to C#/HTML servers, otherwise the response
8181 /// will be used in <see cref="HandleRequestAsync(TRequest, RazorRequestContext, CancellationToken)"/>
8282 /// </summary>
83- protected virtual Task < TResponse ? > TryHandleAsync ( TRequest request , RazorRequestContext requestContext , Projection projection , CancellationToken cancellationToken )
83+ protected virtual Task < TResponse ? > TryHandleAsync ( TRequest request , RazorRequestContext requestContext , DocumentPositionInfo positionInfo , CancellationToken cancellationToken )
8484 => Task . FromResult < TResponse ? > ( default ) ;
8585
8686 /// <summary>
@@ -111,13 +111,13 @@ protected virtual Task<TResponse> HandleDelegatedResponseAsync(TResponse delegat
111111 return default ;
112112 }
113113
114- var projection = await ProjectionStrategy . TryGetProjectionAsync ( _documentMappingService , documentContext , request . Position , requestContext . Logger , cancellationToken ) . ConfigureAwait ( false ) ;
115- if ( projection is null )
114+ var positionInfo = await DocumentPositionInfoStrategy . TryGetPositionInfoAsync ( _documentMappingService , documentContext , request . Position , requestContext . Logger , cancellationToken ) . ConfigureAwait ( false ) ;
115+ if ( positionInfo is null )
116116 {
117117 return default ;
118118 }
119119
120- var response = await TryHandleAsync ( request , requestContext , projection , cancellationToken ) . ConfigureAwait ( false ) ;
120+ var response = await TryHandleAsync ( request , requestContext , positionInfo , cancellationToken ) . ConfigureAwait ( false ) ;
121121 if ( response is not null && response is not ISumType { Value : null } )
122122 {
123123 return response ;
@@ -128,27 +128,27 @@ protected virtual Task<TResponse> HandleDelegatedResponseAsync(TResponse delegat
128128 return default ;
129129 }
130130
131- if ( projection . LanguageKind == RazorLanguageKind . Razor )
131+ if ( positionInfo . LanguageKind == RazorLanguageKind . Razor )
132132 {
133133 // We can only delegate to C# and HTML, so if we're in a Razor context and our inheritor didn't want to provide
134134 // any response then that's all we can do.
135135 return default ;
136136 }
137- else if ( projection . LanguageKind == RazorLanguageKind . Html && PreferCSharpOverHtmlIfPossible )
137+ else if ( positionInfo . LanguageKind == RazorLanguageKind . Html && PreferCSharpOverHtmlIfPossible )
138138 {
139139 // Sometimes Html can actually be mapped to C#, like for example component attributes, which map to
140140 // C# properties, even though they appear entirely in a Html context. Since remapping is pretty cheap
141141 // it's easier to just try mapping, and see what happens, rather than checking for specific syntax nodes.
142142 var codeDocument = await documentContext . GetCodeDocumentAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
143- if ( _documentMappingService . TryMapToProjectedDocumentPosition ( codeDocument . GetCSharpDocument ( ) , projection . AbsoluteIndex , out var csharpPosition , out _ ) )
143+ if ( _documentMappingService . TryMapToGeneratedDocumentPosition ( codeDocument . GetCSharpDocument ( ) , positionInfo . HostDocumentIndex , out var csharpPosition , out _ ) )
144144 {
145- // We're just gonna pretend this mapped perfectly normally onto C#. Moving this logic to the actual projection
145+ // We're just gonna pretend this mapped perfectly normally onto C#. Moving this logic to the actual position info
146146 // calculating code is possible, but could have untold effects, so opt-in is better (for now?)
147- projection = new Projection ( RazorLanguageKind . CSharp , csharpPosition , projection . AbsoluteIndex ) ;
147+ positionInfo = new DocumentPositionInfo ( RazorLanguageKind . CSharp , csharpPosition , positionInfo . HostDocumentIndex ) ;
148148 }
149149 }
150150
151- var delegatedParams = await CreateDelegatedParamsAsync ( request , requestContext , projection , cancellationToken ) . ConfigureAwait ( false ) ;
151+ var delegatedParams = await CreateDelegatedParamsAsync ( request , requestContext , positionInfo , cancellationToken ) . ConfigureAwait ( false ) ;
152152
153153 if ( delegatedParams is null )
154154 {
@@ -171,7 +171,7 @@ protected virtual Task<TResponse> HandleDelegatedResponseAsync(TResponse delegat
171171 throw ;
172172 }
173173
174- var remappedResponse = await HandleDelegatedResponseAsync ( delegatedRequest , request , requestContext , projection , cancellationToken ) . ConfigureAwait ( false ) ;
174+ var remappedResponse = await HandleDelegatedResponseAsync ( delegatedRequest , request , requestContext , positionInfo , cancellationToken ) . ConfigureAwait ( false ) ;
175175
176176 return remappedResponse ;
177177 }
0 commit comments