提交 7d069ed0 编写于 作者: J Jason Malinowski

Null annotate all the undo units we create for workspace change application

上级 e5cf10bd
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.OLE.Interop;
......
......@@ -2,9 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.AddImport;
using Microsoft.VisualStudio.OLE.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
......@@ -25,7 +27,7 @@ private abstract class AbstractRemoveDocumentUndoUnit : AbstractAddRemoveUndoUni
protected abstract IReadOnlyList<DocumentId> GetDocumentIds(Project fromProject);
protected abstract TextDocument GetDocument(Solution currentSolution);
protected abstract TextDocument? GetDocument(Solution currentSolution);
public override void Do(IOleUndoManager pUndoManager)
{
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.IO;
using System.Linq;
......@@ -29,22 +31,25 @@ public override void Do(IOleUndoManager pUndoManager)
{
var currentSolution = Workspace.CurrentSolution;
var fromProject = currentSolution.GetProject(FromProjectId);
var reference = fromProject?.MetadataReferences.OfType<PortableExecutableReference>()
.FirstOrDefault(p => StringComparer.OrdinalIgnoreCase.Equals(p.FilePath, _filePath));
if (reference == null)
if (fromProject != null)
{
try
{
reference = MetadataReference.CreateFromFile(_filePath);
}
catch (IOException)
var reference = fromProject.MetadataReferences.OfType<PortableExecutableReference>()
.FirstOrDefault(p => StringComparer.OrdinalIgnoreCase.Equals(p.FilePath, _filePath));
if (reference == null)
{
return;
}
try
{
reference = MetadataReference.CreateFromFile(_filePath);
}
catch (IOException)
{
return;
}
var updatedProject = fromProject.AddMetadataReference(reference);
Workspace.TryApplyChanges(updatedProject.Solution);
var updatedProject = fromProject.AddMetadataReference(reference);
Workspace.TryApplyChanges(updatedProject.Solution);
}
}
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
......
......@@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
......@@ -21,7 +24,7 @@ private class RemoveAdditionalDocumentUndoUnit : AbstractRemoveDocumentUndoUnit
protected override IReadOnlyList<DocumentId> GetDocumentIds(Project fromProject)
=> fromProject.AdditionalDocumentIds;
protected override TextDocument GetDocument(Solution currentSolution)
protected override TextDocument? GetDocument(Solution currentSolution)
=> currentSolution.GetAdditionalDocument(this.DocumentId);
}
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
......@@ -21,7 +23,7 @@ private class RemoveAnalyzerConfigDocumentUndoUnit : AbstractRemoveDocumentUndoU
protected override IReadOnlyList<DocumentId> GetDocumentIds(Project fromProject)
=> fromProject.State.AnalyzerConfigDocumentIds.AsImmutable();
protected override TextDocument GetDocument(Solution currentSolution)
protected override TextDocument? GetDocument(Solution currentSolution)
=> currentSolution.GetAnalyzerConfigDocument(this.DocumentId);
}
}
......
......@@ -2,8 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
{
......@@ -21,7 +24,7 @@ private class RemoveDocumentUndoUnit : AbstractRemoveDocumentUndoUnit
protected override IReadOnlyList<DocumentId> GetDocumentIds(Project fromProject)
=> fromProject.DocumentIds;
protected override TextDocument GetDocument(Solution currentSolution)
protected override TextDocument? GetDocument(Solution currentSolution)
=> currentSolution.GetDocument(this.DocumentId);
}
}
......
......@@ -2,10 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.OLE.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
......@@ -29,13 +32,16 @@ public override void Do(IOleUndoManager pUndoManager)
{
var currentSolution = Workspace.CurrentSolution;
var fromProject = currentSolution.GetProject(FromProjectId);
var reference = fromProject?.MetadataReferences.OfType<PortableExecutableReference>()
.FirstOrDefault(p => StringComparer.OrdinalIgnoreCase.Equals(p.FilePath, _filePath));
if (reference != null)
if (fromProject != null)
{
var updatedProject = fromProject.RemoveMetadataReference(reference);
Workspace.TryApplyChanges(updatedProject.Solution);
var reference = fromProject.MetadataReferences.OfType<PortableExecutableReference>()
.FirstOrDefault(p => StringComparer.OrdinalIgnoreCase.Equals(p.FilePath!, _filePath));
if (reference != null)
{
var updatedProject = fromProject.RemoveMetadataReference(reference);
Workspace.TryApplyChanges(updatedProject.Solution);
}
}
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.OLE.Interop;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Linq;
using Microsoft.VisualStudio.OLE.Interop;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册