/// <summary> /// Called by the debugger when a debugging session starts and managed debugging is being used. /// </summary> public async ValueTask StartSessionAsync(CancellationToken cancellationToken) { IsSessionActive = true; if (_disabled) { return; } try { var workspace = WorkspaceProvider.Value.Workspace; var solution = GetCurrentCompileTimeSolution(_committedDesignTimeSolution = workspace.CurrentSolution); var openedDocumentIds = workspace.GetOpenDocumentIds().ToImmutableArray(); var proxy = new RemoteEditAndContinueServiceProxy(workspace); _debuggingSession = await proxy.StartDebuggingSessionAsync( solution, new ManagedHotReloadServiceImpl(_debuggerService.Value), captureMatchingDocuments : openedDocumentIds, captureAllMatchingDocuments : false, reportDiagnostics : true, cancellationToken).ConfigureAwait(false); } catch (Exception e) when(FatalError.ReportAndCatchUnlessCanceled(e, cancellationToken)) { } // the service failed, error has been reported - disable further operations _disabled = _debuggingSession == null; }
private static Task <ImmutableArray <Diagnostic> > AnalyzeSemanticsImplAsync( Document document, CancellationToken cancellationToken ) { var workspace = document.Project.Solution.Workspace; var proxy = new RemoteEditAndContinueServiceProxy(workspace); var activeStatementSpanProvider = new DocumentActiveStatementSpanProvider( async cancellationToken => { var trackingService = workspace.Services.GetRequiredService <IActiveStatementTrackingService>(); return(await trackingService .GetSpansAsync(document, cancellationToken) .ConfigureAwait(false)); } ); return(proxy .GetDocumentDiagnosticsAsync( document, activeStatementSpanProvider, cancellationToken ) .AsTask()); }
private static async Task <ImmutableArray <Diagnostic> > AnalyzeSemanticsImplAsync(Workspace workspace, Document designTimeDocument, CancellationToken cancellationToken) { var designTimeSolution = designTimeDocument.Project.Solution; var compileTimeSolution = workspace.Services.GetRequiredService <ICompileTimeSolutionProvider>().GetCompileTimeSolution(designTimeSolution); var compileTimeDocument = await compileTimeSolution.GetDocumentAsync(designTimeDocument.Id, includeSourceGenerated : true, cancellationToken).ConfigureAwait(false); if (compileTimeDocument == null) { if (!designTimeDocument.State.Attributes.DesignTimeOnly || !designTimeDocument.FilePath.EndsWith(".razor.g.cs")) { return(ImmutableArray <Diagnostic> .Empty); } var relativeDocumentPath = Path.Combine("\\", PathUtilities.GetRelativePath(PathUtilities.GetDirectoryName(designTimeDocument.Project.FilePath), designTimeDocument.FilePath)[..^ ".g.cs".Length]); var generatedDocumentPath = Path.Combine("Microsoft.NET.Sdk.Razor.SourceGenerators", "Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator", GetIdentifierFromPath(relativeDocumentPath)) + ".cs"; var sourceGeneratedDocuments = await compileTimeSolution.GetRequiredProject(designTimeDocument.Project.Id).GetSourceGeneratedDocumentsAsync(cancellationToken).ConfigureAwait(false); compileTimeDocument = sourceGeneratedDocuments.SingleOrDefault(d => d.FilePath == generatedDocumentPath); if (compileTimeDocument == null) { return(ImmutableArray <Diagnostic> .Empty); } } // EnC services should never be called on a design-time solution. var proxy = new RemoteEditAndContinueServiceProxy(workspace); var activeStatementSpanProvider = new ActiveStatementSpanProvider(async(documentId, filePath, cancellationToken) => { var trackingService = workspace.Services.GetRequiredService <IActiveStatementTrackingService>(); return(await trackingService.GetSpansAsync(compileTimeSolution, documentId, filePath, cancellationToken).ConfigureAwait(false)); }); return(await proxy.GetDocumentDiagnosticsAsync(compileTimeDocument, designTimeDocument, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false)); }
private static async Task <ImmutableArray <Diagnostic> > AnalyzeSemanticsImplAsync(Document designTimeDocument, CancellationToken cancellationToken) { var workspace = designTimeDocument.Project.Solution.Workspace; if (workspace.Services.HostServices is not IMefHostExportProvider mefServices) { return(ImmutableArray <Diagnostic> .Empty); } // avoid creating and synchronizing compile-time solution if the Hot Reload/EnC session is not active if (mefServices.GetExports <EditAndContinueLanguageService>().SingleOrDefault()?.Value.IsSessionActive != true) { return(ImmutableArray <Diagnostic> .Empty); } var designTimeSolution = designTimeDocument.Project.Solution; var compileTimeSolution = workspace.Services.GetRequiredService <ICompileTimeSolutionProvider>().GetCompileTimeSolution(designTimeSolution); var compileTimeDocument = await CompileTimeSolutionProvider.TryGetCompileTimeDocumentAsync(designTimeDocument, compileTimeSolution, cancellationToken).ConfigureAwait(false); if (compileTimeDocument == null) { return(ImmutableArray <Diagnostic> .Empty); } // EnC services should never be called on a design-time solution. var proxy = new RemoteEditAndContinueServiceProxy(workspace); var activeStatementSpanProvider = new ActiveStatementSpanProvider(async(documentId, filePath, cancellationToken) => { var trackingService = workspace.Services.GetRequiredService <IActiveStatementTrackingService>(); return(await trackingService.GetSpansAsync(compileTimeSolution, documentId, filePath, cancellationToken).ConfigureAwait(false)); }); return(await proxy.GetDocumentDiagnosticsAsync(compileTimeDocument, designTimeDocument, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false)); }
private static async Task <ImmutableArray <Diagnostic> > AnalyzeSemanticsImplAsync(Workspace workspace, Document designTimeDocument, CancellationToken cancellationToken) { var designTimeSolution = designTimeDocument.Project.Solution; var compileTimeSolution = workspace.Services.GetRequiredService <ICompileTimeSolutionProvider>().GetCompileTimeSolution(designTimeSolution); var compileTimeDocument = await CompileTimeSolutionProvider.TryGetCompileTimeDocumentAsync(designTimeDocument, compileTimeSolution, cancellationToken).ConfigureAwait(false); if (compileTimeDocument == null) { return(ImmutableArray <Diagnostic> .Empty); } // EnC services should never be called on a design-time solution. var proxy = new RemoteEditAndContinueServiceProxy(workspace); var activeStatementSpanProvider = new ActiveStatementSpanProvider(async(documentId, filePath, cancellationToken) => { var trackingService = workspace.Services.GetRequiredService <IActiveStatementTrackingService>(); return(await trackingService.GetSpansAsync(compileTimeSolution, documentId, filePath, cancellationToken).ConfigureAwait(false)); }); return(await proxy.GetDocumentDiagnosticsAsync(compileTimeDocument, designTimeDocument, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false)); }
private static void WorkspaceDocumentOpenedImpl(DocumentEventArgs e) { var proxy = new RemoteEditAndContinueServiceProxy(e.Document.Project.Solution.Workspace); _ = Task.Run(() => proxy.OnSourceFileUpdatedAsync(e.Document, CancellationToken.None)).ReportNonFatalErrorAsync(); }