|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT license. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System.Threading; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.CodeAnalysis.Razor.Protocol; |
| 7 | +using Microsoft.VisualStudio.LanguageServer.Protocol; |
| 8 | +using StreamJsonRpc; |
| 9 | + |
| 10 | +namespace Microsoft.VisualStudio.Razor.LanguageClient.Endpoints; |
| 11 | + |
| 12 | +internal partial class RazorCustomMessageTarget |
| 13 | +{ |
| 14 | + [JsonRpcMethod(CustomMessageNames.RazorReferencesEndpointName, UseSingleObjectParameterDeserialization = true)] |
| 15 | + public async Task<VSInternalReferenceItem[]?> ReferencesAsync(DelegatedPositionParams request, CancellationToken cancellationToken) |
| 16 | + { |
| 17 | + var delegationDetails = await GetProjectedRequestDetailsAsync(request, cancellationToken).ConfigureAwait(false); |
| 18 | + if (delegationDetails is null) |
| 19 | + { |
| 20 | + return default; |
| 21 | + } |
| 22 | + |
| 23 | + var referenceParams = new ReferenceParams() |
| 24 | + { |
| 25 | + TextDocument = new VSTextDocumentIdentifier() |
| 26 | + { |
| 27 | + Uri = delegationDetails.Value.ProjectedUri, |
| 28 | + ProjectContext = null, |
| 29 | + }, |
| 30 | + Position = request.ProjectedPosition, |
| 31 | + Context = new ReferenceContext(), |
| 32 | + }; |
| 33 | + |
| 34 | + var response = await _requestInvoker.ReinvokeRequestOnServerAsync<ReferenceParams, VSInternalReferenceItem[]?>( |
| 35 | + delegationDetails.Value.TextBuffer, |
| 36 | + Methods.TextDocumentReferencesName, |
| 37 | + delegationDetails.Value.LanguageServerName, |
| 38 | + referenceParams, |
| 39 | + cancellationToken).ConfigureAwait(false); |
| 40 | + |
| 41 | + if (response is null) |
| 42 | + { |
| 43 | + return default; |
| 44 | + } |
| 45 | + |
| 46 | + return response.Response; |
| 47 | + } |
| 48 | +} |
0 commit comments