Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start annotating project-system for nullability. #4404

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build/Test.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@
<Rules AnalyzerId="xunit.analyzers" RuleNamespace="xunit.analyzers">
<Rule Id="xUnit1026" Action="None" /> <!-- Theory methods must use all parameters -->
<Rule Id="xUnit1004" Action="None" /> <!-- Test methods should not be skipped -->

<!-- Disabled these two rules until we pick up a compiler with the fix for workaround https://github.com/dotnet/roslyn/issues/31740. -->
<Rule Id="xUnit1009" Action="None" /> <!-- InlineData values must match the number of method parameters -->
<Rule Id="xUnit1010" Action="None" /> <!-- The value is not convertible to the method parameter '{0}' of type '{1}'. -->
<Rule Id="xUnit1019" Action="None" /> <!-- MemberData must reference a data type assignable to '{0}'. The reference type '{1}' is not valid. -->
</Rules>
</RuleSet>
2 changes: 1 addition & 1 deletion build/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<VSWhereVersion>2.3.2</VSWhereVersion>
<TRXUnitVersion>1.0.0-beta1</TRXUnitVersion>
<MicrosoftDotNetIBCMergeVersion>4.7.1-alpha-00001</MicrosoftDotNetIBCMergeVersion>
<MicrosoftNetCompilersVersion>2.11.0-beta2-63529-05</MicrosoftNetCompilersVersion>
<MicrosoftNetCompilersVersion>3.0.0-beta2-18616-01</MicrosoftNetCompilersVersion>
<MicrosoftDiaSymReaderPdb2PdbVersion>1.1.0-beta1-62624-01</MicrosoftDiaSymReaderPdb2PdbVersion>
<RoslynAnalyzersPackagesVersion>2.6.3-beta1.18614.2</RoslynAnalyzersPackagesVersion>
<OpenCoverVersion>4.6.519</OpenCoverVersion>
Expand Down
6 changes: 3 additions & 3 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function InstallToolset {
}

if (!(Test-Path $ToolsetBuildProj)) {
& $MsbuildExe $ToolsetRestoreProj /t:restore /m /nologo /clp:None /warnaserror /v:quiet /p:NuGetPackageRoot=$NuGetPackageRoot /p:BaseIntermediateOutputPath=$ToolsetDir /p:ExcludeRestorePackageImports=true $logCmd
& $MsbuildExe $ToolsetRestoreProj /t:restore /m /nologo /clp:None /p:TreatWarningsAsErrors=true /v:quiet /p:NuGetPackageRoot=$NuGetPackageRoot /p:BaseIntermediateOutputPath=$ToolsetDir /p:ExcludeRestorePackageImports=true $logCmd
}
}

Expand All @@ -180,14 +180,14 @@ function Build {
$useCodecov = $ci -and $env:CODECOV_TOKEN -and ($configuration -eq 'Debug') -and ($env:ghprbPullAuthorLogin -ne 'dotnet-bot')
$useOpenCover = $useCodecov

& $MsbuildExe $ToolsetBuildProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /warnaserror /v:$verbosity $logCmd /p:Configuration=$configuration /p:SolutionPath=$solution /p:Restore=$restore /p:QuietRestore=true /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:IntegrationTest="false" /p:Sign=$sign /p:Pack=$pack /p:UseCodecov=$useCodecov /p:UseOpenCover=$useOpenCover /p:CIBuild=$ci /p:Optimize=$optimize /p:NuGetPackageRoot=$NuGetPackageRoot $properties
& $MsbuildExe $ToolsetBuildProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /p:TreatWarningsAsErrors=true /v:$verbosity $logCmd /p:Configuration=$configuration /p:SolutionPath=$solution /p:Restore=$restore /p:QuietRestore=true /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:IntegrationTest="false" /p:Sign=$sign /p:Pack=$pack /p:UseCodecov=$useCodecov /p:UseOpenCover=$useOpenCover /p:CIBuild=$ci /p:Optimize=$optimize /p:NuGetPackageRoot=$NuGetPackageRoot $properties
if ((-not $?) -or ($lastExitCode -ne 0)) {
throw "Aborting after build failure."
}

if ($useCodecov) {
$CodecovProj = Join-Path $PSScriptRoot 'Codecov.proj'
& $MsbuildExe $CodecovProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /warnaserror /v:diag /t:Codecov /p:Configuration=$configuration /p:UseCodecov=$useCodecov /p:NuGetPackageRoot=$NuGetPackageRoot $properties
& $MsbuildExe $CodecovProj /m /nologo /clp:Summary /nodeReuse:$nodeReuse /p:TreatWarningsAsErrors=true /v:diag /t:Codecov /p:Configuration=$configuration /p:UseCodecov=$useCodecov /p:NuGetPackageRoot=$NuGetPackageRoot $properties
}

# create suite.json file
Expand Down
4 changes: 3 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

<PropertyGroup Condition="'$(Language)' == 'C#'">
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<LangVersion>7.3</LangVersion>
<LangVersion>8.0</LangVersion>
<Features>strict</Features>
<!--<NullableReferenceTypes Condition="'$(IsTestProject)' != 'true'">true</NullableReferenceTypes>-->
<WarningsNotAsErrors>$(WarningsNotAsErrors);8600;8601;8602;8603;8604;8608;8610;8612;8614;8618;8619;8620;8622;8625;8626;8629</WarningsNotAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Language)' == 'VB'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Test()
private void CallPropertyPageControl()
{
var ppvm = new Mock<PropertyPageViewModel>();
ppvm.Setup(m => m.Save()).ReturnsAsync(VSConstants.S_OK);
ppvm.Setup(m => m.Save());
ppvm.Setup(m => m.Initialize()).Returns(new Task(() => { }));
ppvm.CallBase = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<Description>Microsoft VisualStudio ProjectSystem for Managed Languages Project hosts that interact with VisualStudio interfaces.</Description>
<Summary>Microsoft VisualStudio Managed Project System VS Components</Summary>
<PackageTags>Roslyn Managed Project System VisualStudio</PackageTags>
<NoWarn>$(NoWarn);NU5125</NoWarn>
<NoWarn>$(NoWarn);NU5125</NoWarn>
<NullableReferenceTypes>true</NullableReferenceTypes>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.VisualStudio.ProjectSystem.Managed\Microsoft.VisualStudio.ProjectSystem.Managed.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal partial class ManagedProjectSystemPackage : AsyncPackage
ProjectCapability.LanguageService + "; " +
ProjectCapability.DotNet;

private IDotNetCoreProjectCompatibilityDetector _dotNetCoreCompatibilityDetector;
private IDotNetCoreProjectCompatibilityDetector? _dotNetCoreCompatibilityDetector;

public ManagedProjectSystemPackage()
{
Expand All @@ -53,7 +53,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
Lazy<DebugFrameworksDynamicMenuCommand> debugFrameworksCmd = componentModel.DefaultExportProvider.GetExport<DebugFrameworksDynamicMenuCommand>();

var mcs = (await GetServiceAsync(typeof(IMenuCommandService))) as OleMenuCommandService;
var mcs = (OleMenuCommandService)await GetServiceAsync(typeof(IMenuCommandService));
mcs.AddCommand(debugFrameworksCmd.Value);

Lazy<DebugFrameworkPropertyMenuTextUpdater> debugFrameworksMenuTextUpdater = componentModel.DefaultExportProvider.GetExport<DebugFrameworkPropertyMenuTextUpdater>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected AbstractExtenderCATIDProvider()
{
}

public string GetExtenderCATID(ExtenderCATIDType extenderCATIDType, IProjectTree treeNode)
public string? GetExtenderCATID(ExtenderCATIDType extenderCATIDType, IProjectTree treeNode)
{
// CPS's implementation of ExtenderCATIDType incorrectly treats the same "instances" as distinct items based
// where they are accessed in CPS. It also incorrectly maps "HierarchyExtensionObject" and "HierarchyBrowseObject"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ public string GetUniqueFilename(object pDispatch, string bstrRoot, string bstrDe

#region IConnectionPointContainer

public void EnumConnectionPoints(out IEnumConnectionPoints ppEnum)
public void EnumConnectionPoints(out IEnumConnectionPoints? ppEnum)
{
ppEnum = null;
(_vsProject as IConnectionPointContainer)?.EnumConnectionPoints(out ppEnum);
}

public void FindConnectionPoint(ref Guid riid, out IConnectionPoint ppCP)
public void FindConnectionPoint(ref Guid riid, out IConnectionPoint? ppCP)
{
ppCP = null;
(_vsProject as IConnectionPointContainer)?.FindConnectionPoint(ref riid, out ppCP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public string OutputFileName
}
}

public string ExtenderCATID => null;
public string? ExtenderCATID => null;

public string AbsoluteProjectDirectory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public string File

public string GetFileFullPath(ILanguageServiceHost languageServiceHost)
{
string projectFile = ProjectFile;
string? projectFile = ProjectFile;
if (string.IsNullOrEmpty(projectFile))
{
projectFile = languageServiceHost.ActiveProjectContext?.ProjectFilePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal partial class LanguageServiceErrorListProvider : IVsErrorListProvider
private static readonly Task<AddMessageResult> s_handledAndStopProcessing = Task.FromResult(AddMessageResult.HandledAndStopProcessing);
private static readonly Task<AddMessageResult> s_notHandled = Task.FromResult(AddMessageResult.NotHandled);
private readonly ILanguageServiceHost _host;
private IVsLanguageServiceBuildErrorReporter2 _languageServiceBuildErrorReporter;
private IVsLanguageServiceBuildErrorReporter2? _languageServiceBuildErrorReporter;

/// <remarks>
/// <see cref="UnconfiguredProject"/> must be imported in the contructor in order for scope of this class' export to be correct.
Expand Down Expand Up @@ -101,7 +101,7 @@ private void InitializeBuildErrorReporter()
// We defer grabbing error reporter the until the first build event, because the language service is initialized asynchronously
if (_languageServiceBuildErrorReporter == null)
{
_languageServiceBuildErrorReporter = (IVsLanguageServiceBuildErrorReporter2)_host.HostSpecificErrorReporter;
_languageServiceBuildErrorReporter = (IVsLanguageServiceBuildErrorReporter2?)_host.HostSpecificErrorReporter;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void Advise(object pUnkSink, out uint pdwCookie)
Marshal.ThrowExceptionForHR(VSConstants.E_NOINTERFACE);
}

_sinks.Add(_nextCookie, sink);
_sinks.Add(_nextCookie, sink!);
pdwCookie = _nextCookie;
_source.OnSinkAdded(sink);
_source.OnSinkAdded(sink!);
_nextCookie += 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private async Task<IReadOnlyList<IDebugLaunchSettings>> QueryDebugTargetsAsync(D
/// <summary>
/// Does some basic validation of the settings. If we don't, the error messages are terrible.
/// </summary>
public void ValidateSettings(string executable, string workingDir, string profileName)
public void ValidateSettings(string? executable, string workingDir, string? profileName)
{
if (string.IsNullOrEmpty(executable))
{
Expand All @@ -158,12 +158,12 @@ public void ValidateSettings(string executable, string workingDir, string profil
/// <summary>
/// Helper returns cmd.exe as the launcher for Ctrl-F5 (useCmdShell == true), otherwise just the exe and args passed in.
/// </summary>
public static void GetExeAndArguments(bool useCmdShell, string debugExe, string debugArgs, out string finalExePath, out string finalArguments)
public static void GetExeAndArguments(bool useCmdShell, string? debugExe, string? debugArgs, out string? finalExePath, out string? finalArguments)
{
if (useCmdShell)
{
// Escape the characters ^<>& so that they are passed to the application rather than interpreted by cmd.exe.
string escapedArgs = EscapeString(debugArgs, s_escapedChars);
string? escapedArgs = EscapeString(debugArgs, s_escapedChars);
finalArguments = $"/c \"\"{debugExe}\" {escapedArgs} & pause\"";
finalExePath = Path.Combine(Environment.SystemDirectory, "cmd.exe");
}
Expand Down Expand Up @@ -201,7 +201,7 @@ private async Task<DebugLaunchSettings> GetConsoleTargetForProfile(ILaunchProfil
{
var settings = new DebugLaunchSettings(launchOptions);

string executable, arguments;
string? executable, arguments;

string projectFolder = Path.GetDirectoryName(_project.FullPath);
ConfiguredProject configuredProject = await GetConfiguredProjectForDebugAsync();
Expand Down Expand Up @@ -283,7 +283,7 @@ private async Task<DebugLaunchSettings> GetConsoleTargetForProfile(ILaunchProfil
{
// Try to resolve against the current working directory (for compat) and failing that, the environment path.
string exeName = executable.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ? executable : executable + ".exe";
string fullPath = _fileSystem.GetFullPath(exeName);
string? fullPath = _fileSystem.GetFullPath(exeName);
if (_fileSystem.FileExists(fullPath))
{
executable = fullPath;
Expand Down Expand Up @@ -338,7 +338,7 @@ private async Task<DebugLaunchSettings> GetConsoleTargetForProfile(ILaunchProfil
useCmdShell = UseCmdShellForConsoleLaunch(resolvedProfile, settings.LaunchOptions);
}

GetExeAndArguments(useCmdShell, executable, arguments, out string finalExecutable, out string finalArguments);
GetExeAndArguments(useCmdShell, executable, arguments, out string? finalExecutable, out string? finalArguments);

settings.Executable = finalExecutable;
settings.Arguments = finalArguments;
Expand Down Expand Up @@ -394,7 +394,7 @@ private async Task<string> GetTargetCommandAsync(
bool validateSettings)
{
// First try "RunCommand" property
string runCommand = await GetRunCommandAsync(properties);
string? runCommand = await GetRunCommandAsync(properties);

if (string.IsNullOrEmpty(runCommand))
{
Expand All @@ -412,7 +412,7 @@ private async Task<string> GetTargetCommandAsync(
}


private async Task<string> GetRunCommandAsync(IProjectProperties properties)
private async Task<string?> GetRunCommandAsync(IProjectProperties properties)
{
string runCommand = await properties.GetEvaluatedPropertyValueAsync("RunCommand");

Expand All @@ -429,7 +429,7 @@ private async Task<string> GetRunCommandAsync(IProjectProperties properties)
// If the path is just the name of an exe like dotnet.exe then we try to find it on the path
if (runCommand.IndexOf(Path.DirectorySeparatorChar) == -1)
{
string executable = GetFullPathOfExeFromEnvironmentPath(runCommand);
string? executable = GetFullPathOfExeFromEnvironmentPath(runCommand);
if (executable != null)
{
runCommand = executable;
Expand Down Expand Up @@ -458,7 +458,7 @@ private static async Task<Guid> GetDebuggingEngineAsync(ConfiguredProject config
/// Searches the path variable for the first match of exeToSearchFor. Returns
/// null if not found.
/// </summary>
public string GetFullPathOfExeFromEnvironmentPath(string exeToSearchFor)
public string? GetFullPathOfExeFromEnvironmentPath(string exeToSearchFor)
{
string pathEnv = _environment.GetEnvironmentVariable("Path");

Expand Down Expand Up @@ -492,7 +492,7 @@ public string GetFullPathOfExeFromEnvironmentPath(string exeToSearchFor)
/// <param name="unescaped">The string to escape.</param>
/// <param name="toEscape">The characters to escape in the string.</param>
/// <returns>The escaped string.</returns>
internal static string EscapeString(string unescaped, char[] toEscape)
internal static string? EscapeString(string? unescaped, char[] toEscape)
{
if (string.IsNullOrWhiteSpace(unescaped))
return unescaped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Debug
[ExportMetadata("Name", "DebugProfileProvider")]
internal class DebugProfileDebugTargetGenerator : ProjectValueDataSourceBase<IReadOnlyList<IEnumValue>>, IDynamicEnumValuesProvider, IDynamicDebugTargetsGenerator
{
private IReceivableSourceBlock<IProjectVersionedValue<IReadOnlyList<IEnumValue>>> _publicBlock;
private IReceivableSourceBlock<IProjectVersionedValue<IReadOnlyList<IEnumValue>>>? _publicBlock;

// Represents the link to the launch profiles
private IDisposable _launchProfileProviderLink;
private IDisposable? _launchProfileProviderLink;

// Represents the link to our source provider
private IDisposable _debugProviderLink;
private IDisposable? _debugProviderLink;

[ImportingConstructor]
public DebugProfileDebugTargetGenerator(
Expand Down Expand Up @@ -63,7 +63,7 @@ public override IReceivableSourceBlock<IProjectVersionedValue<IReadOnlyList<IEnu
get
{
EnsureInitialized();
return _publicBlock;
return _publicBlock!;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal DebugProfileEnumValuesGenerator(

_listedValues = new AsyncLazy<ICollection<IEnumValue>>(delegate
{
ILaunchSettings curSnapshot = profileProvider.CurrentSnapshot;
ILaunchSettings? curSnapshot = profileProvider.CurrentSnapshot;
if (curSnapshot != null)
{
return Task.FromResult(GetEnumeratorEnumValues(curSnapshot));
Expand Down Expand Up @@ -83,7 +83,7 @@ from profile in profiles.Profiles
return result;
}

private static string EscapeMnemonics(string text)
private static string? EscapeMnemonics(string? text)
{
return text?.Replace("&", "&&");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public Task OnAfterLaunchAsync(DebugLaunchOptions launchOptions, ILaunchProfile
/// </summary>
public Task<IReadOnlyList<IDebugLaunchSettings>> QueryDebugTargetsAsync(DebugLaunchOptions launchOptions, ILaunchProfile activeProfile)
{
if (activeProfile.OtherSettings.TryGetValue("ErrorString", out object objErrorString) && objErrorString is string errorString)
if (activeProfile.OtherSettings != null &&
activeProfile.OtherSettings.TryGetValue("ErrorString", out object objErrorString) &&
objErrorString is string errorString)
{
throw new Exception(string.Format(VSResources.ErrorInProfilesFile2, Path.GetFileNameWithoutExtension(_configuredProject.UnconfiguredProject.FullPath), errorString));
}
Expand Down
Loading