Merge branch 'main' into RoslynCohost

This commit is contained in:
David Wengier 2023-12-14 09:13:24 +11:00 коммит произвёл GitHub
Родитель 21c1de9d81 d50c353b6f
Коммит a511a7e8c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
22 изменённых файлов: 366 добавлений и 118 удалений

Просмотреть файл

@ -2,24 +2,22 @@
"solution": {
"path": "Razor.sln",
"projects": [
"src\\Analyzers\\Razor.Diagnostics.Analyzers\\Razor.Diagnostics.Analyzers.csproj",
"src\\Analyzers\\Razor.Diagnostics.Analyzers.Test\\Razor.Diagnostics.Analyzers.Test.csproj",
"src\\Analyzers\\Razor.Diagnostics.Analyzers\\Razor.Diagnostics.Analyzers.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X\\src\\Microsoft.CodeAnalysis.Razor.Compiler.Mvc.Version1_X.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X\\test\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.Test.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X\\src\\Microsoft.CodeAnalysis.Razor.Compiler.Mvc.Version2_X.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X\\test\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X.Test.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Mvc.Razor.Extensions\\src\\Microsoft.CodeAnalysis.Razor.Compiler.Mvc.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Mvc.Razor.Extensions\\test\\Microsoft.AspNetCore.Mvc.Razor.Extensions.Test.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Razor.Language\\legacyTest\\Microsoft.AspNetCore.Razor.Language.Legacy.Test.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Razor.Language\\src\\Microsoft.CodeAnalysis.Razor.Compiler.Language.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Razor.Language\\test\\Microsoft.AspNetCore.Razor.Language.Test.csproj",
"src\\Compiler\\Microsoft.AspNetCore.Razor.Language\\legacyTest\\Microsoft.AspNetCore.Razor.Language.Legacy.Test.csproj",
"src\\Compiler\\Microsoft.CodeAnalysis.Razor\\src\\Microsoft.CodeAnalysis.Razor.Compiler.CSharp.csproj",
"src\\Compiler\\Microsoft.CodeAnalysis.Razor\\test\\Microsoft.CodeAnalysis.Razor.Test.csproj",
"src\\Compiler\\Microsoft.NET.Sdk.Razor.SourceGenerators.Transport\\Microsoft.NET.Sdk.Razor.SourceGenerators.Transport.csproj",
"src\\Compiler\\Microsoft.NET.Sdk.Razor.SourceGenerators\\Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.csproj",
"src\\Compiler\\Microsoft.Net.Compilers.Razor.Toolset\\Microsoft.Net.Compilers.Razor.Toolset.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Test.Common\\Microsoft.AspNetCore.Razor.Test.Common.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Test.ComponentShim\\Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj",
"src\\Compiler\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.Compiler.csproj",
"src\\Compiler\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X.Compiler.csproj",
"src\\Compiler\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim\\Microsoft.AspNetCore.Razor.Test.MvcShim.Compiler.csproj",
@ -33,6 +31,7 @@
"src\\Razor\\src\\Microsoft.VisualStudio.LanguageServer.ContainedLanguage\\Microsoft.VisualStudio.LanguageServer.ContainedLanguage.csproj",
"src\\Razor\\src\\Microsoft.VisualStudio.LanguageServices.Razor\\Microsoft.VisualStudio.LanguageServices.Razor.csproj",
"src\\Razor\\src\\Microsoft.VisualStudio.LiveShare.Razor\\Microsoft.VisualStudio.LiveShare.Razor.csproj",
"src\\Razor\\src\\Microsoft.VisualStudio.RazorExtension\\Microsoft.VisualStudio.RazorExtension.csproj",
"src\\Razor\\test\\Microsoft.AspNetCore.Razor.Test.Common.Tooling\\Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj",
"src\\Razor\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj",
"src\\Razor\\test\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X\\Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.csproj",
@ -45,8 +44,10 @@
"src\\Razor\\test\\Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test\\Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj",
"src\\Razor\\test\\Microsoft.VisualStudio.LanguageServices.Razor.Test\\Microsoft.VisualStudio.LanguageServices.Razor.Test.csproj",
"src\\Razor\\test\\Microsoft.VisualStudio.LiveShare.Razor.Test\\Microsoft.VisualStudio.LiveShare.Razor.Test.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Test.Common\\Microsoft.AspNetCore.Razor.Test.Common.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Test.ComponentShim\\Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Utilities.Shared.Test\\Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj",
"src\\Shared\\Microsoft.AspNetCore.Razor.Utilities.Shared\\Microsoft.AspNetCore.Razor.Utilities.Shared.csproj"
]
}
}
}

Просмотреть файл

@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31415.485
MinimumVisualStudioVersion = 16.0.0.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.RazorExtension", "src\Razor\src\Microsoft.VisualStudio.RazorExtension\Microsoft.VisualStudio.RazorExtension.csproj", "{BCF712D4-329A-4C7A-8292-9EFC864B2ABA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tooling", "Tooling", "{3C0D6505-79B3-49D0-B4C3-176F0F1836ED}"
ProjectSection(SolutionItems) = preProject
src\Razor\src\Directory.Build.props = src\Razor\src\Directory.Build.props
@ -38,8 +40,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X", "src\Razor\test\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X\Microsoft.AspNetCore.Razor.Test.MvcShim.Version2_X.csproj", "{D87E5501-B832-46B6-ACD3-EC989E3D14ED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.RazorExtension", "src\Razor\src\Microsoft.VisualStudio.RazorExtension\Microsoft.VisualStudio.RazorExtension.csproj", "{BCF712D4-329A-4C7A-8292-9EFC864B2ABA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.LiveShare.Razor", "src\Razor\src\Microsoft.VisualStudio.LiveShare.Razor\Microsoft.VisualStudio.LiveShare.Razor.csproj", "{20193C6A-8981-447F-99B3-120DD3B06279}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.LiveShare.Razor.Test", "src\Razor\test\Microsoft.VisualStudio.LiveShare.Razor.Test\Microsoft.VisualStudio.LiveShare.Razor.Test.csproj", "{9A27DD55-E8CD-4C03-A89B-A7348B787660}"

Просмотреть файл

@ -5,9 +5,9 @@
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>839cdfb0ecca5e0be3dbccd926e7651ef50fdf10</Sha>
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.23565.2">
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build-reference-packages" Version="9.0.0-alpha.1.23608.1">
<Uri>https://github.com/dotnet/source-build-reference-packages</Uri>
<Sha>b5ceed90b72d1b05975dd95fedd86c2455969adb</Sha>
<Sha>9e09ace1897546ac85dab114a6e1a5b6f773db7a</Sha>
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="4.8.0-3.23475.1">
@ -90,14 +90,14 @@
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-runtime</Uri>
<Sha>3a25a7f1cc446b60678ed25c9d829420d6321eba</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="9.0.0-beta.23607.2">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="9.0.0-beta.23612.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>3faeb9817f465151aa4bbcdb315f0a6170206760</Sha>
<Sha>1f6c5acef9bdf9d4bf1eded044eeec0d7d19560d</Sha>
<SourceBuild RepoName="arcade" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.DotNet.XliffTasks" Version="9.0.0-beta.23607.2">
<Dependency Name="Microsoft.DotNet.XliffTasks" Version="9.0.0-beta.23612.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>3faeb9817f465151aa4bbcdb315f0a6170206760</Sha>
<Sha>1f6c5acef9bdf9d4bf1eded044eeec0d7d19560d</Sha>
</Dependency>
<!-- Necessary for source-build. This allows Microsoft.Extensions.ObjectPool and System.Collections.Immutable packages
to be retrieved from live source-build and their content consumed by packages produced by razor.

Просмотреть файл

@ -51,7 +51,7 @@
<PropertyGroup Label="Automated">
<MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>6.0.2-servicing.22064.6</MicrosoftNETCoreBrowserDebugHostTransportPackageVersion>
<MicrosoftNETCorePlatformsPackageVersion>6.0.1</MicrosoftNETCorePlatformsPackageVersion>
<MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>9.0.0-alpha.1.23565.2</MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>
<MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>9.0.0-alpha.1.23608.1</MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>
<MicrosoftNetCompilersToolsetPackageVersion>4.9.0-3.23612.8</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.9.0-3.23612.8</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.9.0-3.23612.8</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
@ -71,7 +71,7 @@
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.9.0-3.23612.8</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.9.0-3.23612.8</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftVisualStudioLanguageServicesPackageVersion>4.9.0-3.23612.8</MicrosoftVisualStudioLanguageServicesPackageVersion>
<MicrosoftDotNetXliffTasksPackageVersion>9.0.0-beta.23607.2</MicrosoftDotNetXliffTasksPackageVersion>
<MicrosoftDotNetXliffTasksPackageVersion>9.0.0-beta.23612.2</MicrosoftDotNetXliffTasksPackageVersion>
<!--
Exception - Microsoft.Extensions.ObjectPool and System.Collections.Immutable packages are not updated by automation,
but are present in Version.Details.xml for source-build PVP flow. See the comment in Version.Details.xml for more information.

Просмотреть файл

@ -19,6 +19,7 @@ Param(
[switch] $pack,
[switch] $publish,
[switch] $clean,
[switch] $verticalBuild,
[switch][Alias('bl')]$binaryLog,
[switch][Alias('nobl')]$excludeCIBinarylog,
[switch] $ci,
@ -58,6 +59,7 @@ function Print-Usage() {
Write-Host " -sign Sign build outputs"
Write-Host " -publish Publish artifacts (e.g. symbols)"
Write-Host " -clean Clean the solution"
Write-Host " -verticalBuild Run in 'vertical build' infra mode."
Write-Host ""
Write-Host "Advanced settings:"
@ -120,6 +122,7 @@ function Build {
/p:Deploy=$deploy `
/p:Test=$test `
/p:Pack=$pack `
/p:ArcadeBuildVertical=$verticalBuild `
/p:IntegrationTest=$integrationTest `
/p:PerformanceTest=$performanceTest `
/p:Sign=$sign `

Просмотреть файл

@ -59,6 +59,7 @@ scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
restore=false
build=false
source_build=false
vertical_build=false
rebuild=false
test=false
integration_test=false
@ -129,6 +130,12 @@ while [[ $# > 0 ]]; do
restore=true
pack=true
;;
-verticalbuild|-vb)
build=true
vertical_build=true
restore=true
pack=true
;;
-test|-t)
test=true
;;
@ -220,6 +227,7 @@ function Build {
/p:Restore=$restore \
/p:Build=$build \
/p:ArcadeBuildFromSource=$source_build \
/p:ArcadeBuildVertical=$vertical_build \
/p:Rebuild=$rebuild \
/p:Test=$test \
/p:Pack=$pack \

Просмотреть файл

@ -827,7 +827,8 @@ function MSBuild-Core() {
}
}
$env:ARCADE_BUILD_TOOL_COMMAND = "$($buildTool.Path) $cmdArgs"
# Be sure quote the path in case there are spaces in the dotnet installation location.
$env:ARCADE_BUILD_TOOL_COMMAND = "`"$($buildTool.Path)`" $cmdArgs"
$exitCode = Exec-Process $buildTool.Path $cmdArgs

Просмотреть файл

@ -21,6 +21,6 @@
"rollForward": "latestPatch"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.23607.2"
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.23612.2"
}
}

Просмотреть файл

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration;
@ -538,7 +539,8 @@ internal static class CodeWriterExtensions
return NullDisposable.Default;
}
return new LinePragmaWriter(writer, span.Value, context, 0, false);
var sourceSpan = RemapFilePathIfNecessary(span.Value, context);
return new LinePragmaWriter(writer, sourceSpan, context, 0, false);
}
public static IDisposable BuildEnhancedLinePragma(this CodeWriter writer, SourceSpan? span, CodeRenderingContext context, int characterOffset = 0)
@ -549,7 +551,22 @@ internal static class CodeWriterExtensions
return NullDisposable.Default;
}
return new LinePragmaWriter(writer, span.Value, context, characterOffset, useEnhancedLinePragma: true);
var sourceSpan = RemapFilePathIfNecessary(span.Value, context);
return new LinePragmaWriter(writer, sourceSpan, context, characterOffset, useEnhancedLinePragma: true);
}
private static SourceSpan RemapFilePathIfNecessary(SourceSpan sourceSpan, CodeRenderingContext context)
{
if (context.Options.RemapLinePragmaPathsOnWindows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// ISSUE: https://github.com/dotnet/razor/issues/9108
// The razor tooling normalizes paths to be forward slash based, regardless of OS.
// If you try and use the line pragma in the design time docs to map back to the original file it will fail,
// as the path isn't actually valid on windows. As a workaround we apply a simple heuristic to switch the
// paths back when writing out the design time paths.
sourceSpan = new SourceSpan(sourceSpan.FilePath.Replace("/", "\\"), sourceSpan.AbsoluteIndex, sourceSpan.LineIndex, sourceSpan.CharacterIndex, sourceSpan.Length);
}
return sourceSpan;
}
private static void WriteVerbatimStringLiteral(CodeWriter writer, ReadOnlyMemory<char> literal)

Просмотреть файл

@ -20,7 +20,8 @@ internal class DefaultRazorCodeGenerationOptions : RazorCodeGenerationOptions
bool supportLocalizedComponentNames,
bool useEnhancedLinePragma,
string suppressUniqueIds,
bool suppressAddComponentParameter)
bool suppressAddComponentParameter,
bool remapLinePragmaPathsOnWindows)
{
IndentWithTabs = indentWithTabs;
IndentSize = indentSize;
@ -35,6 +36,7 @@ internal class DefaultRazorCodeGenerationOptions : RazorCodeGenerationOptions
UseEnhancedLinePragma = useEnhancedLinePragma;
SuppressUniqueIds = suppressUniqueIds;
SuppressAddComponentParameter = suppressAddComponentParameter;
RemapLinePragmaPathsOnWindows = remapLinePragmaPathsOnWindows;
}
public override bool DesignTime { get; }

Просмотреть файл

@ -62,7 +62,8 @@ internal class DefaultRazorCodeGenerationOptionsBuilder : RazorCodeGenerationOpt
SupportLocalizedComponentNames,
UseEnhancedLinePragma,
SuppressUniqueIds,
SuppressAddComponentParameter)
SuppressAddComponentParameter,
RemapLinePragmaPathsOnWindows)
{
SuppressMetadataSourceChecksumAttributes = SuppressMetadataSourceChecksumAttributes,
};

Просмотреть файл

@ -144,6 +144,7 @@ Microsoft.AspNetCore.Razor.Language.RazorCodeDocument
Microsoft.AspNetCore.Razor.Language.RazorCodeDocument.Imports.get -> System.Collections.Immutable.ImmutableArray<Microsoft.AspNetCore.Razor.Language.RazorSourceDocument!>
Microsoft.AspNetCore.Razor.Language.RazorCodeDocument.Items.get -> Microsoft.AspNetCore.Razor.Language.ItemCollection!
Microsoft.AspNetCore.Razor.Language.RazorCodeDocument.Source.get -> Microsoft.AspNetCore.Razor.Language.RazorSourceDocument!
Microsoft.AspNetCore.Razor.Language.RazorCodeGenerationOptions.RemapLinePragmaPathsOnWindows.get -> bool
Microsoft.AspNetCore.Razor.Language.RazorDiagnostic.Equals(Microsoft.AspNetCore.Razor.Language.RazorDiagnostic? other) -> bool
Microsoft.AspNetCore.Razor.Language.RazorDiagnostic.GetMessage() -> string!
Microsoft.AspNetCore.Razor.Language.RazorDiagnostic.GetMessage(System.IFormatProvider? formatProvider) -> string!

Просмотреть файл

@ -24,7 +24,8 @@ public abstract class RazorCodeGenerationOptions
supportLocalizedComponentNames: false,
useEnhancedLinePragma: true,
suppressUniqueIds: null,
suppressAddComponentParameter: false);
suppressAddComponentParameter: false,
remapLinePragmaPathsOnWindows: false);
}
public static RazorCodeGenerationOptions CreateDesignTimeDefault()
@ -42,7 +43,8 @@ public abstract class RazorCodeGenerationOptions
supportLocalizedComponentNames: false,
useEnhancedLinePragma: true,
suppressUniqueIds: null,
suppressAddComponentParameter: false);
suppressAddComponentParameter: false,
remapLinePragmaPathsOnWindows: true);
}
public static RazorCodeGenerationOptions Create(Action<RazorCodeGenerationOptionsBuilder> configure)
@ -160,4 +162,9 @@ public abstract class RazorCodeGenerationOptions
/// Determines whether RenderTreeBuilder.AddComponentParameter should not be used.
/// </summary>
internal bool SuppressAddComponentParameter { get; private protected init; }
/// <summary>
/// Determines if the file paths emitted as part of line pragmas should be mapped back to a valid path on windows.
/// </summary>
public bool RemapLinePragmaPathsOnWindows { get; private protected init; }
}

Просмотреть файл

@ -95,6 +95,11 @@ public abstract class RazorCodeGenerationOptionsBuilder
/// </summary>
internal bool SuppressAddComponentParameter { get; set; }
/// <summary>
/// Determines if the file paths emitted as part of line pragmas should be mapped back to a valid path on windows.
/// </summary>
internal bool RemapLinePragmaPathsOnWindows { get; set; }
public abstract RazorCodeGenerationOptions Build();
public virtual void SetDesignTime(bool designTime)

Просмотреть файл

@ -457,6 +457,101 @@ Render Children
ignoreLineEndingDifferences: true);
}
[OSSkipConditionTheory(new[] { "Linux", "osx" })]
[InlineData(@"test.cshtml", @"test.cshtml")]
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]
[InlineData(@"c:/pages/test.cshtml", @"c:\pages\test.cshtml")]
[InlineData(@"c:\pages\test.cshtml", @"c:\pages\test.cshtml")]
[InlineData(@"c:/pages with space/test.cshtml", @"c:\pages with space\test.cshtml")]
[InlineData(@"c:\pages with space\test.cshtml", @"c:\pages with space\test.cshtml")]
[InlineData(@"//SERVER/pages/test.cshtml", @"\\SERVER\pages\test.cshtml")]
[InlineData(@"\\SERVER/pages\test.cshtml", @"\\SERVER\pages\test.cshtml")]
public void LinePragma_Is_Adjusted_On_Windows(string fileName, string expectedFileName)
{
var writer = new DesignTimeNodeWriter();
var context = TestCodeRenderingContext.CreateDesignTime();
Assert.True(context.Options.RemapLinePragmaPathsOnWindows);
var node = new CSharpExpressionIntermediateNode()
{
Source = new SourceSpan(fileName, 0, 0, 0, 3),
};
var builder = IntermediateNodeBuilder.Create(node);
builder.Add(new IntermediateToken()
{
Content = "i++",
Kind = TokenKind.CSharp,
});
writer.WriteCSharpExpression(context, node);
var csharp = context.CodeWriter.GenerateCode();
Assert.Equal(
$"""
#nullable restore
#line 1 "{expectedFileName}"
__o = i++;
#line default
#line hidden
#nullable disable
""",
csharp,
ignoreLineEndingDifferences: true);
}
[OSSkipConditionTheory(new[] { "Linux", "osx" })]
[InlineData(@"test.cshtml", @"test.cshtml")]
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]
[InlineData(@"c:/pages/test.cshtml", @"c:\pages\test.cshtml")]
[InlineData(@"c:\pages\test.cshtml", @"c:\pages\test.cshtml")]
[InlineData(@"c:/pages with space/test.cshtml", @"c:\pages with space\test.cshtml")]
[InlineData(@"c:\pages with space\test.cshtml", @"c:\pages with space\test.cshtml")]
[InlineData(@"//SERVER/pages/test.cshtml", @"\\SERVER\pages\test.cshtml")]
[InlineData(@"\\SERVER/pages\test.cshtml", @"\\SERVER\pages\test.cshtml")]
public void LinePragma_Enhanced_Is_Adjusted_On_Windows(string fileName, string expectedFileName)
{
var writer = new RuntimeNodeWriter();
var context = TestCodeRenderingContext.CreateDesignTime();
Assert.True(context.Options.RemapLinePragmaPathsOnWindows);
Assert.True(context.Options.UseEnhancedLinePragma);
var node = new CSharpExpressionIntermediateNode()
{
Source = new SourceSpan(fileName, 0, 0, 0, 3),
};
var builder = IntermediateNodeBuilder.Create(node);
builder.Add(new IntermediateToken()
{
Content = "i++",
Kind = TokenKind.CSharp,
});
writer.WriteCSharpExpression(context, node);
var csharp = context.CodeWriter.GenerateCode();
Assert.Equal(
$"""
#nullable restore
#line (1,0)-(1,0) 6 "{expectedFileName}"
Write(i++);
#line default
#line hidden
#nullable disable
""",
csharp,
ignoreLineEndingDifferences: true);
}
private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
{
var projectEngine = CreateProjectEngine();

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(DefaultNetCoreTargetFrameworks)</TargetFrameworks>
@ -28,6 +28,7 @@
<Compile Include="..\..\shared\JsonReaderExtensions.cs" LinkBase="Shared" />
<Compile Include="..\..\shared\RazorDiagnosticJsonConverter.cs" LinkBase="Shared" />
<Compile Include="..\..\shared\TagHelperDescriptorJsonConverter.cs" LinkBase="Shared" />
<Compile Include="..\..\..\Razor\test\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -69,6 +69,7 @@ internal class RemoteProjectSnapshotProjectEngineFactory : DefaultProjectSnapsho
// We don't need to explicitly subscribe to options changing because this method will be run on every parse.
options.IndentSize = _optionsMonitor.CurrentValue.TabSize;
options.IndentWithTabs = !_optionsMonitor.CurrentValue.InsertSpaces;
options.RemapLinePragmaPathsOnWindows = true;
}
}
}

Просмотреть файл

@ -612,6 +612,7 @@ internal class DefaultVisualStudioRazorParser : VisualStudioRazorParser, IDispos
{
options.IndentSize = _settings.IndentSize;
options.IndentWithTabs = _settings.IndentWithTabs;
options.RemapLinePragmaPathsOnWindows = true;
}
}

Просмотреть файл

@ -31,26 +31,38 @@ internal class VSTelemetryReporter : TelemetryReporter
{
if (exception is RemoteInvocationException remoteInvocationException)
{
ReportRemoteInvocationException(remoteInvocationException);
return true;
if (ReportRemoteInvocationException(remoteInvocationException, @params))
{
return true;
}
}
return false;
}
private void ReportRemoteInvocationException(RemoteInvocationException remoteInvocationException)
private bool ReportRemoteInvocationException(RemoteInvocationException remoteInvocationException, object?[] @params)
{
if (remoteInvocationException.InnerException is Exception innerException)
{
// innerException might be an OperationCancelled or Aggregate, use the full ReportFault to unwrap it consistently.
ReportFault(innerException, "RIE: " + remoteInvocationException.Message);
return;
return true;
}
else if (@params.Length < 2)
{
// RIE has '2' extra pieces of data to report via @params, if we don't have those, then we unwrap and call one more time.
// If we have both, though, we want the core code of ReportFault to do the reporting.
ReportFault(
remoteInvocationException,
remoteInvocationException.Message,
remoteInvocationException.ErrorCode,
remoteInvocationException.DeserializedErrorData);
return true;
}
else
{
return false;
}
ReportFault(
remoteInvocationException,
remoteInvocationException.Message,
remoteInvocationException.ErrorCode,
remoteInvocationException.DeserializedErrorData);
}
protected override void LogTrace(string? message, params object?[] args)

Просмотреть файл

@ -7,7 +7,7 @@ using Microsoft.VisualStudio.Telemetry;
namespace Microsoft.VisualStudio.Editor.Razor.Test.Shared;
internal class TestTelemetryReporter : TelemetryReporter
internal class TestTelemetryReporter : VSTelemetryReporter
{
public List<TelemetryEvent> Events { get; } = [];

Просмотреть файл

@ -5,6 +5,7 @@ using System;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.VisualStudio.Editor.Razor.Test.Shared;
using Microsoft.VisualStudio.Telemetry;
using StreamJsonRpc;
using Xunit;
namespace Microsoft.VisualStudio.Editor.Razor.Test;
@ -239,6 +240,49 @@ public class TelemetryReporterTests
});
}
[Fact]
public void HandleRIEWithInnerException()
{
var reporter = new TestTelemetryReporter();
var ae = new ApplicationException("expectedText");
var rie = new RemoteInvocationException("a", 0, ae);
reporter.ReportFault(rie, rie.Message);
Assert.Collection(reporter.Events,
e1 =>
{
Assert.Equal(TelemetrySeverity.High, e1.Severity);
Assert.Equal("dotnet/razor/fault", e1.Name);
// faultEvent doesn't expose any interesting properties,
// like the ExceptionObject, or the resulting Description,
// or really anything we would explicitly want to verify against.
Assert.IsType<FaultEvent>(e1);
});
}
[Fact]
public void HandleRIEWithNoInnerException()
{
var reporter = new TestTelemetryReporter();
var rie = new RemoteInvocationException("a", 0, errorData:null);
reporter.ReportFault(rie, rie.Message);
Assert.Collection(reporter.Events,
e1 =>
{
Assert.Equal(TelemetrySeverity.High, e1.Severity);
Assert.Equal("dotnet/razor/fault", e1.Name);
// faultEvent doesn't expose any interesting properties,
// like the ExceptionObject, or the resulting Description,
// or really anything we would explicitly want to verify against.
Assert.IsType<FaultEvent>(e1);
});
}
[Fact]
public void TrackLspRequest()
{

Просмотреть файл

@ -21,23 +21,16 @@ using Xunit.Sdk;
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Test;
public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public class RazorProjectInfoPublisherTest(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
{
private readonly ProjectSnapshotManagerBase _projectSnapshotManager;
private readonly ProjectConfigurationFilePathStore _projectConfigurationFilePathStore;
public RazorProjectInfoPublisherTest(ITestOutputHelper testOutput)
: base(testOutput)
{
_projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
_projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
}
[Fact]
[WorkItem("https://github.com/dotnet/aspnetcore/issues/35945")]
public async Task ProjectManager_Changed_Remove_Change_NoopsOnDelayedPublish()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var tagHelpers = ImmutableArray.Create<TagHelperDescriptor>(
new TagHelperDescriptor(FileKinds.Component, "Namespace.FileNameOther", "Assembly", "FileName", "FileName document", "FileName hint",
@ -47,7 +40,7 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
var expectedProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray<TagHelperDescriptor>.Empty, CodeAnalysis.CSharp.LanguageVersion.Preview));
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Same(expectedProjectSnapshot, snapshot);
@ -58,8 +51,8 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
EnqueueDelay = 10,
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(expectedProjectSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(expectedProjectSnapshot.Key, expectedConfigurationFilePath);
var documentRemovedArgs = ProjectChangeEventArgs.CreateTestInstance(initialProjectSnapshot, initialProjectSnapshot, documentFilePath: @"C:\path\to\file.razor", ProjectChangeKind.DocumentRemoved);
var projectChangedArgs = ProjectChangeEventArgs.CreateTestInstance(initialProjectSnapshot, expectedProjectSnapshot, documentFilePath: null, ProjectChangeKind.ProjectChanged);
@ -77,20 +70,23 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public void ProjectManager_Changed_NotActive_Noops()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var attemptedToSerialize = false;
var hostProject = new HostProject(@"C:\path\to\project.csproj", @"C:\path\to\obj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor");
_projectSnapshotManager.ProjectAdded(hostProject);
projectSnapshotManager.ProjectAdded(hostProject);
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true)
{
EnqueueDelay = 10,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
// Act
_projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
// Assert
Assert.Empty(publisher.DeferredPublishTasks);
@ -98,24 +94,30 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
}
[Fact]
public void ProjectManager_Changed_DocumentOpened_UninitializedProject_NotActive_Noops()
public async Task ProjectManager_Changed_DocumentOpened_UninitializedProject_NotActive_Noops()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var attemptedToSerialize = false;
var hostProject = new HostProject(@"C:\path\to\project.csproj", @"C:\path\to\obj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor");
_projectSnapshotManager.ProjectAdded(hostProject);
_projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
projectSnapshotManager.ProjectAdded(hostProject);
projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true)
{
EnqueueDelay = 10,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
// Act
_projectSnapshotManager.DocumentOpened(hostProject.Key, hostDocument.FilePath, SourceText.From(string.Empty));
await RunOnDispatcherThreadAsync(() =>
{
projectSnapshotManager.DocumentOpened(hostProject.Key, hostDocument.FilePath, SourceText.From(string.Empty));
});
// Assert
Assert.Empty(publisher.DeferredPublishTasks);
@ -126,17 +128,20 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task ProjectManager_Changed_DocumentOpened_InitializedProject_NotActive_Publishes()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var hostProject = new HostProject(@"C:\path\to\project.csproj", @"C:\path\to\obj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor");
_projectSnapshotManager.ProjectAdded(hostProject);
_projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Default);
_projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
var projectSnapshot = _projectSnapshotManager.GetProjects()[0];
projectSnapshotManager.ProjectAdded(hostProject);
projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Default);
projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
var projectSnapshot = projectSnapshotManager.GetProjects()[0];
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
_projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
@ -145,14 +150,13 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
{
EnqueueDelay = 10,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
// Act
await RunOnDispatcherThreadAsync(() =>
{
_projectSnapshotManager.DocumentOpened(hostProject.Key, hostDocument.FilePath, SourceText.From(string.Empty));
projectSnapshotManager.DocumentOpened(hostProject.Key, hostDocument.FilePath, SourceText.From(string.Empty));
});
// Assert
Assert.Empty(publisher.DeferredPublishTasks);
@ -163,17 +167,25 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task ProjectManager_Changed_DocumentOpened_InitializedProject_NoFile_Active_Publishes()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var hostProject = new HostProject(@"C:\path\to\project.csproj", @"C:\path\to\obj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor");
_projectSnapshotManager.ProjectAdded(hostProject);
_projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Default);
_projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
var projectSnapshot = _projectSnapshotManager.GetProjects()[0];
await RunOnDispatcherThreadAsync(() =>
{
projectSnapshotManager.ProjectAdded(hostProject);
projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, ProjectWorkspaceState.Default);
projectSnapshotManager.DocumentAdded(hostProject.Key, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
});
var projectSnapshot = projectSnapshotManager.GetProjects()[0];
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
_projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
@ -181,15 +193,15 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
},
configurationFileExists: false)
{
EnqueueDelay = 10,
EnqueueDelay = 10000, // Long enqueue delay to make sure this test doesn't pass due to slow running, but broken product code
_active = true
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
// Act
await RunOnDispatcherThreadAsync(() =>
{
_projectSnapshotManager.DocumentOpened(hostProject.Key, hostDocument.FilePath, SourceText.From(string.Empty));
projectSnapshotManager.DocumentOpened(hostProject.Key, hostDocument.FilePath, SourceText.From(string.Empty));
});
// Assert
@ -204,11 +216,14 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
internal async Task ProjectManager_Changed_EnqueuesPublishAsync(ProjectChangeKind changeKind)
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var projectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray<TagHelperDescriptor>.Empty, CodeAnalysis.CSharp.LanguageVersion.CSharp7_3));
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Same(projectSnapshot, snapshot);
@ -219,8 +234,8 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
EnqueueDelay = 10,
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, projectSnapshot, documentFilePath: null, changeKind);
// Act
@ -236,13 +251,16 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
internal async Task ProjectManager_ChangedTagHelpers_PublishesImmediately()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var projectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray<TagHelperDescriptor>.Empty, CodeAnalysis.CSharp.LanguageVersion.Default));
var changedProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray<TagHelperDescriptor>.Empty, CodeAnalysis.CSharp.LanguageVersion.CSharp8));
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var aboutToChange = false;
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
if (!aboutToChange)
@ -258,8 +276,8 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
EnqueueDelay = 10,
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, projectSnapshot, documentFilePath: null, ProjectChangeKind.ProjectChanged);
publisher.ProjectSnapshotManager_Changed(null, args);
@ -283,18 +301,21 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task ProjectManager_Changed_ProjectRemoved_AfterEnqueuedPublishAsync()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var attemptedToSerialize = false;
var projectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj");
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true)
{
EnqueueDelay = 10,
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(projectSnapshot.Key, expectedConfigurationFilePath);
publisher.EnqueuePublish(projectSnapshot);
var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, newer: null, documentFilePath: null, ProjectChangeKind.ProjectRemoved);
@ -312,12 +333,15 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task EnqueuePublish_BatchesPublishRequestsAsync()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var firstSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj");
var secondSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new[] { @"C:\path\to\file.cshtml" });
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Same(secondSnapshot, snapshot);
@ -328,8 +352,8 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
EnqueueDelay = 10,
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(firstSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(firstSnapshot.Key, expectedConfigurationFilePath);
// Act
publisher.EnqueuePublish(firstSnapshot);
@ -345,12 +369,15 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task EnqueuePublish_OnProjectWithoutRazor_Publishes()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var firstSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj");
var secondSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new[] { @"C:\path\to\file.cshtml" });
var expectedConfigurationFilePath = @"C:\path\to\objbin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Same(secondSnapshot, snapshot);
@ -362,8 +389,8 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
EnqueueDelay = 10,
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(secondSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(secondSnapshot.Key, expectedConfigurationFilePath);
// Act
publisher.EnqueuePublish(secondSnapshot);
@ -378,6 +405,9 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task EnqueuePublish_OnProjectBeforeTagHelperProcessed_DoesNotPublish()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var firstSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj");
var tagHelpers = ImmutableArray.Create<TagHelperDescriptor>(
@ -389,7 +419,7 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
});
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Same(secondSnapshot, snapshot);
@ -401,8 +431,8 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
EnqueueDelay = 10,
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(firstSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(firstSnapshot.Key, expectedConfigurationFilePath);
// Act
publisher.EnqueuePublish(secondSnapshot);
@ -417,12 +447,15 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public void Publish_UnsetConfigurationFilePath_Noops()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore)
projectConfigurationFilePathStore)
{
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
var omniSharpProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj");
// Act & Assert
@ -433,11 +466,14 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public void Publish_PublishesToSetPublishFilePath()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var omniSharpProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj");
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Same(omniSharpProjectSnapshot, snapshot);
@ -447,8 +483,8 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
{
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
_projectConfigurationFilePathStore.Set(omniSharpProjectSnapshot.Key, expectedConfigurationFilePath);
publisher.Initialize(projectSnapshotManager);
projectConfigurationFilePathStore.Set(omniSharpProjectSnapshot.Key, expectedConfigurationFilePath);
// Act
publisher.Publish(omniSharpProjectSnapshot);
@ -461,11 +497,14 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task ProjectAdded_PublishesToCorrectFilePathAsync()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
@ -474,17 +513,17 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
{
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
var projectFilePath = @"C:\path\to\project.csproj";
var hostProject = new HostProject(projectFilePath, Path.Combine(Path.GetDirectoryName(projectFilePath), "obj"), RazorConfiguration.Default, "TestRootNamespace");
_projectConfigurationFilePathStore.Set(hostProject.Key, expectedConfigurationFilePath);
projectConfigurationFilePathStore.Set(hostProject.Key, expectedConfigurationFilePath);
var projectWorkspaceState = new ProjectWorkspaceState(ImmutableArray<TagHelperDescriptor>.Empty, CodeAnalysis.CSharp.LanguageVersion.Default);
// Act
await RunOnDispatcherThreadAsync(() =>
{
_projectSnapshotManager.ProjectAdded(hostProject);
_projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState);
projectSnapshotManager.ProjectAdded(hostProject);
projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState);
}).ConfigureAwait(false);
// Assert
@ -495,11 +534,14 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task ProjectAdded_DoesNotPublishWithoutProjectWorkspaceStateAsync()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.True(false, "Serialization should not have been atempted because there is no ProjectWorkspaceState.");
@ -508,12 +550,12 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
{
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
var hostProject = new HostProject(@"C:\path\to\project.csproj", @"C:\path\to\obj", RazorConfiguration.Default, "TestRootNamespace");
_projectConfigurationFilePathStore.Set(hostProject.Key, expectedConfigurationFilePath);
projectConfigurationFilePathStore.Set(hostProject.Key, expectedConfigurationFilePath);
// Act
await RunOnDispatcherThreadAsync(() => _projectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false);
await RunOnDispatcherThreadAsync(() => projectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false);
Assert.Empty(publisher.DeferredPublishTasks);
@ -525,17 +567,20 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task ProjectRemoved_UnSetPublishFilePath_NoopsAsync()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore)
projectConfigurationFilePathStore)
{
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
var hostProject = new HostProject(@"C:\path\to\project.csproj", @"C:\path\to\obj", RazorConfiguration.Default, "TestRootNamespace");
await RunOnDispatcherThreadAsync(() => _projectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false);
await RunOnDispatcherThreadAsync(() => projectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false);
// Act & Assert
await RunOnDispatcherThreadAsync(() => _projectSnapshotManager.ProjectRemoved(hostProject.Key)).ConfigureAwait(false);
await RunOnDispatcherThreadAsync(() => projectSnapshotManager.ProjectRemoved(hostProject.Key)).ConfigureAwait(false);
Assert.Empty(publisher.DeferredPublishTasks);
}
@ -544,11 +589,14 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
public async Task ProjectAdded_DoesNotFireWhenNotReadyAsync()
{
// Arrange
var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
var projectConfigurationFilePathStore = new DefaultProjectConfigurationFilePathStore();
var serializationSuccessful = false;
var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin";
var publisher = new TestRazorProjectInfoPublisher(
_projectConfigurationFilePathStore,
projectConfigurationFilePathStore,
onSerializeToFile: (snapshot, configurationFilePath) =>
{
Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
@ -558,17 +606,17 @@ public class RazorProjectInfoPublisherTest : LanguageServerTestBase
{
_active = true,
};
publisher.Initialize(_projectSnapshotManager);
publisher.Initialize(projectSnapshotManager);
var projectFilePath = @"C:\path\to\project.csproj";
var hostProject = new HostProject(projectFilePath, Path.Combine(Path.GetDirectoryName(projectFilePath), "obj"), RazorConfiguration.Default, "TestRootNamespace");
_projectConfigurationFilePathStore.Set(hostProject.Key, expectedConfigurationFilePath);
projectConfigurationFilePathStore.Set(hostProject.Key, expectedConfigurationFilePath);
var projectWorkspaceState = new ProjectWorkspaceState(ImmutableArray<TagHelperDescriptor>.Empty, CodeAnalysis.CSharp.LanguageVersion.Default);
// Act
await RunOnDispatcherThreadAsync(() =>
{
_projectSnapshotManager.ProjectAdded(hostProject);
_projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState);
projectSnapshotManager.ProjectAdded(hostProject);
projectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.Key, projectWorkspaceState);
}).ConfigureAwait(false);
// Assert