Skip to content

Commit

Permalink
Merge pull request dotnet#20435 from Pilchie/VenusOOP
Browse files Browse the repository at this point in the history
Don't crash in OOP with TS projects/documents
  • Loading branch information
Pilchie authored Jun 30, 2017
2 parents 502449f + 4383d35 commit 66362df
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public async Task<ImmutableArray<AddImportFixData>> GetFixesAsync(

using (session)
{
if (session == null)
// This service is only defined for C# and VB, but we'll be a bit paranoid.
if (session == null || !RemoteSupportedLanguages.IsSupported(document.Project.Language))
{
return await GetFixesInCurrentProcessAsync(
document, span, diagnosticId, placeSystemNamespaceFirst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ private async Task<ImmutableArray<INavigateToSearchResult>> SearchProjectInRemot

private static Task<RemoteHostClient.Session> GetRemoteHostSessionAsync(Project project, CancellationToken cancellationToken)
{
// This service is only defined for C# and VB, but we'll be a bit paranoid.
if (!RemoteSupportedLanguages.IsSupported(project.Language))
{
return null;
}

return project.Solution.TryCreateCodeAnalysisServiceSessionAsync(
RemoteFeatureOptions.NavigateToEnabled, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,22 @@ await AddMetadataDeclarationsWithNormalQueryAsync(
private static async Task<(bool, ImmutableArray<SymbolAndProjectId>)> TryFindAllDeclarationsWithNormalQueryInRemoteProcessAsync(
Project project, SearchQuery query, SymbolFilter criteria, CancellationToken cancellationToken)
{
using (var session = await SymbolFinder.TryGetRemoteSessionAsync(
project.Solution, cancellationToken).ConfigureAwait(false))
if (RemoteSupportedLanguages.IsSupported(project.Language))
{
if (session != null)
using (var session = await SymbolFinder.TryGetRemoteSessionAsync(
project.Solution, cancellationToken).ConfigureAwait(false))
{
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindAllDeclarationsWithNormalQueryAsync),
project.Id, query.Name, query.Kind, criteria).ConfigureAwait(false);
if (session != null)
{
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindAllDeclarationsWithNormalQueryAsync),
project.Id, query.Name, query.Kind, criteria).ConfigureAwait(false);

var rehydrated = await RehydrateAsync(
project.Solution, result, cancellationToken).ConfigureAwait(false);
var rehydrated = await RehydrateAsync(
project.Solution, result, cancellationToken).ConfigureAwait(false);

return (true, rehydrated);
return (true, rehydrated);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static partial class DeclarationFinder
#region Dispatch Members

// These are the public entrypoints to finding source declarations. They will attempt to
// remove the query to the OOP process, and will fallback to local processing if they can't.
// remote the query to the OOP process, and will fallback to local processing if they can't.

public static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarationsWithNormalQueryAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
Expand Down Expand Up @@ -135,18 +135,21 @@ public static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarati
private static async Task<(bool, ImmutableArray<SymbolAndProjectId>)> TryFindSourceDeclarationsWithNormalQueryInRemoteProcessAsync(
Project project, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
using (var session = await SymbolFinder.TryGetRemoteSessionAsync(project.Solution, cancellationToken).ConfigureAwait(false))
if (RemoteSupportedLanguages.IsSupported(project.Language))
{
if (session != null)
using (var session = await SymbolFinder.TryGetRemoteSessionAsync(project.Solution, cancellationToken).ConfigureAwait(false))
{
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithNormalQueryAsync),
project.Id, name, ignoreCase, criteria).ConfigureAwait(false);
if (session != null)
{
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithNormalQueryAsync),
project.Id, name, ignoreCase, criteria).ConfigureAwait(false);

var rehydrated = await RehydrateAsync(
project.Solution, result, cancellationToken).ConfigureAwait(false);
var rehydrated = await RehydrateAsync(
project.Solution, result, cancellationToken).ConfigureAwait(false);

return (true, rehydrated);
return (true, rehydrated);
}
}
}

Expand All @@ -156,18 +159,21 @@ public static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarati
private static async Task<(bool, ImmutableArray<SymbolAndProjectId>)> TryFindSourceDeclarationsWithPatternInRemoteProcessAsync(
Project project, string pattern, SymbolFilter criteria, CancellationToken cancellationToken)
{
using (var session = await SymbolFinder.TryGetRemoteSessionAsync(project.Solution, cancellationToken).ConfigureAwait(false))
if (RemoteSupportedLanguages.IsSupported(project.Language))
{
if (session != null)
using (var session = await SymbolFinder.TryGetRemoteSessionAsync(project.Solution, cancellationToken).ConfigureAwait(false))
{
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithPatternAsync),
project.Id, pattern, criteria).ConfigureAwait(false);
if (session != null)
{
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithPatternAsync),
project.Id, pattern, criteria).ConfigureAwait(false);

var rehydrated = await RehydrateAsync(
project.Solution, result, cancellationToken).ConfigureAwait(false);
var rehydrated = await RehydrateAsync(
project.Solution, result, cancellationToken).ConfigureAwait(false);

return (true, rehydrated);
return (true, rehydrated);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.DocumentHighlighting;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Remote
{
Expand All @@ -14,9 +15,14 @@ internal partial class CodeAnalysisService : IRemoteDocumentHighlights
public async Task<ImmutableArray<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
DocumentId documentId, int position, DocumentId[] documentIdsToSearch)
{
// NOTE: In projection scenarios, we might get a set of documents to search
// that are not all the same language and might not exist in the OOP process
// (like the JS parts of a .cshtml file). Filter them out here. This will
// need to be revisited if we someday support FAR between these languages.
var solution = await GetSolutionAsync().ConfigureAwait(false);
var document = solution.GetDocument(documentId);
var documentsToSearch = ImmutableHashSet.CreateRange(documentIdsToSearch.Select(solution.GetDocument));
var documentsToSearch = ImmutableHashSet.CreateRange(
documentIdsToSearch.Select(solution.GetDocument).WhereNotNull());

var service = document.GetLanguageService<IDocumentHighlightsService>();
var result = await service.GetDocumentHighlightsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Remote
{
Expand All @@ -30,7 +31,12 @@ public async Task FindReferencesAsync(SerializableSymbolAndProjectId symbolAndPr
return;
}

// NOTE: In projection scenarios, we might get a set of documents to search
// that are not all the same language and might not exist in the OOP process
// (like the JS parts of a .cshtml file). Filter them out here. This will
// need to be revisited if we someday support FAR between these languages.
var documents = documentArgs?.Select(solution.GetDocument)
.WhereNotNull()
.ToImmutableHashSet();

await SymbolFinder.FindReferencesInCurrentProcessAsync(
Expand Down

0 comments on commit 66362df

Please sign in to comment.