Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release/dev16.11 to main #53508

Merged
merged 3 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ public static LSP.Range TextSpanToRange(TextSpan textSpan, SourceText text)
}

public static Task<LSP.Location?> DocumentSpanToLocationAsync(DocumentSpan documentSpan, CancellationToken cancellationToken)
=> TextSpanToLocationAsync(documentSpan.Document, documentSpan.SourceSpan, cancellationToken);
=> TextSpanToLocationAsync(documentSpan.Document, documentSpan.SourceSpan, isStale: false, cancellationToken);

public static async Task<LSP.LocationWithText?> DocumentSpanToLocationWithTextAsync(DocumentSpan documentSpan, ClassifiedTextElement text, CancellationToken cancellationToken)
public static async Task<LSP.LocationWithText?> DocumentSpanToLocationWithTextAsync(
DocumentSpan documentSpan, ClassifiedTextElement text, CancellationToken cancellationToken)
{
var location = await TextSpanToLocationAsync(documentSpan.Document, documentSpan.SourceSpan, cancellationToken).ConfigureAwait(false);
var location = await TextSpanToLocationAsync(
documentSpan.Document, documentSpan.SourceSpan, isStale: false, cancellationToken).ConfigureAwait(false);

return location == null ? null : new LSP.LocationWithText
{
Expand Down Expand Up @@ -280,18 +282,22 @@ public static LSP.Range TextSpanToRange(TextSpan textSpan, SourceText text)
return documentEdits;
}

public static async Task<LSP.Location?> TextSpanToLocationAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
public static async Task<LSP.Location?> TextSpanToLocationAsync(
Document document,
TextSpan textSpan,
bool isStale,
CancellationToken cancellationToken)
{
var result = await GetMappedSpanResultAsync(document, ImmutableArray.Create(textSpan), cancellationToken).ConfigureAwait(false);
if (result == null)
{
return await ConvertTextSpanToLocation(document, textSpan, cancellationToken).ConfigureAwait(false);
return await ConvertTextSpanToLocation(document, textSpan, isStale, cancellationToken).ConfigureAwait(false);
}

var mappedSpan = result.Value.Single();
if (mappedSpan.IsDefault)
{
return await ConvertTextSpanToLocation(document, textSpan, cancellationToken).ConfigureAwait(false);
return await ConvertTextSpanToLocation(document, textSpan, isStale, cancellationToken).ConfigureAwait(false);
}

return new LSP.Location
Expand All @@ -300,10 +306,24 @@ public static LSP.Range TextSpanToRange(TextSpan textSpan, SourceText text)
Range = MappedSpanResultToRange(mappedSpan)
};

static async Task<LSP.Location> ConvertTextSpanToLocation(Document document, TextSpan span, CancellationToken cancellationToken)
static async Task<LSP.Location> ConvertTextSpanToLocation(
Document document,
TextSpan span,
bool isStale,
CancellationToken cancellationToken)
{
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

if (isStale)
{
// in the case of a stale item, the span may be out of bounds of the document. Cap
// us to the end of the document as that's where we're going to navigate the user
// to.
span = TextSpan.FromBounds(
Math.Min(text.Length, span.Start),
Math.Min(text.Length, span.End));
}

return ConvertTextSpanWithTextToLocation(span, text, document.GetURI());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public AbstractGoToDefinitionHandler(IMetadataAsSourceFileService metadataAsSour
continue;
}

var location = await ProtocolConversions.TextSpanToLocationAsync(definition.Document, definition.SourceSpan, cancellationToken).ConfigureAwait(false);
var location = await ProtocolConversions.TextSpanToLocationAsync(
definition.Document, definition.SourceSpan, definition.IsStale, cancellationToken).ConfigureAwait(false);
locations.AddIfNotNull(location);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public void ReportProgress(int current, int maximum)

private async Task ReportSymbolInformationAsync(INavigateToSearchResult result, CancellationToken cancellationToken)
{
var location = await ProtocolConversions.TextSpanToLocationAsync(result.NavigableItem.Document, result.NavigableItem.SourceSpan, cancellationToken).ConfigureAwait(false);
var location = await ProtocolConversions.TextSpanToLocationAsync(
result.NavigableItem.Document, result.NavigableItem.SourceSpan, result.NavigableItem.IsStale, cancellationToken).ConfigureAwait(false);
Contract.ThrowIfNull(location);
_progress.Report(new VSSymbolInformation
{
Expand Down