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 ClearAnalyzerDiagnostics(ImmutableArray<DiagnosticAnalyzer> analyzers, ProjectId projectId) { foreach (var analyzer in analyzers) { ClearAnalyzerDiagnostics(analyzer, projectId); } }
public UpdatedEventArgs(object id, Workspace workspace, ProjectId projectId, DocumentId documentId) { this.Id = id; this.Workspace = workspace; this.ProjectId = projectId; this.DocumentId = documentId; }
public ActionAssignedToProject(TenantId id, ActionId action, ProjectId newProject, DateTime timeUtc) { Id = id; Action = action; NewProject = newProject; TimeUtc = timeUtc; }
protected override Solution CreateSolution(ProjectId projectId, string language) { Solution solution = base.CreateSolution(projectId, language); Project project = solution.GetProject(projectId); return solution.WithProjectParseOptions(projectId, project.ParseOptions.WithDocumentationMode(this.documentationMode)); }
protected AbstractAddRemoveUndoUnit( VisualStudioWorkspaceImpl workspace, ProjectId fromProjectId) { Workspace = workspace; FromProjectId = fromProjectId; }
public DiagnosticGetter( DiagnosticIncrementalAnalyzer owner, Solution solution, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics) { Owner = owner; CurrentSolution = solution; CurrentDocumentId = documentId; CurrentProjectId = projectId ?? documentId?.ProjectId; Id = id; IncludeSuppressedDiagnostics = includeSuppressedDiagnostics; // try to retrieve projectId/documentId from id if possible. var argsId = id as LiveDiagnosticUpdateArgsId; if (argsId != null) { CurrentDocumentId = CurrentDocumentId ?? argsId.Key as DocumentId; CurrentProjectId = CurrentProjectId ?? (argsId.Key as ProjectId) ?? CurrentDocumentId.ProjectId; } _builder = null; }
public async Task<Compilation> GetCompilationAsync(Checksum solutionChecksum, ProjectId projectId, CancellationToken cancellationToken) { var solution = await RoslynServices.SolutionService.GetSolutionAsync(solutionChecksum, cancellationToken).ConfigureAwait(false); // TODO: need to figure out how to deal with exceptions in service hub return await solution.GetProject(projectId).GetCompilationAsync(cancellationToken).ConfigureAwait(false); }
public void RemoveProject(ProjectId projectId) { long unused; _map.TryRemove(projectId, out unused); _size = _map.Values.Sum(); }
public IList<string> GetFolders(ProjectId projectId, Workspace workspace) { var folders = new List<string>(); if (workspace is VisualStudioWorkspaceImpl) { ((VisualStudioWorkspaceImpl)workspace).GetProjectData(projectId, out var ivisualStudioHostProject, out var hierarchy, out var envDTEProject); var projectItems = envDTEProject.ProjectItems; var projectItemsStack = new Stack<Tuple<ProjectItem, string>>(); // Populate the stack projectItems.OfType<ProjectItem>().Where(n => n.IsFolder()).Do(n => projectItemsStack.Push(Tuple.Create(n, "\\"))); while (projectItemsStack.Count != 0) { var projectItemTuple = projectItemsStack.Pop(); var projectItem = projectItemTuple.Item1; var currentFolderPath = projectItemTuple.Item2; var folderPath = currentFolderPath + projectItem.Name + "\\"; folders.Add(folderPath); projectItem.ProjectItems.OfType<ProjectItem>().Where(n => n.IsFolder()).Do(n => projectItemsStack.Push(Tuple.Create(n, folderPath))); } } return folders; }
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; } }
public override void RemoveProject(ProjectId projectId) { if (_symbolCountByProjectMap != null) { _symbolCountByProjectMap.Remove(projectId); } }
protected ReferenceChange(ProjectId projectId, string projectName, bool isAddedReference, PreviewEngine engine) : base(engine) { _projectId = projectId; _projectName = projectName; _isAddedReference = isAddedReference; }
internal void ReportAnalyzerDiagnostic(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Workspace workspace, ProjectId projectId) { if (workspace != this.Workspace) { return; } var project = workspace.CurrentSolution.GetProject(projectId); bool raiseDiagnosticsUpdated = true; var diagnosticData = project != null ? DiagnosticData.Create(project, diagnostic) : DiagnosticData.Create(this.Workspace, diagnostic); var dxs = ImmutableInterlocked.AddOrUpdate(ref s_analyzerHostDiagnosticsMap, analyzer, ImmutableHashSet.Create(diagnosticData), (a, existing) => { var newDiags = existing.Add(diagnosticData); raiseDiagnosticsUpdated = newDiags.Count > existing.Count; return newDiags; }); if (raiseDiagnosticsUpdated) { RaiseDiagnosticsUpdated(MakeArgs(analyzer, dxs, project)); } }
public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Solution solution, ProjectId projectId, DocumentId documentId, CancellationToken cancellationToken) { if (solution == null) { return GetDiagnosticData(); } if (documentId != null) { var document = solution.GetDocument(documentId); await AppendDiagnosticsAsync(document, cancellationToken).ConfigureAwait(false); await AppendProjectAndDocumentDiagnosticsAsync(document.Project, document, d => d.DocumentId == documentId, cancellationToken).ConfigureAwait(false); return GetDiagnosticData(); } if (projectId != null) { await AppendDiagnosticsAsync(solution.GetProject(projectId), cancellationToken: cancellationToken).ConfigureAwait(false); return GetDiagnosticData(); } await AppendDiagnosticsAsync(solution, cancellationToken: cancellationToken).ConfigureAwait(false); return GetDiagnosticData(); }
public SolutionPreviewItem(ProjectId projectId, DocumentId documentId, string text) { ProjectId = projectId; DocumentId = documentId; Text = text; LazyPreview = c => Task.FromResult<object>(text); }
public void UpdateReferences(ProjectId projectId, FrameworkProject frameworkProject) { DnxProject project = FindProject (projectId); if (project != null) { UpdateReferences (project, frameworkProject); } }
public void RemoveProject(ProjectId projectId) { foreach (var documentId in _map.Keys.Where(id => id.ProjectId == projectId).ToArray()) { RemoveDocument(documentId); } }
public DiagnosticData( string id, string category, string message, string enuMessageForBingSearch, DiagnosticSeverity severity, bool isEnabledByDefault, int warningLevel, Workspace workspace, ProjectId projectId, DocumentId documentId = null, TextSpan? span = null, string originalFilePath = null, int originalStartLine = 0, int originalStartColumn = 0, int originalEndLine = 0, int originalEndColumn = 0, string title = null, string description = null, string helpLink = null) : this( id, category, message, enuMessageForBingSearch, severity, severity, isEnabledByDefault, warningLevel, ImmutableArray<string>.Empty, ImmutableDictionary<string, string>.Empty, workspace, projectId, documentId, span, null, originalStartLine, originalStartColumn, originalEndLine, originalEndColumn, originalFilePath, originalStartLine, originalStartColumn, originalEndLine, originalEndColumn, title, description, helpLink) { }
void IProjectView.ShowView(FilteredProject project) { _region.SwitchTo("project-view"); this.Sync(() => { _project = project.Info.ProjectId; _projectName.Text = string.Format("{0} ({1})", project.Info.Outcome, project.ActionCount); // TODO: smarter update for the case when we remove item if (_source.Count == project.FilteredActions.Count) { for (int i = 0; i < project.FilteredActions.Count; i++) { _source[i] = new ActionDisplay(project.FilteredActions[i], this); } return; } _source.Clear(); foreach (var action in project.FilteredActions) { _source.Add(new ActionDisplay(action, this)); } }); }
private CodeTypeRef(CodeModelState state, object parent, ProjectId projectId, ITypeSymbol typeSymbol) : base(state) { _parentHandle = new ParentHandle<object>(parent); _projectId = projectId; _symbolId = typeSymbol.GetSymbolKey(); }
private DiagnosticData CreateDiagnostic(ProjectId projectId, AnalyzerDependencyConflict conflict) { string id = ServicesVSResources.WRN_AnalyzerDependencyConflictId; string category = ServicesVSResources.ErrorCategory; string message = string.Format( ServicesVSResources.WRN_AnalyzerDependencyConflictMessage, conflict.DependencyFilePath1, Path.GetFileNameWithoutExtension(conflict.AnalyzerFilePath1), conflict.DependencyFilePath2, Path.GetFileNameWithoutExtension(conflict.AnalyzerFilePath2)); DiagnosticData data = new DiagnosticData( id, category, message, ServicesVSResources.WRN_AnalyzerDependencyConflictMessage, severity: DiagnosticSeverity.Warning, defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, warningLevel: 0, customTags: ImmutableArray<string>.Empty, workspace: _workspace, projectId: projectId); return data; }
public DiagnosticsUpdatedArgs( object id, Workspace workspace, Solution solution, ProjectId projectId, DocumentId documentId, ImmutableArray<DiagnosticData> diagnostics) : base(id, workspace, projectId, documentId) { this.Solution = solution; this.Diagnostics = diagnostics; }
public TodoItemsUpdatedArgs( object id, Workspace workspace, Solution solution, ProjectId projectId, DocumentId documentId, ImmutableArray<TodoItem> todoItems) : base(id, workspace, projectId, documentId) { this.Solution = solution; this.TodoItems = todoItems; }
public static bool TryGetImageListAndIndex(this VisualStudioWorkspaceImpl workspace, IVsImageService2 imageService, ProjectId id, out IntPtr imageList, out int index) { var result = TryGetImageListAndIndex(workspace, imageService, id, out imageList, out ushort ushortIndex); index = ushortIndex; return result; }
private ExternalOverloadsCollection( CodeModelState state, ExternalCodeFunction parent, ProjectId projectId) : base(state, parent) { _projectId = projectId; }
public RemoveMetadataReferenceUndoUnit( VisualStudioWorkspaceImpl workspace, ProjectId fromProjectId, string filePath) : base(workspace, fromProjectId) { _filePath = filePath; }
public static DocumentId AddDocument(this Workspace workspace, ProjectId projectId, IEnumerable<string> folders, string name, SourceText initialText, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular) { var id = projectId.CreateDocumentId(name, folders); var oldSolution = workspace.CurrentSolution; var newSolution = oldSolution.AddDocument(id, name, initialText, folders).GetDocument(id).WithSourceCodeKind(sourceCodeKind).Project.Solution; workspace.TryApplyChanges(newSolution); return id; }
internal static EnvDTE.CodeElements Create( CodeModelState state, ExternalCodeFunction parent, ProjectId projectId) { var collection = new ExternalOverloadsCollection(state, parent, projectId); return (EnvDTE.CodeElements)ComAggregate.CreateAggregatedObject(collection); }
internal void RaiseTaskListUpdated(object id, Workspace workspace, ProjectId projectId, DocumentId documentId, ImmutableArray<ITaskItem> items) { var handler = this.TodoListUpdated; if (handler != null) { handler(this, new TaskListEventArgs(Tuple.Create(this, id), PredefinedTaskItemTypes.Todo, workspace, projectId, documentId, items)); } }
public void OnProjectReferenceAdded(ProjectId projectId, ProjectReference projectReference) { }
internal bool HasProject(ProjectId id) { return(Projects.TryGetValue(id, out var reason)); }
public void ClearAnalyzerDiagnostics(ImmutableArray <DiagnosticAnalyzer> analyzers, ProjectId projectId) { foreach (var analyzer in analyzers) { ClearAnalyzerDiagnostics(analyzer, projectId); } }
public ImmutableArray <DiagnosticData> GetDiagnostics(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) { return(ImmutableArray <DiagnosticData> .Empty); }
public void ClearAnalyzerReferenceDiagnostics(AnalyzerFileReference analyzerReference, string language, ProjectId projectId) { var analyzers = analyzerReference.GetAnalyzers(language); ClearAnalyzerDiagnostics(analyzers, projectId); CompilationWithAnalyzers.ClearAnalyzerState(analyzers); }
public IEnumerable <UpdatedEventArgs> GetDiagnosticsUpdatedEventArgs(Workspace workspace, ProjectId projectId, DocumentId documentId, CancellationToken cancellationToken) { Assert.Equal(workspace, _workspace); Assert.Equal(projectId, GetProjectId()); Assert.Equal(documentId, GetDocumentId()); if (_diagnostic == null) { yield break; } else { yield return(new UpdatedEventArgs(this, workspace, GetProjectId(), GetDocumentId())); } }
async Task InitializeAsync(ITextBuffer buffer, string code, MetadataReference[] refs, string languageName, ISynchronousTagger <IClassificationTag> tagger, CompilationOptions compilationOptions, ParseOptions parseOptions) { using (var workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices)) { var documents = new List <DocumentInfo>(); var projectId = ProjectId.CreateNewId(); documents.Add(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "main.cs", null, SourceCodeKind.Regular, TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create()))); var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", Guid.NewGuid().ToString(), languageName, compilationOptions: compilationOptions .WithOptimizationLevel(OptimizationLevel.Release) .WithPlatform(Platform.AnyCpu) .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default), parseOptions: parseOptions, documents: documents, metadataReferences: refs, isSubmission: false, hostObjectType: null); workspace.AddProject(projectInfo); foreach (var doc in documents) { workspace.OpenDocument(doc.Id); } buffer.Replace(new Span(0, buffer.CurrentSnapshot.Length), code); { // Initialize classification code paths var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); foreach (var tagSpan in tagger.GetTags(spans, CancellationToken.None)) { } } { // Initialize completion code paths var info = CompletionInfo.Create(buffer.CurrentSnapshot); Debug2.Assert(info is not null); if (info is not null) { var completionTrigger = CompletionTrigger.Invoke; var completionList = await info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, 0, completionTrigger); } } { // Initialize signature help code paths var info = SignatureHelpInfo.Create(buffer.CurrentSnapshot); Debug2.Assert(info is not null); if (info is not null) { int sigHelpIndex = code.IndexOf("sighelp"); Debug.Assert(sigHelpIndex >= 0); var triggerInfo = new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.InvokeSignatureHelpCommand); var items = await info.Value.SignatureHelpService.GetItemsAsync(info.Value.Document, sigHelpIndex, triggerInfo); } } { // Initialize quick info code paths var info = QuickInfoState.Create(buffer.CurrentSnapshot); Debug2.Assert(info is not null); if (info is not null) { int quickInfoIndex = code.IndexOf("Equals"); Debug.Assert(quickInfoIndex >= 0); var item = await info.Value.QuickInfoService.GetItemAsync(info.Value.Document, quickInfoIndex); } } } }
public static string?GetDebugName(this ProjectId projectId) => projectId.DebugName;
internal static EnvDTE.CodeModel Create(CodeModelState state, EnvDTE.Project parent, ProjectId projectId) { var rootCodeModel = new RootCodeModel(state, parent, projectId); return((EnvDTE.CodeModel)ComAggregate.CreateAggregatedObject(rootCodeModel)); }
public void OnOutputFilePathChanged(ProjectId id, string outputFilePath) { }
public new void OnParseOptionsChanged(ProjectId projectId, ParseOptions parseOptions) { base.OnParseOptionsChanged(projectId, parseOptions); }
public new void OnProjectReferenceRemoved(ProjectId projectId, ProjectReference projectReference) { base.OnProjectReferenceRemoved(projectId, projectReference); }
public new void OnProjectRemoved(ProjectId projectId) { base.OnProjectRemoved(projectId); }
// internal for testing purposes. internal Action <Exception, DiagnosticAnalyzer, Diagnostic> GetOnAnalyzerException(ProjectId projectId) { return(Owner.GetOnAnalyzerException(projectId, DiagnosticLogAggregator)); }
public void ReportAnalyzerDiagnostic(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Workspace workspace, ProjectId projectIdOpt) { if (workspace != this.Workspace) { return; } // check whether we are reporting project specific diagnostic or workspace wide diagnostic var project = projectIdOpt != null?workspace.CurrentSolution.GetProject(projectIdOpt) : null; // check whether project the diagnostic belong to still exist if (projectIdOpt != null && project == null) { // project the diagnostic belong to already removed from the solution. // ignore the diagnostic return; } var diagnosticData = project != null? DiagnosticData.Create(project, diagnostic) : DiagnosticData.Create(this.Workspace, diagnostic); ReportAnalyzerDiagnostic(analyzer, diagnosticData, project); }
/// <summary> /// True if given project has any diagnostics /// </summary> public abstract bool ContainsDiagnostics(Workspace workspace, ProjectId projectId);
public HostArgsId(AbstractHostDiagnosticUpdateSource source, DiagnosticAnalyzer analyzer, ProjectId projectIdOpt) : base(analyzer) { _source = source; _projectIdOpt = projectIdOpt; }
/// <summary> /// Get diagnostics matching one of a set of diagnostic IDs that are not associated with a particular document. /// </summary> /// <param name="solution">The solution. If projectId is null, returned diagnostics are for the entire solution.</param> /// <param name="projectId">If projectId is non null, returned diagnostics are for that project only.</param> /// <param name="diagnosticIds">The diagnostic IDs to match.</param> /// <param name="includeSuppressedDiagnostics">Flag indicating whether diagnostics with source suppressions (pragma/SuppressMessageAttribute) should be included.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public abstract Task <ImmutableArray <DiagnosticData> > GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId projectId = null, ImmutableHashSet <string> diagnosticIds = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken));
public ImmutableArray <DiagnosticData> GetDiagnostics(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken)) { return(includeSuppressedDiagnostics ? diagnostics : diagnostics.WhereAsArray(d => !d.IsSuppressed)); }
/// <summary> /// Get diagnostics associated with a particular document, project, or solution. /// </summary> /// <param name="solution">The solution. If projectId and documentId are both null, returned diagnostics are for the entire solution.</param> /// <param name="projectId">If projectId is non null and documentId is null, returned diagnostics are for that project only.</param> /// <param name="documentId">If documentId is non null, returned diagnostics are for that document only.</param> /// <param name="includeSuppressedDiagnostics">Flag indicating whether diagnostics with source suppressions (pragma/SuppressMessageAttribute) should be included.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public abstract Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(Solution solution, ProjectId projectId = null, DocumentId documentId = null, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken));
public void OnProjectRemoved(ProjectId projectId) { }
/// <summary> /// Flush diagnostics produced by a prior analysis of a project, /// and suppress future analysis of the project. /// Calls <see cref="DiagnosticAnalyzerService.RaiseDiagnosticsUpdated(DiagnosticsUpdatedArgs)"/> with an empty collection. /// </summary> /// <param name="projectId"></param> public abstract void RemoveProject(ProjectId projectId);
public void OnProjectReferenceRemoved(ProjectId projectId, ProjectReference projectReference) { }
public void AddOthers(ProjectId unused, ImmutableArray <DiagnosticData> diagnostics) { _others = diagnostics; }
public Builder(ProjectId projectId, VersionStamp version, ImmutableHashSet <DocumentId> documentIds = null) { _projectId = projectId; _version = version; _documentIds = documentIds; }
public ProjectState(StateSet owner, ProjectId projectId) { _owner = owner; _lastResult = new DiagnosticAnalysisResult(projectId, VersionStamp.Default, documentIds: null, isEmpty: true, fromBuild: false); }
public void OnProjectNameChanged(ProjectId projectId, string name, string filePath) { }
public bool OnProjectRemoved(ProjectId id) { RemoveInMemoryCacheEntry(id, _owner.NonLocalStateName); return(!IsEmpty()); }
public void OnOptionsChanged(ProjectId projectId, CompilationOptions compilationOptions, ParseOptions parseOptions) { }
private RootCodeModel(CodeModelState state, EnvDTE.Project parent, ProjectId projectId) : base(state) { _parentHandle = new ParentHandle <EnvDTE.Project>(parent); _projectId = projectId; }