public override async Task <ImmutableArray <Diagnostic> > AnalyzeSemanticsAsync(Document document, CancellationToken cancellationToken) { try { var encService = document.Project.Solution.Workspace.Services.GetService <IDebuggingWorkspaceService>()?.EditAndContinueServiceOpt; if (encService == null) { return(ImmutableArray <Diagnostic> .Empty); } EditSession session = encService.EditSession; if (session == null || session.BaseSolution.WorkspaceVersion == document.Project.Solution.WorkspaceVersion || !session.HasProject(document.Project.Id)) { return(ImmutableArray <Diagnostic> .Empty); } var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var analysis = await session.GetDocumentAnalysis(document).GetValueAsync(cancellationToken).ConfigureAwait(false); if (analysis.RudeEditErrors.IsDefault) { return(ImmutableArray <Diagnostic> .Empty); } session.LogRudeEditErrors(analysis.RudeEditErrors); return(analysis.RudeEditErrors.SelectAsArray((e, t) => e.ToDiagnostic(t), tree)); } catch (Exception e) when(FatalError.ReportUnlessCanceled(e)) { throw ExceptionUtilities.Unreachable; } }
public override async Task AnalyzeSemanticsAsync(Document document, Action <Diagnostic> addDiagnostic, CancellationToken cancellationToken) { try { var encService = document.Project.Solution.Workspace.Services.GetService <IEditAndContinueWorkspaceService>(); if (encService == null) { return; } EditSession session = encService.EditSession; if (session == null || !session.HasProject(document.Project.Id)) { return; } var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var analysis = await session.GetDocumentAnalysis(document).GetValueAsync(cancellationToken).ConfigureAwait(false); if (!analysis.RudeEditErrors.IsDefault) { session.LogRudeEditErrors(analysis.RudeEditErrors); foreach (var error in analysis.RudeEditErrors) { addDiagnostic(error.ToDiagnostic(tree)); } } } catch (Exception e) when(FatalError.ReportUnlessCanceled(e)) { throw ExceptionUtilities.Unreachable; } }
public async Task <LinePositionSpan?> GetCurrentActiveStatementPositionAsync(ActiveInstructionId instructionId, CancellationToken cancellationToken) { try { // It is allowed to call this method before entering or after exiting break mode. In fact, the VS debugger does so. // We return null since there the concept of active statement only makes sense during break mode. if (_editSession == null) { return(null); } Debug.Assert(_debuggingSession != null); // TODO: Avoid enumerating active statements for unchanged documents. // We would need to add a document path parameter to be able to find the document we need to check for changes. // https://github.com/dotnet/roslyn/issues/24324 var baseActiveStatements = await _editSession.BaseActiveStatements.GetValueAsync(cancellationToken).ConfigureAwait(false); if (!baseActiveStatements.InstructionMap.TryGetValue(instructionId, out var baseActiveStatement)) { return(null); } var primaryDocument = _debuggingSession.InitialSolution.Workspace.CurrentSolution.GetDocument(baseActiveStatement.PrimaryDocumentId); var documentAnalysis = await _editSession.GetDocumentAnalysis(primaryDocument).GetValueAsync(cancellationToken).ConfigureAwait(false); var currentActiveStatements = documentAnalysis.ActiveStatements; if (currentActiveStatements.IsDefault) { // The document has syntax errors. return(null); } return(currentActiveStatements[baseActiveStatement.PrimaryDocumentOrdinal].Span); } catch (Exception e) when(FatalError.ReportWithoutCrashUnlessCanceled(e)) { return(null); } }