Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public async Task<Credential> ResolveCredentialAsync(string hostname, Cancellati
try
{
using var stream = fileSystem.File.OpenRead(configPath);
using var document = JsonDocument.Parse(stream);
using var document = await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken);

if (document.RootElement.TryGetProperty("auths", out var auths) && auths.ValueKind == JsonValueKind.Object)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core/Registry/Providers/ExtensionV1Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static async Task<BinaryData> Build(ExtensionPackage package)

stream.Seek(0, SeekOrigin.Begin);

return BinaryData.FromStream(stream);
return await BinaryData.FromStreamAsync(stream);
}

public static ExtensionPackage Read(BinaryData binaryData)
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core/Registry/Providers/TypesV1Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static async Task<BinaryData> PackIntoBinaryData(IFileHandle typeIndexFil

stream.Seek(0, SeekOrigin.Begin);

return BinaryData.FromStream(stream);
return await BinaryData.FromStreamAsync(stream);
}

private static IEnumerable<string> EnumerateDistinctTypeReferences(TypeIndex index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override async Task<Unit> Handle(DocumentUri documentUri, string ruleCode
{
if (!File.Exists(bicepConfigFilePath))
{
File.WriteAllText(bicepConfigFilePath, DefaultBicepConfig);
await File.WriteAllTextAsync(bicepConfigFilePath, DefaultBicepConfig);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -84,7 +84,7 @@ public static async Task<bool> AddAndSelectRuleLevel(ILanguageServerFacade serve
return false;
}

string json = File.ReadAllText(bicepConfigFilePath);
string json = await File.ReadAllTextAsync(bicepConfigFilePath);
(int line, int column, string text)? insertion = new JsonEditor(json).InsertIfNotExist(
["analyzers", "core", "rules", ruleCode, "level"],
"warning");
Expand All @@ -95,7 +95,7 @@ public static async Task<bool> AddAndSelectRuleLevel(ILanguageServerFacade serve
var (line, column, insertText) = insertion.Value;
try
{
File.WriteAllText(bicepConfigFilePath, JsonEditor.ApplyInsertion(json, (line, column, insertText)));
await File.WriteAllTextAsync(bicepConfigFilePath, JsonEditor.ApplyInsertion(json, (line, column, insertText)));
added = true;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task InvokeAsync_BicepBuildError_ReturnsOne()
var fileSystem = MockFileSystemFactory.CreateForSample(Sample.Valid);
var sut = CreateGenerateCommand(fileSystem);

fileSystem.File.WriteAllText(MainBicepFile.FileName, "something");
await fileSystem.File.WriteAllTextAsync(MainBicepFile.FileName, "something");

var exitCode = await sut.Parse("").InvokeAsync();

Expand All @@ -79,7 +79,7 @@ public async Task InvokeAsync_BicepBuildError_PrintDiagnostics()
@$"Failed to build ""{mainBicepFilePath}"".");
var sut = CreateGenerateCommand(fileSystem, console);

fileSystem.File.WriteAllText(MainBicepFile.FileName, "something");
await fileSystem.File.WriteAllTextAsync(MainBicepFile.FileName, "something");

await sut.Parse("").InvokeAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task InvokeAsync_InvalidFiles_WritesErrorsToConsole()
public async Task InvokeAsync_BicepBuildError_ReturnsOne()
{
var fileSystem = MockFileSystemFactory.CreateForSample(Sample.Valid);
fileSystem.File.WriteAllText(MainBicepFile.FileName, "something");
await fileSystem.File.WriteAllTextAsync(MainBicepFile.FileName, "something");
var sut = CreateValidateCommand(fileSystem);

var exitCode = await sut.Parse("").InvokeAsync();
Expand All @@ -96,7 +96,7 @@ public async Task InvokeAsync_BicepBuildError_PrintDiagnostics()
var console = new MockConsole().ExpectErrorLines(
@$"{mainBicepFilePath}(1,1) : Error BCP007: This declaration type is not recognized. Specify a metadata, parameter, variable, resource, or output declaration. [https://aka.ms/bicep/core-diagnostics#BCP007]",
@$"Failed to build ""{mainBicepFilePath}"".");
fileSystem.File.WriteAllText(MainBicepFile.FileName, "something");
await fileSystem.File.WriteAllTextAsync(MainBicepFile.FileName, "something");
var sut = CreateValidateCommand(fileSystem, console);

await sut.Parse("").InvokeAsync();
Expand All @@ -109,7 +109,7 @@ public async Task InvokeAsync_BicepTestBuildError_ReturnsOne()
{
var fileSystem = MockFileSystemFactory.CreateForSample(Sample.Valid);
var bicepTestFile = MainBicepTestFile.Open(fileSystem);
fileSystem.File.WriteAllText(bicepTestFile.Path, "something");
await fileSystem.File.WriteAllTextAsync(bicepTestFile.Path, "something");
var sut = CreateValidateCommand(fileSystem);

var exitCode = await sut.Parse("").InvokeAsync();
Expand All @@ -122,7 +122,7 @@ public async Task InvokeAsync_BicepTestBuildError_PrintDiagnostics()
{
var fileSystem = MockFileSystemFactory.CreateForSample(Sample.Valid);
var bicepTestFile = MainBicepTestFile.Open(fileSystem);
fileSystem.File.WriteAllText(bicepTestFile.Path, "something");
await fileSystem.File.WriteAllTextAsync(bicepTestFile.Path, "something");
var console = new MockConsole().ExpectErrorLines(
@$"{bicepTestFile.Path}(1,1) : Error BCP007: This declaration type is not recognized. Specify a metadata, parameter, variable, resource, or output declaration. [https://aka.ms/bicep/core-diagnostics#BCP007]",
@$"Failed to build ""{bicepTestFile.Path}"".");
Expand Down
29 changes: 18 additions & 11 deletions src/Bicep.Wasm/WorkerInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,31 @@ public static partial class WorkerInterop
public static string Ping(string value) => value;

[JSExport]
public static async Task<string> CompileAndEmitDiagnostics(string content, string? sourcePath) =>
JsonSerializer.Serialize(
await Interop.Value.CompileAndEmitDiagnostics(content, sourcePath),
JsonOptions);
public static async Task<string> CompileAndEmitDiagnostics(string content, string? sourcePath)
{
var result = await Interop.Value.CompileAndEmitDiagnostics(content, sourcePath);
return JsonSerialize(result);
}

[JSExport]
public static async Task<string> Decompile(string content) =>
JsonSerializer.Serialize(await Interop.Value.Decompile(content), JsonOptions);
public static async Task<string> Decompile(string content)
{
var result = await Interop.Value.Decompile(content);
return JsonSerialize(result);
}

[JSExport]
public static string GetSemanticTokensLegend() =>
JsonSerializer.Serialize(Interop.Value.GetSemanticTokensLegend(), JsonOptions);
JsonSerialize(Interop.Value.GetSemanticTokensLegend());

[JSExport]
public static async Task<string> GetSemanticTokens(string content, string? sourcePath) =>
JsonSerializer.Serialize(
await Interop.Value.GetSemanticTokens(content, sourcePath),
JsonOptions);
public static async Task<string> GetSemanticTokens(string content, string? sourcePath)
{
var result = await Interop.Value.GetSemanticTokens(content, sourcePath);
return JsonSerialize(result);
}

private static string JsonSerialize<T>(T value) => JsonSerializer.Serialize(value, JsonOptions);
}

[SupportedOSPlatform("browser")]
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.10.91" PrivateAssets="All" />
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="5.6.0" PrivateAssets="All" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.301" PrivateAssets="All" />
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.13.2" PrivateAssets="All" />
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="18.7.23" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Azure.Bicep.Internal.RoslynAnalyzers" Version="0.1.60" />
Expand Down Expand Up @@ -70,7 +70,7 @@
<PackageVersion Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.12.2149" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.Framework" Version="17.12.40391" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.Interop" Version="17.12.40391" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.12.19" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="18.7.23" />
<PackageVersion Include="Microsoft.VisualStudio.Utilities" Version="17.12.40391" />
<PackageVersion Include="Microsoft.VisualStudio.Workspace" Version="17.1.11-preview-0002" />
<PackageVersion Include="Microsoft.VisualStudio.Workspace.VSIntegration" Version="17.1.11-preview-0002" />
Expand Down
Loading