Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
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
4 changes: 2 additions & 2 deletions src/QsCompiler/CompilationManager/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ public bool ManagerTask(Uri file, Action<CompilationUnitManager> executeTask, ID
/// <summary>
/// used to log exceptions raised during processing -> may be null!
/// </summary>
private readonly Action<Exception> logException;
private readonly Action<Exception>? logException;

/// <summary>
/// general purpose logging routine used for major loading events -> may be null!
Expand All @@ -750,7 +750,7 @@ public bool ManagerTask(Uri file, Action<CompilationUnitManager> executeTask, ID
/// that action is called whenever diagnostics for the project have changed and are ready for publishing.
/// Any exceptions caught during processing are logged using the given exception logger.
/// </summary>
public ProjectManager(Action<Exception> exceptionLogger, Action<string, MessageType>? log = null, Action<PublishDiagnosticParams>? publishDiagnostics = null)
public ProjectManager(Action<Exception>? exceptionLogger, Action<string, MessageType>? log = null, Action<PublishDiagnosticParams>? publishDiagnostics = null)
{
this.load = new ProcessingQueue(exceptionLogger);
this.projects = new ConcurrentDictionary<Uri, Project>();
Expand Down
14 changes: 7 additions & 7 deletions src/QsCompiler/LanguageServer/EditorState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class EditorState : IDisposable

private readonly Action<PublishDiagnosticParams> publish;
private readonly Action<string, Dictionary<string, string?>, Dictionary<string, int>> sendTelemetry;
private readonly Action<Uri> onTemporaryProjectLoaded;
private readonly Action<Uri>? onTemporaryProjectLoaded;

/// <summary>
/// needed to determine if the reality of a source file that has changed on disk is indeed given by the content on disk,
Expand Down Expand Up @@ -58,11 +58,11 @@ internal class EditorState : IDisposable
/// </summary>
internal EditorState(
ProjectLoader projectLoader,
Action<PublishDiagnosticParams> publishDiagnostics,
Action<string, Dictionary<string, string?>, Dictionary<string, int>> sendTelemetry,
Action<string, MessageType> log,
Action<Exception> onException,
Action<Uri> onTemporaryProjectLoaded)
Action<PublishDiagnosticParams>? publishDiagnostics,
Action<string, Dictionary<string, string?>, Dictionary<string, int>>? sendTelemetry,
Action<string, MessageType>? log,
Action<Exception>? onException,
Action<Uri>? onTemporaryProjectLoaded)
{
this.ignoreEditorUpdatesForFiles = new ConcurrentDictionary<Uri, byte>();
this.sendTelemetry = sendTelemetry ?? ((eventName, properties, measurements) => { });
Expand Down Expand Up @@ -258,7 +258,7 @@ internal Task OpenFileAsync(
{
var projectUri = this.QsTemporaryProjectLoader(textDocument.Uri, sdkVersion: null); // null means the Sdk version will be set to the extension version
this.projects.ProjectChangedOnDiskAsync(projectUri, this.QsProjectLoader, this.GetOpenFile);
this.onTemporaryProjectLoaded(projectUri);
this.onTemporaryProjectLoaded?.Invoke(projectUri);
createdTemporaryProject = true;
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions src/QsCompiler/TestTargets/Simulation/Target/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ static void Main(string[] args)

using (var qsim = new QuantumSimulator())
{
Task task = entryPoint.Invoke(null, new[] { qsim }) as Task<QVoid>;
var task = entryPoint.Invoke(null, new[] { qsim }) as Task<QVoid>;
task?.Wait();
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/QsCompiler/TestTargets/Simulation/Target/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public CsharpGeneration() =>
public IDictionary<string, string> AssemblyConstants { get; }

/// <inheritdoc/>
public IEnumerable<IRewriteStep.Diagnostic> GeneratedDiagnostics { get; private set; }
public IEnumerable<IRewriteStep.Diagnostic> GeneratedDiagnostics { get; private set; } =
Enumerable.Empty<IRewriteStep.Diagnostic>();

/// <inheritdoc/>
public bool ImplementsTransformation => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<TargetFramework>netstandard2.1</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/QsCompiler/Tests.DocGenerator/Tests.DocGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<IsPackable>false</IsPackable>
<RootNamespace>Microsoft.Quantum.QsCompiler.Documentation.Testing</RootNamespace>
<AssemblyName>Tests.Microsoft.Quantum.QsDocumentationParser</AssemblyName>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
69 changes: 35 additions & 34 deletions src/QsCompiler/Tests.LanguageServer/ProjectLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static string ProjectFileName(string project) =>
private static string SourceFileName(string project, string fileName) =>
Path.Combine("TestProjects", project, fileName);

private (string, ProjectInformation) Context(string project)
private (string, ProjectInformation?) Context(string project)
{
var relativePath = ProjectFileName(project);
var uri = new Uri(Path.GetFullPath(relativePath));
Expand Down Expand Up @@ -73,18 +73,18 @@ public void SupportedTargetFrameworks()
[TestMethod]
public void FindProjectTargetFramework()
{
void CompareFramework(string project, string expected)
void CompareFramework(string project, string? expected)
{
var projectFileName = ProjectFileName(project);
var props = new ProjectLoader().DesignTimeBuildProperties(projectFileName, out var _, (x, y) => (y.Contains('.') ? 1 : 0) - (x.Contains('.') ? 1 : 0));
if (!props.TryGetValue("TargetFramework", out string actual))
if (!props.TryGetValue("TargetFramework", out var actual))
{
actual = null;
}
Assert.AreEqual(expected, actual);
}

var testProjects = new (string, string)[]
var testProjects = new (string, string?)[]
{
("test1", "netcoreapp2.1"),
("test2", "netstandard2.0"),
Expand Down Expand Up @@ -129,10 +129,10 @@ public void LoadNonQsharpProjects()
public void LoadOutdatedQsharpProject()
{
var (projectFile, context) = this.Context("test9");
var projDir = Path.GetDirectoryName(projectFile);
var projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test9.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test9.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

var qsFiles = new string[]
{
Expand All @@ -149,10 +149,10 @@ public void LoadOutdatedQsharpProject()
public void LoadQsharpCoreLibraries()
{
var (projectFile, context) = this.Context("test3");
var projDir = Path.GetDirectoryName(projectFile);
var projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test3.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test3.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

var qsFiles = new string[]
{
Expand All @@ -168,10 +168,10 @@ public void LoadQsharpCoreLibraries()
CollectionAssert.AreEquivalent(qsFiles, context.SourceFiles.ToArray());

(projectFile, context) = this.Context("test12");
projDir = Path.GetDirectoryName(projectFile);
projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test12.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test12.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

qsFiles = new string[]
{
Expand All @@ -191,10 +191,10 @@ public void LoadQsharpCoreLibraries()
public void LoadQsharpFrameworkLibrary()
{
var (projectFile, context) = this.Context("test7");
var projDir = Path.GetDirectoryName(projectFile);
var projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test7.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test7.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

var qsFiles = new string[]
{
Expand All @@ -211,10 +211,10 @@ public void LoadQsharpFrameworkLibrary()
public void LoadQsharpConsoleApps()
{
var (projectFile, context) = this.Context("test4");
var projDir = Path.GetDirectoryName(projectFile);
var projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test4.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test4.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

var qsFiles = new string[]
{
Expand All @@ -228,10 +228,10 @@ public void LoadQsharpConsoleApps()
CollectionAssert.AreEquivalent(qsFiles, context.SourceFiles.ToArray());

(projectFile, context) = this.Context("test10");
projDir = Path.GetDirectoryName(projectFile);
projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test10.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test10.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

qsFiles = new string[]
{
Expand All @@ -243,10 +243,10 @@ public void LoadQsharpConsoleApps()
CollectionAssert.AreEquivalent(qsFiles, context.SourceFiles.ToArray());

(projectFile, context) = this.Context("test11");
projDir = Path.GetDirectoryName(projectFile);
projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test11.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test11.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

qsFiles = new string[]
{
Expand All @@ -262,10 +262,10 @@ public void LoadQsharpConsoleApps()
public void LoadQsharpUnitTest()
{
var (projectFile, context) = this.Context("test5");
var projDir = Path.GetDirectoryName(projectFile);
var projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test5.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test5.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

var qsFiles = new string[]
{
Expand All @@ -286,10 +286,10 @@ public void LoadQsharpUnitTest()
public void LoadQsharpMultiFrameworkLibrary()
{
var (projectFile, context) = this.Context("test6");
var projDir = Path.GetDirectoryName(projectFile);
var projDir = Path.GetDirectoryName(projectFile) ?? "";
Assert.IsNotNull(context);
Assert.AreEqual("test6.dll", Path.GetFileName(context.Properties.OutputPath));
Assert.IsTrue(Path.GetDirectoryName(context.Properties.OutputPath).StartsWith(projDir));
Assert.AreEqual("test6.dll", Path.GetFileName(context!.Properties.OutputPath));
Assert.IsTrue((Path.GetDirectoryName(context.Properties.OutputPath) ?? "").StartsWith(projDir));

var qsFiles = new string[]
{
Expand All @@ -314,8 +314,9 @@ public void LoadQsharpTemporaryProject()

var qsFiles = new string[] { sourceFile };
var projectInformation = CompilationContext.Load(projectUri);
Assert.IsTrue(projectInformation.UsesCanon());
CollectionAssert.AreEquivalent(qsFiles, projectInformation.SourceFiles.ToArray());
Assert.IsNotNull(projectInformation);
Assert.IsTrue(projectInformation!.UsesCanon());
CollectionAssert.AreEquivalent(qsFiles, projectInformation!.SourceFiles.ToArray());
}
}

Expand All @@ -324,7 +325,7 @@ internal static class CompilationContext
private static void LogOutput(string msg, MessageType level) =>
Console.WriteLine($"[{level}]: {msg}");

internal static ProjectInformation Load(Uri projectFile) =>
internal static ProjectInformation? Load(Uri projectFile) =>
new EditorState(new ProjectLoader(LogOutput), null, null, null, null, null)
.QsProjectLoader(projectFile, out var loaded) ? loaded : null;

Expand Down
6 changes: 3 additions & 3 deletions src/QsCompiler/Tests.LanguageServer/TestSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public sealed partial class BasicFunctionality : IDisposable
{
// basic setup

private Connection connection;
private JsonRpc rpc;
private Connection? connection;
private JsonRpc rpc = null!; // Initialized in SetupServerConnectionAsync.
private readonly RandomInput inputGenerator = new RandomInput();
private readonly Stack<PublishDiagnosticParams> receivedDiagnostics = new Stack<PublishDiagnosticParams>();

Expand All @@ -28,7 +28,7 @@ public Task<string[]> GetFileContentInMemoryAsync(string filename) =>
Methods.WorkspaceExecuteCommand.Name,
TestUtils.ServerCommand(CommandIds.FileContentInMemory, TestUtils.GetTextDocumentIdentifier(filename)));

public Task<Diagnostic[]> GetFileDiagnosticsAsync(string filename = null) =>
public Task<Diagnostic[]> GetFileDiagnosticsAsync(string? filename = null) =>
this.rpc.InvokeWithParameterObjectAsync<Diagnostic[]>(
Methods.WorkspaceExecuteCommand.Name,
TestUtils.ServerCommand(CommandIds.FileDiagnostics, filename == null ? new TextDocumentIdentifier { Uri = null } : TestUtils.GetTextDocumentIdentifier(filename)));
Expand Down
8 changes: 2 additions & 6 deletions src/QsCompiler/Tests.LanguageServer/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,12 @@ internal static int GetRangeLength(VisualStudio.LanguageServer.Protocol.Range ra

internal static void ApplyEdit(TextDocumentContentChangeEvent change, ref List<string> content)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
if (!content.Any())
{
throw new ArgumentException("the given content has to have at least on line");
}

Assert.IsTrue(IsValidRange(change?.Range) && change.Text != null);
Assert.IsTrue(IsValidRange(change.Range) && change.Text != null);
Assert.IsTrue(change.Range.End.Line < content.Count());
Assert.IsTrue(change.Range.Start.Character <= content[change.Range.Start.Line].Length);
Assert.IsTrue(change.Range.End.Character <= content[change.Range.End.Line].Length);
Expand All @@ -143,7 +139,7 @@ internal static void ApplyEdit(TextDocumentContentChangeEvent change, ref List<s
content.InsertRange(startLine, lineChanges);
}

internal static bool IsValidRange(Range range)
internal static bool IsValidRange(Range? range)
{
static bool IsValidPosition(Position position) => position.Line >= 0 && position.Character >= 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<PlatformTarget>x64</PlatformTarget>
<OutputType>Library</OutputType>
<NoWarn>NU1701</NoWarn>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
4 changes: 2 additions & 2 deletions src/QsCompiler/Tests.LanguageServer/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public async Task ServerCapabilitiesAsync()
Assert.IsNotNull(initReply.Capabilities.CompletionProvider.TriggerCharacters);
Assert.IsTrue(initReply.Capabilities.CompletionProvider.TriggerCharacters.SequenceEqual(new[] { ".", "(" }));
Assert.IsNotNull(initReply.Capabilities.SignatureHelpProvider?.TriggerCharacters);
Assert.IsTrue(initReply.Capabilities.SignatureHelpProvider.TriggerCharacters.Any());
Assert.IsTrue(initReply.Capabilities.SignatureHelpProvider!.TriggerCharacters.Any());
Assert.IsNotNull(initReply.Capabilities.ExecuteCommandProvider?.Commands);
Assert.IsNotNull(initReply.Capabilities.ExecuteCommandProvider.Commands.Contains(CommandIds.ApplyEdit));
Assert.IsTrue(initReply.Capabilities.ExecuteCommandProvider!.Commands.Contains(CommandIds.ApplyEdit));
Assert.IsTrue(initReply.Capabilities.TextDocumentSync.OpenClose);
Assert.IsTrue(initReply.Capabilities.TextDocumentSync.Save.IncludeText);
Assert.AreEqual(TextDocumentSyncKind.Incremental, initReply.Capabilities.TextDocumentSync.Change);
Expand Down