提交 9b82ff15 编写于 作者: J Jason Malinowski

Add Project.RemoveDocuments() as a helper method as well

上级 f3a71f06
*REMOVED*Microsoft.CodeAnalysis.TextDocument.Project.set -> void
*REMOVED*Microsoft.CodeAnalysis.TextDocument.TextDocument() -> void
Microsoft.CodeAnalysis.Options.DocumentOptionSet.WithChangedOption<T>(Microsoft.CodeAnalysis.Options.PerLanguageOption<T> option, T value) -> Microsoft.CodeAnalysis.Options.DocumentOptionSet
Microsoft.CodeAnalysis.Project.RemoveDocuments(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.DocumentId> documentIds) -> Microsoft.CodeAnalysis.Project
Microsoft.CodeAnalysis.Solution.RemoveDocuments(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.DocumentId> documentIds) -> Microsoft.CodeAnalysis.Solution
Microsoft.CodeAnalysis.Solution.WithOptions(Microsoft.CodeAnalysis.Options.OptionSet options) -> Microsoft.CodeAnalysis.Solution
static Microsoft.CodeAnalysis.Formatting.Formatter.OrganizeImportsAsync(Microsoft.CodeAnalysis.Document document, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Microsoft.CodeAnalysis.Document>
......
......@@ -14,6 +14,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Collections.Immutable;
using Roslyn.Utilities;
......@@ -604,6 +605,23 @@ public Project RemoveDocument(DocumentId documentId)
return this.Solution.RemoveDocument(documentId).GetProject(this.Id)!;
}
/// <summary>
/// Creates a new instance of this project updated to no longer include the specified documents.
/// </summary>
public Project RemoveDocuments(ImmutableArray<DocumentId> documentIds)
{
foreach (var documentId in documentIds)
{
// Handling of null entries is handled by Solution.RemoveDocuments.
if (documentId?.ProjectId != this.Id)
{
throw new ArgumentException(string.Format(WorkspacesResources._0_is_in_a_different_project, documentId));
}
}
return this.Solution.RemoveDocuments(documentIds).GetRequiredProject(this.Id);
}
/// <summary>
/// Creates a new instance of this project updated to no longer include the specified additional document.
/// </summary>
......
......@@ -1440,4 +1440,7 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<data name="Document_does_not_support_syntax_trees" xml:space="preserve">
<value>Document does not support syntax trees</value>
</data>
<data name="_0_is_in_a_different_project" xml:space="preserve">
<value>{0} is in a different project.</value>
</data>
</root>
\ No newline at end of file
......@@ -1317,6 +1317,11 @@ Pozitivní kontrolní výrazy zpětného vyhledávání s nulovou délkou se obv
<target state="translated">Pracovní prostor není platný.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0} není součástí pracovního prostoru.</target>
......
......@@ -1317,6 +1317,11 @@ Positive Lookbehindassertionen mit Nullbreite werden normalerweise am Anfang reg
<target state="translated">Arbeitsbereich ist nicht leer.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'"{0}" ist nicht Teil des Arbeitsbereichs.</target>
......
......@@ -1317,6 +1317,11 @@ Las aserciones de búsqueda retrasada (lookbehind) positivas de ancho cero se us
<target state="translated">El área de trabajo no está vacía.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0}' no es parte del área de trabajo.</target>
......
......@@ -1317,6 +1317,11 @@ Les assertions arrière positives de largeur nulle sont généralement utilisée
<target state="translated">L'espace de travail n'est pas vide.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0}' ne fait pas partie de l'espace de travail.</target>
......
......@@ -1317,6 +1317,11 @@ Le asserzioni lookbehind positive di larghezza zero vengono usate in genere all'
<target state="translated">L'area di lavoro non è vuota.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0}' non fa parte dell'area di lavoro.</target>
......
......@@ -1317,6 +1317,11 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<target state="translated">ワークスペースが空ではありません。</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0}' はワークスペースの一部ではありません。</target>
......
......@@ -1317,6 +1317,11 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<target state="translated">작업 영역이 비어 있지 않습니다.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0}'은(는) 작업 영역의 일부가 아닙니다.</target>
......
......@@ -1317,6 +1317,11 @@ Pozytywne asercje wsteczne o zerowej szerokości są zwykle używane na początk
<target state="translated">Obszar roboczy nie jest pusty.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'Element „{0}” nie jest częścią obszaru roboczego.</target>
......
......@@ -1317,6 +1317,11 @@ As declarações de lookbehind positivas de largura zero normalmente são usadas
<target state="translated">Workspace não está vazio.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">"{0}" não é parte do workspace.</target>
......
......@@ -1317,6 +1317,11 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<target state="translated">Рабочая область не пуста.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'"{0}" не является частью рабочей области.</target>
......
......@@ -1317,6 +1317,11 @@ Sıfır genişlikli pozitif geri yönlü onaylamalar genellikle normal ifadeleri
<target state="translated">Çalışma alanı boş değil.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0}' çalışma alanının parçası değildir.</target>
......
......@@ -1317,6 +1317,11 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<target state="translated">工作区不为空。</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'“{0}”不是工作区的一部分。</target>
......
......@@ -1317,6 +1317,11 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<target state="translated">工作區不是空的。</target>
<note />
</trans-unit>
<trans-unit id="_0_is_in_a_different_project">
<source>{0} is in a different project.</source>
<target state="new">{0} is in a different project.</target>
<note />
</trans-unit>
<trans-unit id="_0_is_not_part_of_the_workspace">
<source>'{0}' is not part of the workspace.</source>
<target state="translated">'{0}' 不是工作區的一部分。</target>
......
......@@ -241,6 +241,24 @@ public void RemoveTwoDocumentsFromDifferentProjects()
Assert.All(solution.Projects, p => Assert.Empty(p.Documents));
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public void RemoveDocumentFromUnrelatedProject()
{
var projectId1 = ProjectId.CreateNewId();
var projectId2 = ProjectId.CreateNewId();
var documentInfo1 = DocumentInfo.Create(DocumentId.CreateNewId(projectId1), "file1.cs");
var solution = CreateSolution()
.AddProject(projectId1, "project1", "project1.dll", LanguageNames.CSharp)
.AddProject(projectId2, "project2", "project2.dll", LanguageNames.CSharp)
.AddDocument(documentInfo1);
// This should throw if we're removing one document from the wrong project. Right now we don't test the RemoveDocument
// API due to https://github.com/dotnet/roslyn/issues/41211.
Assert.Throws<ArgumentException>(() => solution.GetProject(projectId2).RemoveDocuments(ImmutableArray.Create(documentInfo1.Id)));
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public async Task TestOneCSharpProjectAsync()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册