private static async Task <LSP.Location[]> RunFindAllReferencesAsync(Solution solution, LSP.Location caret, bool includeDeclaration) { var request = new LSP.ReferenceParams() { TextDocument = CreateTextDocumentIdentifier(caret.Uri), Position = caret.Range.Start, Context = new LSP.ReferenceContext() { IncludeDeclaration = includeDeclaration } }; var references = await TestHandleAsync <LSP.ReferenceParams, object[]>(solution, request); return(references.Select(o => (LSP.Location)o).ToArray()); }
public async Task FindReferencesAsync(Document document, int position, IFindUsagesContext context) { var text = await document.GetTextAsync().ConfigureAwait(false); var lspClient = _roslynLspClientServiceFactory.ActiveLanguageServerClient; if (lspClient == null) { return; } var referenceParams = new LSP.ReferenceParams { Context = new LSP.ReferenceContext { IncludeDeclaration = false }, TextDocument = ProtocolConversions.DocumentToTextDocumentIdentifier(document), Position = ProtocolConversions.LinePositionToPosition(text.Lines.GetLinePosition(position)) }; var locations = await lspClient.RequestAsync(LSP.Methods.TextDocumentReferences, referenceParams, context.CancellationToken).ConfigureAwait(false); if (locations == null) { return; } // TODO: Need to get real definition data from the server. var dummyDef = DefinitionItem.CreateNonNavigableItem(ImmutableArray <string> .Empty, ImmutableArray <TaggedText> .Empty); await context.OnDefinitionFoundAsync(dummyDef).ConfigureAwait(false); foreach (var location in locations) { var documentSpan = await _remoteLanguageServiceWorkspace.GetDocumentSpanFromLocation(location, context.CancellationToken).ConfigureAwait(false); if (documentSpan == null) { continue; } #pragma warning disable CS0612 // Type or member is obsolete. TODO. await context.OnReferenceFoundAsync(new SourceReferenceItem(dummyDef, documentSpan.Value, isWrittenTo : false)).ConfigureAwait(false); #pragma warning restore CS0612 // Type or member is obsolete } }
public Task <LSP.Location[]> InvokeReferencesAsync(LSP.ReferenceParams request, CancellationToken cancellationToken) => InvokeWithParametersAsync <LSP.Location[]>("textDocument/references", request, cancellationToken);