diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractRoslynTableDataSource.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractRoslynTableDataSource.cs index 9a72c55db1eb8ec368997e0315fa92d2785e17c0..65408099e6ca8e2ccdf2eaec5574157c241fefc0 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractRoslynTableDataSource.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/AbstractRoslynTableDataSource.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.SolutionCrawler; @@ -16,6 +17,17 @@ public AbstractRoslynTableDataSource(Workspace workspace) : base(workspace) ConnectToSolutionCrawlerService(workspace); } + protected ImmutableArray GetDocumentsWithSameFilePath(Solution solution, DocumentId documentId) + { + var document = solution.GetDocument(documentId); + if (document == null) + { + return ImmutableArray.Empty; + } + + return solution.GetDocumentIdsWithFilePath(document.FilePath); + } + private void ConnectToSolutionCrawlerService(Workspace workspace) { var crawlerService = workspace.Services.GetService(); diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseDiagnosticListTable.LiveTableDataSource.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseDiagnosticListTable.LiveTableDataSource.cs index 3f2310c091a508f4ff402072b9d9ec966e83f02a..86fdfa2a51658fc7e30125625afa016d7df21ecf 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseDiagnosticListTable.LiveTableDataSource.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseDiagnosticListTable.LiveTableDataSource.cs @@ -111,7 +111,7 @@ private bool CheckAggregateKey(AggregatedKey key, DiagnosticsUpdatedArgs args) return true; } - var documents = args.Solution.GetRelatedDocumentIds(args.DocumentId); + var documents = GetDocumentsWithSameFilePath(args.Solution, args.DocumentId); return key.DocumentIds == documents; } @@ -129,7 +129,7 @@ private object CreateAggregationKey(object data) return GetItemKey(data); } - var documents = args.Solution.GetRelatedDocumentIds(args.DocumentId); + var documents = GetDocumentsWithSameFilePath(args.Solution, args.DocumentId); return new AggregatedKey(documents, liveArgsId.Analyzer, liveArgsId.Kind); } diff --git a/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseTodoListTable.cs b/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseTodoListTable.cs index a08438cdddd65bdc85fc021a6a14c2b53c91cf0b..a848fe76668000fa6341d6873d78fe5b975384c6 100644 --- a/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseTodoListTable.cs +++ b/src/VisualStudio/Core/Def/Implementation/TableDataSource/VisualStudioBaseTodoListTable.cs @@ -122,7 +122,7 @@ private bool CheckAggregateKey(ImmutableArray key, TodoItemsUpdatedA return true; } - var documents = args.Solution.GetRelatedDocumentIds(args.DocumentId); + var documents = GetDocumentsWithSameFilePath(args.Solution, args.DocumentId); return key == documents; } @@ -134,7 +134,7 @@ private object CreateAggregationKey(object data) return GetItemKey(data); } - return args.Solution.GetRelatedDocumentIds(args.DocumentId); + return GetDocumentsWithSameFilePath(args.Solution, args.DocumentId); } public override ImmutableArray> Deduplicate(IEnumerable>> groupedItems) diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/ISolutionExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/ISolutionExtensions.cs index 491702b362ecb757b6cfca59900e20fece0ab288..ee6f694ee39080a233671f51e5888c670446da87 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/ISolutionExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/ISolutionExtensions.cs @@ -1,12 +1,11 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; -using System.Linq; +using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Shared.Extensions { @@ -61,5 +60,17 @@ public static Solution WithTextDocumentText(this Solution solution, DocumentId d return solution.WithAdditionalDocumentText(documentId, text, mode); } } + + public static IEnumerable FilterDocumentIdsByLanguage(this Solution solution, ImmutableArray documentIds, string language) + { + foreach (var documentId in documentIds) + { + var document = solution.GetDocument(documentId); + if (document != null && document.Project.Language == language) + { + yield return documentId; + } + } + } } } diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs index b8f99d4ddd14dddfb3849bb8b1667bef7f575efd..718ae78ff58d969be4aea52ee732ec16812f24c9 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Document.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Internal.Log; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -386,7 +387,8 @@ public async Task> GetTextChangesAsync(Document oldDocum public ImmutableArray GetLinkedDocumentIds() { var documentIdsWithPath = this.Project.Solution.GetDocumentIdsWithFilePath(this.FilePath); - return documentIdsWithPath.Remove(this.Id); + var filteredDocumentIds = this.Project.Solution.FilterDocumentIdsByLanguage(documentIdsWithPath, this.Project.Language).ToImmutableArray(); + return filteredDocumentIds.Remove(this.Id); } /// diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs index 81f43389d5c8429a35dc267b06ddb061060cadfa..903d4b27ca0c483c9ef779b97004920a6b4345a5 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.ErrorReporting; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Collections.Immutable; using Roslyn.Utilities; @@ -1836,7 +1837,8 @@ internal ImmutableArray GetRelatedDocumentIds(DocumentId documentId) return ImmutableArray.Create(documentId); } - return this.GetDocumentIdsWithFilePath(filePath); + var documentIds = this.GetDocumentIdsWithFilePath(filePath); + return this.FilterDocumentIdsByLanguage(documentIds, projectState.ProjectInfo.Language).ToImmutableArray(); } ///