protected Task RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind kind, Solution oldSolution, Solution newSolution, ProjectId projectId = null, DocumentId documentId = null) { if (newSolution == null) { throw new ArgumentNullException("newSolution"); } if (oldSolution == newSolution) { return SpecializedTasks.EmptyTask; } if (projectId == null && documentId != null) { projectId = documentId.ProjectId; } var handlers = this.eventMap.GetEventHandlers<EventHandler<WorkspaceChangeEventArgs>>(WorkspaceChangeEventName); if (handlers.Length > 0) { return this.ScheduleTask(() => { var args = new WorkspaceChangeEventArgs(kind, oldSolution, newSolution, projectId, documentId); foreach (var handler in handlers) { handler(this, args); } }, "Workspace.WorkspaceChanged"); } else { return SpecializedTasks.EmptyTask; } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { switch (e.Kind) { case WorkspaceChangeKind.SolutionAdded: case WorkspaceChangeKind.ProjectAdded: AddTableSourceIfNecessary(e.NewSolution); break; case WorkspaceChangeKind.SolutionRemoved: case WorkspaceChangeKind.ProjectRemoved: ShutdownSourceIfNecessary(e.NewSolution); RemoveTableSourceIfNecessary(e.NewSolution); break; case WorkspaceChangeKind.SolutionChanged: case WorkspaceChangeKind.SolutionCleared: case WorkspaceChangeKind.SolutionReloaded: case WorkspaceChangeKind.ProjectChanged: case WorkspaceChangeKind.ProjectReloaded: case WorkspaceChangeKind.DocumentAdded: case WorkspaceChangeKind.DocumentRemoved: case WorkspaceChangeKind.DocumentReloaded: case WorkspaceChangeKind.DocumentChanged: case WorkspaceChangeKind.AdditionalDocumentAdded: case WorkspaceChangeKind.AdditionalDocumentRemoved: case WorkspaceChangeKind.AdditionalDocumentReloaded: case WorkspaceChangeKind.AdditionalDocumentChanged: break; default: Contract.Fail("Can't reach here"); return; } }
protected Task RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind kind, Solution oldSolution, Solution newSolution, ProjectId projectId = null, DocumentId documentId = null) { if (newSolution == null) { throw new ArgumentNullException(nameof(newSolution)); } if (oldSolution == newSolution) { return SpecializedTasks.EmptyTask; } if (projectId == null && documentId != null) { projectId = documentId.ProjectId; } var ev = _eventMap.GetEventHandlers<EventHandler<WorkspaceChangeEventArgs>>(WorkspaceChangeEventName); if (ev.HasHandlers) { return this.ScheduleTask(() => { var args = new WorkspaceChangeEventArgs(kind, oldSolution, newSolution, projectId, documentId); ev.RaiseEvent(handler => handler(this, args)); }, "Workspace.WorkspaceChanged"); } else { return SpecializedTasks.EmptyTask; } }
private void Workspace_WorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { switch (e.Kind) { case WorkspaceChangeKind.SolutionAdded: case WorkspaceChangeKind.SolutionChanged: case WorkspaceChangeKind.SolutionReloaded: UpdateAnalyzers(); break; case WorkspaceChangeKind.SolutionRemoved: case WorkspaceChangeKind.SolutionCleared: _analyzersFolder.Workspace.WorkspaceChanged -= Workspace_WorkspaceChanged; break; case WorkspaceChangeKind.ProjectAdded: case WorkspaceChangeKind.ProjectReloaded: case WorkspaceChangeKind.ProjectChanged: if (e.ProjectId == _analyzersFolder.ProjectId) { UpdateAnalyzers(); } break; case WorkspaceChangeKind.ProjectRemoved: if (e.ProjectId == _analyzersFolder.ProjectId) { _analyzersFolder.Workspace.WorkspaceChanged -= Workspace_WorkspaceChanged; } break; } }
private async void WorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { if (e.Kind == WorkspaceChangeKind.DocumentRemoved) { var doc = e.OldSolution.GetDocument(e.DocumentId); _coverageStore.RemoveByFile(doc.FilePath); _coverageStore.RemoveByDocumentTestNodePath(doc.FilePath); _rewrittenDocumentsStorage.RemoveByDocument(doc.FilePath, doc.Project.Name, e.NewSolution.FilePath); DocumentRemoved?.Invoke(this, new DocumentRemovedEventArgs(doc.FilePath)); } else if (e.Kind == WorkspaceChangeKind.DocumentChanged) { var originalDoc = e.OldSolution.GetDocument(e.DocumentId); var newChangedDoc = e.NewSolution.GetDocument(e.DocumentId); var changes = await newChangedDoc.GetTextChangesAsync(originalDoc); if (changes.Any()) { string activeDocumentPath = _dte.ActiveDocument.FullName; if (!string.Equals(newChangedDoc.FilePath,activeDocumentPath,StringComparison.OrdinalIgnoreCase)) _taskCoverageManager.ResyncAll(); } } }
private async void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { switch (e.Kind) { case WorkspaceChangeKind.DocumentChanged: // Ensure the text version actually changed. This is necessary to not // cause Class View to update simply when a document is opened. var oldDocument = e.OldSolution.GetDocument(e.DocumentId); var newDocument = e.NewSolution.GetDocument(e.DocumentId); await DocumentChangedAsync(oldDocument, newDocument).ConfigureAwait(false); break; case WorkspaceChangeKind.ProjectAdded: case WorkspaceChangeKind.ProjectChanged: case WorkspaceChangeKind.ProjectReloaded: case WorkspaceChangeKind.ProjectRemoved: UpdatePackageVersion(); break; case WorkspaceChangeKind.SolutionAdded: case WorkspaceChangeKind.SolutionChanged: case WorkspaceChangeKind.SolutionCleared: case WorkspaceChangeKind.SolutionReloaded: case WorkspaceChangeKind.SolutionRemoved: UpdatePackageVersion(); break; } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { switch (e.Kind) { case WorkspaceChangeKind.DocumentChanged: // Ensure the text version actually changed. This is necessary to not // cause Class View to update simply when a document is opened. var oldDocument = e.OldSolution.GetDocument(e.DocumentId); var newDocument = e.NewSolution.GetDocument(e.DocumentId); // make sure we do this in background thread. we don't care about ordering of events // we just need to refresh OB at some point if it ever needs to be updated // link to the bug tracking root cause - https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?id=169649&_a=edit Task.Run(() => DocumentChangedAsync(oldDocument, newDocument)); break; case WorkspaceChangeKind.ProjectAdded: case WorkspaceChangeKind.ProjectChanged: case WorkspaceChangeKind.ProjectReloaded: case WorkspaceChangeKind.ProjectRemoved: UpdatePackageVersion(); break; case WorkspaceChangeKind.SolutionAdded: case WorkspaceChangeKind.SolutionChanged: case WorkspaceChangeKind.SolutionCleared: case WorkspaceChangeKind.SolutionReloaded: case WorkspaceChangeKind.SolutionRemoved: UpdatePackageVersion(); break; } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { // special bulk update case if (e.Kind == WorkspaceChangeKind.SolutionAdded || e.Kind == WorkspaceChangeKind.ProjectAdded) { _synchronize = true; EnqueueChecksumUpdate(); return; } // record that we are busy UpdateLastAccessTime(); EnqueueChecksumUpdate(); }
private void OnWorkspaceChanged(object source, WorkspaceChangeEventArgs args) { SimpleWorkspaceEvent e = null; switch (args.Kind) { case WorkspaceChangeKind.ProjectAdded: e = new SimpleWorkspaceEvent(args.NewSolution.GetProject(args.ProjectId).FilePath, EventTypes.ProjectAdded); break; case WorkspaceChangeKind.ProjectChanged: case WorkspaceChangeKind.ProjectReloaded: e = new SimpleWorkspaceEvent(args.NewSolution.GetProject(args.ProjectId).FilePath, EventTypes.ProjectChanged); break; case WorkspaceChangeKind.ProjectRemoved: e = new SimpleWorkspaceEvent(args.OldSolution.GetProject(args.ProjectId).FilePath, EventTypes.ProjectRemoved); break; } if (e != null) { lock (_lock) { var removed = _queue.Remove(e); _queue.Add(e); if (!removed) { Task.Factory.StartNew(async () => { await Task.Delay(500); object payload = null; if (e.EventType != EventTypes.ProjectRemoved) { payload = await GetProjectInformation(e.FileName); } lock (_lock) { _queue.Remove(e); _emitter.Emit(e.EventType, payload); } }); } } } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { switch (e.Kind) { case WorkspaceChangeKind.DocumentChanged: // Ensure the text version actually changed. This is necessary to not // cause Class View to update simply when a document is opened. var oldDocument = e.OldSolution.GetDocument(e.DocumentId); var newDocument = e.NewSolution.GetDocument(e.DocumentId); var oldTextVersion = oldDocument.GetTextVersionAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None); var newTextVersion = newDocument.GetTextVersionAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None); if (oldTextVersion != newTextVersion) { UpdateClassVersion(); UpdateMembersVersion(); } break; case WorkspaceChangeKind.ProjectAdded: case WorkspaceChangeKind.ProjectChanged: case WorkspaceChangeKind.ProjectReloaded: case WorkspaceChangeKind.ProjectRemoved: UpdatePackageVersion(); break; case WorkspaceChangeKind.SolutionAdded: case WorkspaceChangeKind.SolutionChanged: case WorkspaceChangeKind.SolutionCleared: case WorkspaceChangeKind.SolutionReloaded: case WorkspaceChangeKind.SolutionRemoved: UpdatePackageVersion(); break; } }
async void Ws_WorkspaceChanged (object sender, WorkspaceChangeEventArgs e) { var ws = (Microsoft.CodeAnalysis.Workspace)sender; var currentSolution = ws.CurrentSolution; if (currentSolution == null) return; try { switch (e.Kind) { case WorkspaceChangeKind.ProjectAdded: var project1 = currentSolution.GetProject (e.ProjectId); if (project1 != null) SearchAsync (documentInfos, project1, default (CancellationToken)); break; case WorkspaceChangeKind.ProjectRemoved: var project = currentSolution.GetProject (e.ProjectId); if (project != null) { foreach (var docId in project.DocumentIds) RemoveDocument (documentInfos, docId); } break; case WorkspaceChangeKind.DocumentAdded: var document = currentSolution.GetDocument (e.DocumentId); if (document != null) await UpdateDocument (documentInfos, document, default (CancellationToken)); break; case WorkspaceChangeKind.DocumentRemoved: RemoveDocument (documentInfos, e.DocumentId); break; case WorkspaceChangeKind.DocumentChanged: var doc = currentSolution.GetDocument (e.DocumentId); if (doc != null) { await Task.Run (async delegate { await UpdateDocument (documentInfos, doc, default (CancellationToken)); }).ConfigureAwait (false); } break; } } catch (AggregateException ae) { ae.Flatten ().Handle (ex => ex is OperationCanceledException); } catch (OperationCanceledException) { } catch (Exception ex) { LoggingService.LogError ("Error while updating navigation symbol cache.", ex); } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { EnqueueUpdate(); }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { if (e.Kind != WorkspaceChangeKind.SolutionAdded) { return; } // first make sure full solution analysis is on. (not user options but our internal options. even if our option is on, if user option is off // full solution analysis won't run. also, reset infobar state. _workspace.Options = _workspace.Options.WithChangedOption(RuntimeOptions.FullSolutionAnalysisInfoBarShown, false) .WithChangedOption(RuntimeOptions.FullSolutionAnalysis, true); }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { // record that we are busy UpdateLastAccessTime(); EnqueueChecksumUpdate(); }
async void Ws_WorkspaceChanged (object sender, WorkspaceChangeEventArgs e) { var ws = (Microsoft.CodeAnalysis.Workspace)sender; var currentSolution = ws.CurrentSolution; if (currentSolution == null) return; try { switch (e.Kind) { case WorkspaceChangeKind.ProjectAdded: var project1 = currentSolution.GetProject (e.ProjectId); if (project1 != null) SearchAsync (documentInfos, project1, default (CancellationToken)); break; case WorkspaceChangeKind.ProjectRemoved: var project = currentSolution.GetProject (e.ProjectId); if (project != null) { foreach (var docId in project.DocumentIds) RemoveDocument (documentInfos, docId); } break; case WorkspaceChangeKind.DocumentAdded: var document = currentSolution.GetDocument (e.DocumentId); if (document != null) await UpdateDocument (documentInfos, document, default (CancellationToken)); break; case WorkspaceChangeKind.DocumentRemoved: RemoveDocument (documentInfos, e.DocumentId); break; case WorkspaceChangeKind.DocumentChanged: var doc = currentSolution.GetDocument (e.DocumentId); if (doc != null) { CancellationTokenSource tcs; lock(documentChangedCts) { CancellationTokenSource oldTcs; if (documentChangedCts.TryGetValue (e.DocumentId, out oldTcs)) { oldTcs.Cancel (); } tcs = new CancellationTokenSource (); documentChangedCts [e.DocumentId] = tcs; } try { //Delaying parsing of new content for 1 second shouldn't be noticable by user //since he would have to edit file and instantlly go to search for newly written member... await Task.Delay (1000, tcs.Token).ConfigureAwait (false); await Task.Run (delegate { return UpdateDocument (documentInfos, doc, tcs.Token); }, tcs.Token).ConfigureAwait (false); } finally { lock (documentChangedCts) { //cts might be replaced by newer call cts CancellationTokenSource existingCts; if (documentChangedCts.TryGetValue (e.DocumentId, out existingCts) && tcs == existingCts) documentChangedCts.Remove (e.DocumentId); } } } break; } } catch (AggregateException ae) { ae.Flatten ().Handle (ex => ex is OperationCanceledException); } catch (OperationCanceledException) { } catch (Exception ex) { LoggingService.LogError ("Error while updating navigation symbol cache.", ex); } }
void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs args) { // We're getting an event for a workspace we already disconnected from if (args.NewSolution.Workspace != _workspace) { return; } if (args.Kind == WorkspaceChangeKind.SolutionChanged || args.Kind == WorkspaceChangeKind.SolutionAdded || args.Kind == WorkspaceChangeKind.SolutionRemoved || args.Kind == WorkspaceChangeKind.SolutionCleared || args.Kind == WorkspaceChangeKind.SolutionReloaded || args.Kind == WorkspaceChangeKind.ProjectAdded || args.Kind == WorkspaceChangeKind.ProjectChanged || args.Kind == WorkspaceChangeKind.ProjectReloaded || args.Kind == WorkspaceChangeKind.ProjectRemoved) { UpdateProjectItems(); } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { ThisCanBeCalledOnAnyThread(); bool localSolutionChanged = false; ProjectId localChangedProject = null; switch (e.Kind) { default: // Nothing to do for any other events. return; case WorkspaceChangeKind.ProjectAdded: case WorkspaceChangeKind.ProjectChanged: case WorkspaceChangeKind.ProjectReloaded: case WorkspaceChangeKind.ProjectRemoved: localChangedProject = e.ProjectId; break; case WorkspaceChangeKind.SolutionAdded: case WorkspaceChangeKind.SolutionChanged: case WorkspaceChangeKind.SolutionCleared: case WorkspaceChangeKind.SolutionReloaded: case WorkspaceChangeKind.SolutionRemoved: localSolutionChanged = true; break; } lock (_gate) { // Augment the data that the foreground thread will process. _solutionChanged |= localSolutionChanged; if (localChangedProject != null) { _changedProjects.Add(localChangedProject); } // Now cancel any inflight work that is processing the data. _tokenSource.Cancel(); _tokenSource = new CancellationTokenSource(); // And enqueue a new job to process things. Wait one second before starting. // That way if we get a flurry of events we'll end up processing them after // they've all come in. var cancellationToken = _tokenSource.Token; Task.Delay(TimeSpan.FromSeconds(1), cancellationToken) .ContinueWith(_ => ProcessBatchedChangesOnForeground(cancellationToken), cancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, this.ForegroundTaskScheduler); } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs args) { string fileName = null; if (args.Kind == WorkspaceChangeKind.DocumentAdded) { fileName = args.NewSolution.GetDocument(args.DocumentId).FilePath; } else if (args.Kind == WorkspaceChangeKind.DocumentRemoved) { fileName = args.OldSolution.GetDocument(args.DocumentId).FilePath; } if (fileName == null) { return; } lock (_lock) { if (_transientDocumentIds.Contains(args.DocumentId)) { return; } IEnumerable<DocumentId> documentIds; if (!_transientDocuments.TryGetValue(fileName, out documentIds)) { return; } _transientDocuments.Remove(fileName); foreach (var documentId in documentIds) { _workspace.RemoveDocument(documentId); _transientDocumentIds.Remove(documentId); } } }
void Workspace_WorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { if (isDisposed) return; if (e.Kind != WorkspaceChangeKind.DocumentChanged) return; docChangedEventCount++; if (docChangedEventCount != documents.Count) return; workspace.WorkspaceChanged -= Workspace_WorkspaceChanged; foreach (var doc in documents) roslynDocumentChangedService.RaiseDocumentChanged(doc.TextView.TextSnapshot); }
private void Workspace_WorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { if (e.Kind == WorkspaceChangeKind.SolutionCleared || e.Kind == WorkspaceChangeKind.SolutionReloaded || e.Kind == WorkspaceChangeKind.SolutionRemoved) { _workspace.WorkspaceChanged -= Workspace_WorkspaceChanged; } else if (e.ProjectId == _projectId) { if (e.Kind == WorkspaceChangeKind.ProjectRemoved) { _workspace.WorkspaceChanged -= Workspace_WorkspaceChanged; } else if (e.Kind == WorkspaceChangeKind.ProjectChanged) { var project = e.NewSolution.GetProject(_projectId); var newGeneralDiagnosticOption = project.CompilationOptions.GeneralDiagnosticOption; var newSpecificDiagnosticOptions = project.CompilationOptions.SpecificDiagnosticOptions; if (newGeneralDiagnosticOption != _generalDiagnosticOption || !object.ReferenceEquals(newSpecificDiagnosticOptions, _specificDiagnosticOptions)) { _generalDiagnosticOption = newGeneralDiagnosticOption; _specificDiagnosticOptions = newSpecificDiagnosticOptions; foreach (var item in _diagnosticItems) { item.UpdateEffectiveSeverity(GetEffectiveSeverity(item.Descriptor.Id, _specificDiagnosticOptions, _generalDiagnosticOption, item.Descriptor.DefaultSeverity, item.Descriptor.IsEnabledByDefault)); } } } } }
private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs e) { // special initial case if (e.Kind == WorkspaceChangeKind.SolutionAdded) { CreateInitialSolutionChecksum(); return; } // record that we are busy UpdateLastAccessTime(); // event will raised sequencially. no concurrency on this handler if (_event.CurrentCount > 0) { return; } _event.Release(); }