NetCore Analyzers
This commit is contained in:
Ryan Brandenburg 2020-08-04 14:20:34 -07:00 коммит произвёл GitHub
Родитель cbe5899d2c
Коммит 73f8402092
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
118 изменённых файлов: 362 добавлений и 340 удалений

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

@ -12,6 +12,7 @@ trim_trailing_whitespace = true
# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
insert_final_newline = true
# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]

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

@ -34,8 +34,14 @@
<!-- Working around https://github.com/microsoft/msbuild/pull/4764 -->
<EmbeddedResourceUseDependentUponConvention>false</EmbeddedResourceUseDependentUponConvention>
<CodeAnalysisRuleSet>$(RepoRoot)src/Razor/Microsoft.AspNetCore.Razor.Basic.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="$(Tooling_MicrosoftNetCoreAnalyzersPackageVersion)" NoWarn="NU1608" />
</ItemGroup>
<PropertyGroup Label="Package and Assembly Metadata">
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Product>Microsoft ASP.NET Core</Product>

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

@ -148,6 +148,7 @@
<Tooling_MicrosoftCodeAnalysisRemoteRazorServiceHubPackageVersion>3.7.0-4.20351.7</Tooling_MicrosoftCodeAnalysisRemoteRazorServiceHubPackageVersion>
<Tooling_MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>3.7.0-4.20351.7</Tooling_MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
<Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>3.7.0-4.20351.7</Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<Tooling_MicrosoftNetCoreAnalyzersPackageVersion>$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)</Tooling_MicrosoftNetCoreAnalyzersPackageVersion>
<Tooling_MicrosoftVisualStudioLanguageServicesPackageVersion>3.7.0-4.20351.7</Tooling_MicrosoftVisualStudioLanguageServicesPackageVersion>
<Tooling_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion>3.7.0-4.20351.7</Tooling_MicrosoftVisualStudioLanguageServicesRazorRemoteClientPackageVersion>
<XunitAnalyzersPackageVersion>0.10.0</XunitAnalyzersPackageVersion>

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

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Microsoft Managed Basic Rules" Description="" ToolsVersion="15.0">
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.CSharp.Analyzers">
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1810" Action="None" />
<Rule Id="CA1816" Action="None" />
<Rule Id="CA1826" Action="None" />
<Rule Id="CA2000" Action="Info" />
<Rule Id="CA2002" Action="Info" />
<Rule Id="CA2008" Action="Info" />
<Rule Id="CA2208" Action="None" />
<Rule Id="CA2237" Action="None" />
</Rules>
</RuleSet>

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

@ -69,15 +69,15 @@ namespace Microsoft.AspNetCore.Razor.Performance
TagHelperResolver,
new StaticProjectSnapshotProjectEngineFactory(),
},
new ILanguageService[]
{
});
Array.Empty<ILanguageService>());
return new DefaultProjectSnapshotManager(
new TestForegroundDispatcher(),
new TestErrorReporter(),
Array.Empty<ProjectSnapshotChangeTrigger>(),
#pragma warning disable CA2000 // Dispose objects before losing scope
new AdhocWorkspace(services));
#pragma warning restore CA2000 // Dispose objects before losing scope
}
private static IReadOnlyList<TagHelperDescriptor> ReadTagHelpers(string filePath)

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

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
{
var normalized = Normalize(directoryFilePath);
if (!normalized.EndsWith("/"))
if (!normalized.EndsWith("/", StringComparison.Ordinal))
{
normalized += '/';
}

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

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
@ -126,7 +125,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
continue;
}
if (newUsingNamespace.CompareTo(usingDirectiveNamespace) < 0)
if (string.CompareOrdinal(newUsingNamespace, usingDirectiveNamespace) < 0)
{
var usingDirectiveLineIndex = codeDocument.Source.Lines.GetLocation(usingDirective.Node.Span.Start).LineIndex;
var head = new Position(usingDirectiveLineIndex, 0);

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

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
@ -148,7 +149,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
string codeBehindPath;
do
{
var identifier = n > 0 ? n.ToString() : string.Empty; // Make it look nice
var identifier = n > 0 ? n.ToString(CultureInfo.InvariantCulture) : string.Empty; // Make it look nice
codeBehindPath = Path.Combine(
Path.GetDirectoryName(path),
$"{Path.GetFileNameWithoutExtension(path)}{identifier}{Path.GetExtension(path)}.cs");

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

@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
// 1. Determine if this specific completion is an indexer based completion
// 2. Resolve an appropriate snippet if it is. This is more troublesome because we need to remove the ... suffix to accurately
// build a snippet that makes sense for the user to type.
var indexerCompletion = filterText.EndsWith("...");
var indexerCompletion = filterText.EndsWith("...", StringComparison.Ordinal);
if (indexerCompletion)
{
filterText = filterText.Substring(0, filterText.Length - 3);

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

@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
if (summaryTagStart == -1 || summaryTagEndStart == -1)
{
// A really wrong but cheap way to check if this is XML
if (!documentation.StartsWith("<") && !documentation.EndsWith(">"))
if (!documentation.StartsWith("<", StringComparison.Ordinal) && !documentation.EndsWith(">", StringComparison.Ordinal))
{
// This doesn't look like a doc comment, we'll return it as-is.
summary = documentation;

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

@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
return Array.Empty<RazorCompletionItem>();
}
if (attributeNameLocation.IntersectsWith(location.AbsoluteIndex) && attributeName.StartsWith("@"))
if (attributeNameLocation.IntersectsWith(location.AbsoluteIndex) && attributeName.StartsWith("@", StringComparison.Ordinal))
{
// The transition is already provided for the attribute name
return Array.Empty<RazorCompletionItem>();

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

@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
}
else
{
Debug.Assert(binding.Descriptors.Count() > 0);
Debug.Assert(binding.Descriptors.Any());
var range = containingTagNameToken.GetRange(codeDocument.Source);
@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
}
else
{
Debug.Assert(binding.Descriptors.Count() > 0);
Debug.Assert(binding.Descriptors.Any());
var tagHelperAttributes = _tagHelperFactsService.GetBoundTagHelperAttributes(tagHelperDocumentContext, selectedAttributeName, binding);
var attribute = attributes.Single(a => a.Span.IntersectsWith(location.AbsoluteIndex));

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

@ -399,7 +399,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
private string EnsureFullPath(string filePath, string projectDirectory)
{
var normalizedFilePath = _filePathNormalizer.Normalize(filePath);
if (!normalizedFilePath.StartsWith(projectDirectory))
if (!normalizedFilePath.StartsWith(projectDirectory, StringComparison.Ordinal))
{
var absolutePath = Path.Combine(projectDirectory, normalizedFilePath);
normalizedFilePath = _filePathNormalizer.Normalize(absolutePath);

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

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var diagnostic = new Diagnostic()
{
Message = razorDiagnostic.GetMessage(),
Message = razorDiagnostic.GetMessage(CultureInfo.InvariantCulture),
Code = razorDiagnostic.Id,
Severity = ConvertSeverity(razorDiagnostic.Severity),
Range = ConvertSpanToRange(razorDiagnostic.Span, sourceText),

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

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
FilePath = filePath;
PhysicalPath = physicalPath;
FileKind = fileKind ?? FileKinds.GetFileKindFromFilePath(FilePath);
if (FilePath.StartsWith("/"))
if (FilePath.StartsWith("/", StringComparison.Ordinal))
{
RelativePhysicalPath = FilePath.Substring(1);
}

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

@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic.Models
private static IReadOnlyDictionary<string, uint> GetMap(IReadOnlyCollection<string> tokens)
{
var result = new Dictionary<string, uint>();
for (var i = 0; i < tokens.Count(); i++)
for (var i = 0; i < tokens.Count; i++)
{
result[tokens.ElementAt(i)] = (uint)i;
}

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

@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic.Services
break;
case DiffEdit.Type.Insert:
if (current != null &&
current.Data.Count() > 0 &&
current.Data.Any() &&
current.Start == diff.Position)
{
current.Data = current.Data.Append(NewArray[diff.NewTextPosition.Value]);

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

@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
throw new FormatException("TargetPath's must use '\\' instead of '/'");
}
if (targetPath.StartsWith("\\"))
if (targetPath.StartsWith("\\", StringComparison.Ordinal))
{
throw new FormatException("TargetPath's can't start with '\\'");
}

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

@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
break;
}
if (document.FilePath.EndsWith(ActiveVirtualDocumentSuffix) && !document.FilePath.EndsWith(BackgroundVirtualDocumentSuffix))
if (document.FilePath.EndsWith(ActiveVirtualDocumentSuffix, StringComparison.Ordinal) && !document.FilePath.EndsWith(BackgroundVirtualDocumentSuffix, StringComparison.Ordinal))
{
// Document from editor got opened, clear out any background documents of the same type
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
break;
}
if (document.FilePath.EndsWith(ActiveVirtualDocumentSuffix) && !document.FilePath.EndsWith(BackgroundVirtualDocumentSuffix))
if (document.FilePath.EndsWith(ActiveVirtualDocumentSuffix, StringComparison.Ordinal) && !document.FilePath.EndsWith(BackgroundVirtualDocumentSuffix, StringComparison.Ordinal))
{
var razorDocumentFilePath = GetRazorDocumentFilePath(document);
@ -247,12 +247,12 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
private static string GetRazorDocumentFilePath(Document document)
{
if (document.FilePath.EndsWith(BackgroundVirtualDocumentSuffix))
if (document.FilePath.EndsWith(BackgroundVirtualDocumentSuffix, StringComparison.Ordinal))
{
var razorDocumentFilePath = document.FilePath.Substring(0, document.FilePath.Length - BackgroundVirtualDocumentSuffix.Length);
return razorDocumentFilePath;
}
else if (document.FilePath.EndsWith(ActiveVirtualDocumentSuffix))
else if (document.FilePath.EndsWith(ActiveVirtualDocumentSuffix, StringComparison.Ordinal))
{
var razorDocumentFilePath = document.FilePath.Substring(0, document.FilePath.Length - ActiveVirtualDocumentSuffix.Length);
return razorDocumentFilePath;

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

@ -17,7 +17,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="$(Tooling_MicrosoftCodeAnalysisCSharpFeaturesPackageVersion)" />
<PackageReference Include="OmniSharp.MSBuild" Version="$(OmniSharpMSBuildPackageVersion)" />
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />

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

@ -82,7 +82,7 @@ namespace Microsoft.CodeAnalysis.Razor.Completion
// We don't provide Directive Attribute completions when we're in the middle of
// another unrelated (doesn't start with @) partially completed attribute.
// <svg xml:| ></svg> (attributeName = "xml:") should not get any directive attribute completions.
if (string.IsNullOrWhiteSpace(attributeName) || attributeName.StartsWith("@"))
if (string.IsNullOrWhiteSpace(attributeName) || attributeName.StartsWith("@", StringComparison.Ordinal))
{
return completionItems;
}
@ -146,13 +146,13 @@ namespace Microsoft.CodeAnalysis.Razor.Completion
foreach (var completion in attributeCompletions)
{
var insertText = completion.Key;
if (insertText.EndsWith("..."))
if (insertText.EndsWith("...", StringComparison.Ordinal))
{
// Indexer attribute, we don't want to insert with the triple dot.
insertText = insertText.Substring(0, insertText.Length - 3);
}
if (insertText.StartsWith("@"))
if (insertText.StartsWith("@", StringComparison.Ordinal))
{
// Strip off the @ from the insertion text. This change is here to align the insertion text with the
// completion hooks into VS and VSCode. Basically, completion triggers when `@` is typed so we don't
@ -206,7 +206,7 @@ namespace Microsoft.CodeAnalysis.Razor.Completion
boundAttributeDescriptor.Documentation);
attributeDescriptionInfos.Add(descriptionInfo);
if (attributeName.EndsWith("..."))
if (attributeName.EndsWith("...", StringComparison.Ordinal))
{
// Indexer attribute, we don't want to commit with standard chars
return;
@ -226,4 +226,4 @@ namespace Microsoft.CodeAnalysis.Razor.Completion
}
}
}
}
}

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

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Syntax;
@ -183,7 +184,7 @@ namespace Microsoft.CodeAnalysis.Razor.Completion
// It's possible that the attribute looks like a directive attribute but is incomplete.
// We should try and extract out the transition and parameter.
if (!attributeName.StartsWith("@"))
if (!attributeName.StartsWith("@", StringComparison.Ordinal))
{
// Doesn't look like a directive attribute. Not an incomplete directive attribute.
return;

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

@ -85,7 +85,7 @@ namespace Microsoft.CodeAnalysis.Razor
for (var i = 0; i < _factories.Length; i++)
{
var factory = _factories[i];
if (string.Equals(configuration.ConfigurationName, factory.Metadata.ConfigurationName))
if (string.Equals(configuration.ConfigurationName, factory.Metadata.ConfigurationName, StringComparison.Ordinal))
{
return requireSerializable && !factory.Metadata.SupportsSerialization ? null : factory.Value;
}

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

@ -9,7 +9,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(Tooling_MicrosoftCodeAnalysisCSharpPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Razor" Version="$(MicrosoftCodeAnalysisRazorPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.ExternalAccess.Razor" Version="$(Tooling_MicrosoftCodeAnalysisExternalAccessRazorPackageVersion)" />

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

@ -129,7 +129,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
document.FilePath.EndsWith(".razor", StringComparison.Ordinal) ||
// VSCode's background C# document
document.FilePath.EndsWith("__bg__virtual.cs"))
document.FilePath.EndsWith("__bg__virtual.cs", StringComparison.Ordinal))
{
EnqueueUpdate(e.ProjectId);
return;

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

@ -27,7 +27,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="$(MicrosoftAspNetCoreRazorLanguagePackageVersion)"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(Tooling_MicrosoftCodeAnalysisCSharpPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(Tooling_MicrosoftCodeAnalysisCommonPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Remote.Razor.ServiceHub" Version="$(Tooling_MicrosoftCodeAnalysisRemoteRazorServiceHubPackageVersion)" PrivateAssets="All" />

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

@ -57,6 +57,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
public void Dispose()
{
_main.Cancel();
_main.Dispose();
}
public IDisposable SynchronizeMainThreadState()

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

@ -10,7 +10,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="$(Tooling_MicrosoftCodeAnalysisCSharpFeaturesPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="$(Tooling_MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion)" />

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

@ -11,7 +11,6 @@
<ItemGroup>
<PackageReference Include="System.Composition" Version="$(SystemCompositionPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.VisualStudio.Editor" Version="$(MicrosoftVisualStudioEditorPackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Package.LanguageService.15.0" Version="$(MicrosoftVisualStudioPackageLanguageService150PackageVersion)" />
<!-- TODO: Remove this after we get rid of DefaultLSPEditorService -->

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

@ -75,6 +75,7 @@
<Rule Id="CA1707" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.Analyzers">
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1816" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.VisualStudio.Threading.Analyzers" RuleNamespace="Microsoft.VisualStudio.Threading.Analyzers">

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

@ -76,7 +76,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
{
TextBuffer.ChangeContentType(InertContentType.Instance, null);
if (TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDocument))
if (TextBuffer.Properties != null && TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDocument))
{
TextBuffer.Properties.RemoveProperty(typeof(ITextDocument));

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

@ -7,10 +7,8 @@ using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Threading;
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
@ -177,7 +175,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
// We have now obtained the necessary completion items. We no longer need the provisional change. Revert.
var removeProvisionalDot = new VisualStudioTextChange(previousCharacterProjection.PositionIndex, 1, string.Empty);
trackingDocumentManager.UpdateVirtualDocument<CSharpVirtualDocument>(documentSnapshot.Uri, new[] { removeProvisionalDot }, previousCharacterProjection.HostDocumentVersion);
return (true, result);

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

@ -215,7 +215,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor.HtmlCSharp
if (referenceText is string text)
{
if (text.StartsWith(codeBehindObjectPrefix))
if (text.StartsWith(codeBehindObjectPrefix, StringComparison.Ordinal))
{
return text
.Substring(codeBehindObjectPrefix.Length, text.Length - codeBehindObjectPrefix.Length - 1); // -1 for trailing `;`

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

@ -74,8 +74,10 @@
<Rule Id="CA1063" Action="None" />
<Rule Id="CA1707" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.Analyzers">
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.CSharp.Analyzers">
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1816" Action="None" />
<Rule Id="CA2008" Action="Info" />
</Rules>
<Rules AnalyzerId="Microsoft.VisualStudio.Threading.Analyzers" RuleNamespace="Microsoft.VisualStudio.Threading.Analyzers">
<Rule Id="VSTHRD001" Action="Info" />

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

@ -15,7 +15,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
throw new ArgumentNullException(nameof(uri));
}
return uri.GetAbsoluteOrUNCPath()?.EndsWith(RazorLSPConstants.VirtualCSharpFileNameSuffix) ?? false;
return uri.GetAbsoluteOrUNCPath()?.EndsWith(RazorLSPConstants.VirtualCSharpFileNameSuffix, StringComparison.Ordinal) ?? false;
}
public static bool IsRazorHtmlFile(Uri uri)
@ -25,7 +25,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
throw new ArgumentNullException(nameof(uri));
}
return uri.GetAbsoluteOrUNCPath()?.EndsWith(RazorLSPConstants.VirtualHtmlFileNameSuffix) ?? false;
return uri.GetAbsoluteOrUNCPath()?.EndsWith(RazorLSPConstants.VirtualHtmlFileNameSuffix, StringComparison.Ordinal) ?? false;
}
public static Uri GetRazorDocumentUri(Uri virtualDocumentUri)

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

@ -236,7 +236,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
}
}
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void ProjectConfigurationFilePathStore_Changed(object sender, ProjectConfigurationFilePathChangedEventArgs args)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
try
{

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

@ -21,7 +21,6 @@
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" />
<PackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="$(Tooling_MicrosoftCodeAnalysisPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(Tooling_MicrosoftCodeAnalysisCommonPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(Tooling_MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Features" Version="$(Tooling_MicrosoftCodeAnalysisFeaturesPackageVersion)" />

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

@ -92,14 +92,16 @@
<Rule Id="VSSDK005" Action="Info" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
<Rule Id="CA1507" Action="None" />
<Rule Id="CA1707" Action="None" />
<Rule Id="CA1810" Action="None" />
<Rule Id="CA1812" Action="None" />
<Rule Id="CA1819" Action="None" />
<Rule Id="CA1825" Action="None" />
<Rule Id="CA2007" Action="None" />
<Rule Id="CA2211" Action="None" />
<Rule Id="CA2227" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.CSharp.Analyzers">
<Rule Id="CA1303" Action="None" />
</Rules>
</RuleSet>

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

@ -10,8 +10,8 @@
namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules
{
internal partial class RazorConfiguration
{

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

@ -37,7 +37,9 @@ namespace Microsoft.VisualStudio.LiveShare.Razor.Guest
throw new ArgumentNullException(nameof(sessionContext));
}
#pragma warning disable CA2000 // Dispose objects before losing scope
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
#pragma warning restore CA2000 // Dispose objects before losing scope
_viewImportsCopyTask = EnsureViewImportsCopiedAsync(sessionContext, cts.Token);
_sessionAccessor.SetSession(sessionContext);
@ -89,7 +91,7 @@ namespace Microsoft.VisualStudio.LiveShare.Razor.Guest
{
foreach (var fileUri in fileUris)
{
if (fileUri.GetAbsoluteOrUNCPath().EndsWith(ViewImportsFileName))
if (fileUri.GetAbsoluteOrUNCPath().EndsWith(ViewImportsFileName, StringComparison.Ordinal))
{
var copyTask = sessionContext.DownloadFileAsync(fileUri, cancellationToken);
copyTasks.Add(copyTask);

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

@ -83,6 +83,7 @@ namespace Microsoft.VisualStudio.LiveShare.Razor.Host
_foregroundDispatcher.AssertForegroundThread();
_projectSnapshotManager.Changed -= ProjectSnapshotManager_Changed;
_latestStateSemaphore.Dispose();
_disposed = true;
}

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

@ -20,7 +20,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.VisualStudio.LiveShare" Version="$(MicrosoftVisualStudioLiveSharePackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServices" Version="$(Tooling_MicrosoftVisualStudioLanguageServicesPackageVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="$(MicrosoftVisualStudioShell150PackageVersion)" />

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

@ -4,6 +4,11 @@
<Name Resource="MinimumRecommendedRules_Name" />
<Description Resource="MinimumRecommendedRules_Description" />
</Localization>
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.CSharp.Analyzers">
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1810" Action="None" />
<Rule Id="CA1816" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />

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

@ -119,7 +119,8 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor.ProjectSystem
return false;
}
if (!item.Include.EndsWith(".razor") && !item.Include.EndsWith(".cshtml"))
if (!item.Include.EndsWith(".razor", StringComparison.Ordinal) && !item.Include.EndsWith(".cshtml", StringComparison.Ordinal))
{
// Doesn't have a Razor looking file extension
return false;
@ -273,4 +274,4 @@ namespace Microsoft.VisualStudio.Mac.LanguageServices.Razor.ProjectSystem
return true;
}
}
}
}

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

@ -160,7 +160,6 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion1_XPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion2_XPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="$(MicrosoftAspNetCoreRazorLanguagePackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.Razor" Version="$(MicrosoftCodeAnalysisRazorPackageVersion)" />
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="$(MicrosoftNETSdkRazorPackageVersion)" IncludeAssets="None" PrivateAssets="All" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.VisualStudio.ComponentModelHost" Version="$(MicrosoftVisualStudioComponentModelHostPackageVersion)" />

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

@ -8,10 +8,6 @@
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Razor.LanguageServer\Microsoft.AspNetCore.Razor.LanguageServer.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.LanguageServer.Test.Common\Microsoft.AspNetCore.Razor.LanguageServer.Test.Common.csproj" />

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

@ -11,7 +11,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingPackageVersion)" />
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
</ItemGroup>

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

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Common
public static TestDocumentSnapshot Create(string filePath, string text, VersionStamp version)
{
var testProject = TestProjectSnapshot.Create(filePath + ".csproj");
var testWorkspace = TestWorkspace.Create();
using var testWorkspace = TestWorkspace.Create();
var hostDocument = new HostDocument(filePath, filePath);
var sourceText = SourceText.From(text);
var documentState = new DocumentState(

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

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Common
{
internal class TestProjectSnapshot : DefaultProjectSnapshot
{
public static TestProjectSnapshot Create(string filePath, ProjectWorkspaceState projectWorkspaceState = null) => Create(filePath, new string[0], projectWorkspaceState);
public static TestProjectSnapshot Create(string filePath, ProjectWorkspaceState projectWorkspaceState = null) => Create(filePath, Array.Empty<string>(), projectWorkspaceState);
public static TestProjectSnapshot Create(string filePath, string[] documentFilePaths, ProjectWorkspaceState projectWorkspaceState = null) =>
Create(filePath, documentFilePaths, RazorConfiguration.Default, projectWorkspaceState);
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Common
var languageServices = new List<ILanguageService>();
var hostServices = TestServices.Create(workspaceServices, languageServices);
var workspace = TestWorkspace.Create(hostServices);
using var workspace = TestWorkspace.Create(hostServices);
var hostProject = new HostProject(filePath, configuration, "TestRootNamespace");
var state = ProjectState.Create(workspace.Services, hostProject);
foreach (var documentFilePath in documentFilePaths)

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

@ -19,8 +19,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
protected void RunAutoInsertTest(string input, string expected, string character, int tabSize = 4, bool insertSpaces = true, string fileKind = default, IReadOnlyList<TagHelperDescriptor> tagHelpers = default)
{
// Arrange
var location = input.IndexOf('|') + character.Length;
input = input.Replace("|", character);
var location = input.IndexOf('|', StringComparison.Ordinal) + character.Length;
input = input.Replace("|", character, StringComparison.Ordinal);
var source = SourceText.From(input);
source.GetLineAndOffset(location, out var line, out var column);

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

@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
{
// Arrange
var documentPath = "C:/path/to/Page.razor";
var codeActionEndpoint = new CodeActionEndpoint(new RazorCodeActionProvider[] { }, Dispatcher, EmptyDocumentResolver, LoggerFactory);
var codeActionEndpoint = new CodeActionEndpoint(Array.Empty<RazorCodeActionProvider>(), Dispatcher, EmptyDocumentResolver, LoggerFactory);
var request = new CodeActionParams()
{
TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var codeDocument = CreateCodeDocument("@code {}");
var documentResolver = CreateDocumentResolver(documentPath, codeDocument);
codeDocument.SetUnsupported();
var codeActionEndpoint = new CodeActionEndpoint(new RazorCodeActionProvider[] { }, Dispatcher, documentResolver, LoggerFactory);
var codeActionEndpoint = new CodeActionEndpoint(Array.Empty<RazorCodeActionProvider>(), Dispatcher, documentResolver, LoggerFactory);
var request = new CodeActionParams()
{
TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var documentPath = "C:/path/to/Page.razor";
var codeDocument = CreateCodeDocument("@code {}");
var documentResolver = CreateDocumentResolver(documentPath, codeDocument);
var codeActionEndpoint = new CodeActionEndpoint(new RazorCodeActionProvider[] { }, Dispatcher, documentResolver, LoggerFactory);
var codeActionEndpoint = new CodeActionEndpoint(Array.Empty<RazorCodeActionProvider>(), Dispatcher, documentResolver, LoggerFactory);
var request = new CodeActionParams()
{
TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),

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

@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
};
var location = new SourceLocation(0, -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component"), 9));
var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9));
var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer);
@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
};
var location = new SourceLocation(1, -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component"), 9));
var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9));
var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer);
@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
};
var location = new SourceLocation(1, -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component"), 9));
var context = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(contents.IndexOf("Component", StringComparison.Ordinal), 9));
var provider = new ComponentAccessibilityCodeActionProvider(new DefaultTagHelperFactsService(), FilePathNormalizer);

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

@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var editNewComponentChange = documentChanges[1];
var editNewComponentEdit = editNewComponentChange.TextDocumentEdit.Edits.First();
Assert.Contains("@namespace Another.Namespace", editNewComponentEdit.NewText);
Assert.Contains("@namespace Another.Namespace", editNewComponentEdit.NewText, StringComparison.Ordinal);
}
private static DocumentResolver CreateDocumentResolver(string documentPath, RazorCodeDocument codeDocument)

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

@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
Range = new Range(),
};
var location = new SourceLocation(contents.IndexOf("code"), -1, -1);
var location = new SourceLocation(contents.IndexOf("code", StringComparison.Ordinal), -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
context.CodeDocument.SetFileKind(FileKinds.Legacy);
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
Range = new Range(),
};
var location = new SourceLocation(contents.IndexOf("test"), -1, -1);
var location = new SourceLocation(contents.IndexOf("test", StringComparison.Ordinal), -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
var provider = new ExtractToCodeBehindCodeActionProvider();
@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
Range = new Range(),
};
var location = new SourceLocation(contents.IndexOf("code") + 6, -1, -1);
var location = new SourceLocation(contents.IndexOf("code", StringComparison.Ordinal) + 6, -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
var provider = new ExtractToCodeBehindCodeActionProvider();
@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
Range = new Range(),
};
var location = new SourceLocation(contents.IndexOf("code"), -1, -1);
var location = new SourceLocation(contents.IndexOf("code", StringComparison.Ordinal), -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
var provider = new ExtractToCodeBehindCodeActionProvider();
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
Range = new Range(),
};
var location = new SourceLocation(contents.IndexOf("code"), -1, -1);
var location = new SourceLocation(contents.IndexOf("code", StringComparison.Ordinal), -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
var provider = new ExtractToCodeBehindCodeActionProvider();
@ -153,7 +153,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
Range = new Range(),
};
var location = new SourceLocation(contents.IndexOf("code"), -1, -1);
var location = new SourceLocation(contents.IndexOf("code", StringComparison.Ordinal), -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
var provider = new ExtractToCodeBehindCodeActionProvider();
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
Range = new Range(),
};
var location = new SourceLocation(contents.IndexOf("functions"), -1, -1);
var location = new SourceLocation(contents.IndexOf("functions", StringComparison.Ordinal), -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
var provider = new ExtractToCodeBehindCodeActionProvider();

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

@ -108,10 +108,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var actionParams = new ExtractToCodeBehindCodeActionParams
{
Uri = documentUri,
RemoveStart = contents.IndexOf("@code"),
ExtractStart = contents.IndexOf("{"),
ExtractEnd = contents.IndexOf("}"),
RemoveEnd = contents.IndexOf("}"),
RemoveStart = contents.IndexOf("@code", StringComparison.Ordinal),
ExtractStart = contents.IndexOf("{", StringComparison.Ordinal),
ExtractEnd = contents.IndexOf("}", StringComparison.Ordinal),
RemoveEnd = contents.IndexOf("}", StringComparison.Ordinal),
};
var data = JObject.FromObject(actionParams);
@ -134,9 +134,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var editCodeBehindChange = documentChanges[2];
var editCodeBehindEdit = editCodeBehindChange.TextDocumentEdit.Edits.First();
Assert.Contains("public partial class Test", editCodeBehindEdit.NewText);
Assert.Contains("private var x = 1", editCodeBehindEdit.NewText);
Assert.Contains("namespace test.Pages", editCodeBehindEdit.NewText);
Assert.Contains("public partial class Test", editCodeBehindEdit.NewText, StringComparison.Ordinal);
Assert.Contains("private var x = 1", editCodeBehindEdit.NewText, StringComparison.Ordinal);
Assert.Contains("namespace test.Pages", editCodeBehindEdit.NewText, StringComparison.Ordinal);
}
[Fact]
@ -152,10 +152,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var actionParams = new ExtractToCodeBehindCodeActionParams
{
Uri = documentUri,
RemoveStart = contents.IndexOf("@functions"),
ExtractStart = contents.IndexOf("{"),
ExtractEnd = contents.IndexOf("}"),
RemoveEnd = contents.IndexOf("}"),
RemoveStart = contents.IndexOf("@functions", StringComparison.Ordinal),
ExtractStart = contents.IndexOf("{", StringComparison.Ordinal),
ExtractEnd = contents.IndexOf("}", StringComparison.Ordinal),
RemoveEnd = contents.IndexOf("}", StringComparison.Ordinal),
};
var data = JObject.FromObject(actionParams);
@ -178,9 +178,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var editCodeBehindChange = documentChanges[2];
var editCodeBehindEdit = editCodeBehindChange.TextDocumentEdit.Edits.First();
Assert.Contains("public partial class Test", editCodeBehindEdit.NewText);
Assert.Contains("private var x = 1", editCodeBehindEdit.NewText);
Assert.Contains("namespace test.Pages", editCodeBehindEdit.NewText);
Assert.Contains("public partial class Test", editCodeBehindEdit.NewText, StringComparison.Ordinal);
Assert.Contains("private var x = 1", editCodeBehindEdit.NewText, StringComparison.Ordinal);
Assert.Contains("namespace test.Pages", editCodeBehindEdit.NewText, StringComparison.Ordinal);
}
[Fact]
@ -196,10 +196,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var actionParams = new ExtractToCodeBehindCodeActionParams
{
Uri = documentUri,
RemoveStart = contents.IndexOf("@code"),
ExtractStart = contents.IndexOf("{"),
ExtractEnd = contents.IndexOf("}"),
RemoveEnd = contents.IndexOf("}"),
RemoveStart = contents.IndexOf("@code", StringComparison.Ordinal),
ExtractStart = contents.IndexOf("{", StringComparison.Ordinal),
ExtractEnd = contents.IndexOf("}", StringComparison.Ordinal),
RemoveEnd = contents.IndexOf("}", StringComparison.Ordinal),
};
var data = JObject.FromObject(actionParams);
@ -222,10 +222,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.CodeActions
var editCodeBehindChange = documentChanges[2];
var editCodeBehindEdit = editCodeBehindChange.TextDocumentEdit.Edits.First();
Assert.Contains("using System.Diagnostics", editCodeBehindEdit.NewText);
Assert.Contains("public partial class Test", editCodeBehindEdit.NewText);
Assert.Contains("private var x = 1", editCodeBehindEdit.NewText);
Assert.Contains("namespace test.Pages", editCodeBehindEdit.NewText);
Assert.Contains("using System.Diagnostics", editCodeBehindEdit.NewText, StringComparison.Ordinal);
Assert.Contains("public partial class Test", editCodeBehindEdit.NewText, StringComparison.Ordinal);
Assert.Contains("private var x = 1", editCodeBehindEdit.NewText, StringComparison.Ordinal);
Assert.Contains("namespace test.Pages", editCodeBehindEdit.NewText, StringComparison.Ordinal);
}
private static DocumentResolver CreateDocumentResolver(string documentPath, RazorCodeDocument codeDocument)

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

@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
tagHelpers = tagHelpers ?? Array.Empty<TagHelperDescriptor>();
var sourceDocument = TestRazorSourceDocument.Create(text, filePath: filePath, relativePath: filePath);
var projectEngine = RazorProjectEngine.Create(builder => { });
var fileKind = filePath.EndsWith(".razor") ? FileKinds.Component : FileKinds.Legacy;
var fileKind = filePath.EndsWith(".razor", StringComparison.Ordinal) ? FileKinds.Component : FileKinds.Legacy;
var codeDocument = projectEngine.ProcessDesignTime(sourceDocument, fileKind, Array.Empty<RazorSourceDocument>(), tagHelpers);
return codeDocument;
}

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

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common;
@ -61,8 +62,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var documentFilePath = "C:\\path\\to\\document.cshtml";
var normalizedFilePath = "C:/path/to/document.cshtml";
var filePathNormalizer = new FilePathNormalizer();
var project = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == new string[0]);
var miscProject = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == new string[0]);
var project = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == Array.Empty<string>());
var miscProject = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == Array.Empty<string>());
var projectResolver = Mock.Of<ProjectResolver>(resolver =>
resolver.TryResolvePotentialProject(normalizedFilePath, out project) == true &&
resolver.GetMiscellaneousProject() == miscProject);
@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var normalizedFilePath = "C:/path/to/document.cshtml";
var filePathNormalizer = new FilePathNormalizer();
var expectedDocument = Mock.Of<DocumentSnapshot>();
var project = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == new string[0]);
var project = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == Array.Empty<string>());
var miscProject = Mock.Of<ProjectSnapshot>(shim => shim.GetDocument(normalizedFilePath) == expectedDocument && shim.DocumentFilePaths ==new[] { normalizedFilePath });
var projectResolver = Mock.Of<ProjectResolver>(resolver =>
resolver.TryResolvePotentialProject(normalizedFilePath, out project) == true &&
@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// Arrange
var documentFilePath = "C:\\path\\to\\document.cshtml";
var filePathNormalizer = new FilePathNormalizer();
var project = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == new string[0]);
var project = Mock.Of<ProjectSnapshot>(shim => shim.DocumentFilePaths == Array.Empty<string>());
var projectResolver = Mock.Of<ProjectResolver>(resolver => resolver.GetMiscellaneousProject() == project);
var documentResolver = new DefaultDocumentResolver(Dispatcher, projectResolver, filePathNormalizer);

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

@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
// Arrange
var documentFilePath = "C:/path/to/document.cshtml";
var projectResolver = CreateProjectResolver(() => new ProjectSnapshot[0]);
var projectResolver = CreateProjectResolver(() => Array.Empty<ProjectSnapshot>());
// Act
var result = projectResolver.TryResolvePotentialProject(documentFilePath, out var project);

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

@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
public async Task GetLatestOptionsAsync_EmptyResponse_ReturnsNull()
{
// Arrange
var languageServer = GetLanguageServer(new object[] { });
var languageServer = GetLanguageServer(Array.Empty<object>());
var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);
// Act
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
public async Task GetLatestOptionsAsync_ClientRequestThrows_ReturnsNull()
{
// Arrange
var languageServer = GetLanguageServer(new object[] { }, shouldThrow: true);
var languageServer = GetLanguageServer(Array.Empty<object>(), shouldThrow: true);
var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);
// Act

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

@ -563,7 +563,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
// Arrange
var documentFilePath = "C:/path/to/document.cshtml";
var ownerProject = TestProjectSnapshot.Create("C:/path/to/project.csproj", new string[0]);
var ownerProject = TestProjectSnapshot.Create("C:/path/to/project.csproj", Array.Empty<string>());
var projectResolver = new TestProjectResolver(
new Dictionary<string, ProjectSnapshot>
{
@ -584,7 +584,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
// Arrange
var documentFilePath = "C:/path/to/document.cshtml";
var miscellaneousProject = TestProjectSnapshot.Create("C:/__MISC_PROJECT__", new string[0]);
var miscellaneousProject = TestProjectSnapshot.Create("C:/__MISC_PROJECT__", Array.Empty<string>());
var projectResolver = new TestProjectResolver(
new Dictionary<string, ProjectSnapshot>(),
miscellaneousProject);

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

@ -532,9 +532,9 @@ tabSize: 12);
private async Task RunFormattingTestAsync(string input, string expected, int tabSize = 4, bool insertSpaces = true, string fileKind = default)
{
// Arrange
var start = input.IndexOf('|');
var start = input.IndexOf('|', StringComparison.Ordinal);
var end = input.LastIndexOf('|');
input = input.Replace("|", string.Empty);
input = input.Replace("|", string.Empty, StringComparison.Ordinal);
var source = SourceText.From(input);
var span = TextSpan.FromBounds(start, end - 1);

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

@ -53,13 +53,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1></test1>";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("test1"), -1, -1);
var location = new SourceLocation(txt.IndexOf("test1", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
// Assert
Assert.Contains("**Test1TagHelper**", hover.Contents.MarkupContent.Value);
Assert.Contains("**Test1TagHelper**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
var expectedRange = new RangeModel(new Position(1, 1), new Position(1, 6));
Assert.Equal(expectedRange, hover.Range);
}
@ -71,14 +71,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1 bool-val='true'></test1>";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("bool-val"), -1, -1);
var location = new SourceLocation(txt.IndexOf("bool-val", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
// Assert
Assert.Contains("**BoolVal**", hover.Contents.MarkupContent.Value);
Assert.DoesNotContain("**IntVal**", hover.Contents.MarkupContent.Value);
Assert.Contains("**BoolVal**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
Assert.DoesNotContain("**IntVal**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
var expectedRange = new RangeModel(new Position(1, 7), new Position(1, 15));
Assert.Equal(expectedRange, hover.Range);
}
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1 bool-val='true'></test1>";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("true"), -1, -1);
var location = new SourceLocation(txt.IndexOf("true", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1 bool-val='true'></test1>";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("=") + 1, -1, -1);
var location = new SourceLocation(txt.IndexOf("=", StringComparison.Ordinal) + 1, -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1 bool-val='true'></test1>";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("true'") + 5, -1, -1);
var location = new SourceLocation(txt.IndexOf("true'", StringComparison.Ordinal) + 5, -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
@ -138,14 +138,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1 bool-val></test1>";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("bool-val"), -1, -1);
var location = new SourceLocation(txt.IndexOf("bool-val", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
// Assert
Assert.Contains("**BoolVal**", hover.Contents.MarkupContent.Value);
Assert.DoesNotContain("**IntVal**", hover.Contents.MarkupContent.Value);
Assert.Contains("**BoolVal**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
Assert.DoesNotContain("**IntVal**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
var expectedRange = new RangeModel(new Position(1, 7), new Position(1, 15));
Assert.Equal(expectedRange, hover.Range);
}
@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
}";
var codeDocument = CreateCodeDocument(txt, "text.razor", DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var charIndex = txt.IndexOf("@test") + 2;
var charIndex = txt.IndexOf("@test", StringComparison.Ordinal) + 2;
var location = new SourceLocation(charIndex, -1, -1);
// Act
@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
// Assert
Assert.NotNull(hover);
Assert.Contains("**Test**", hover.Contents.MarkupContent.Value);
Assert.Contains("**Test**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
var expectedRange = new RangeModel(new Position(1, 5), new Position(1, 10));
Assert.Equal(expectedRange, hover.Range);
}
@ -182,13 +182,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1<hello";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("test1"), -1, -1);
var location = new SourceLocation(txt.IndexOf("test1", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
// Assert
Assert.Contains("**Test1TagHelper**", hover.Contents.MarkupContent.Value);
Assert.Contains("**Test1TagHelper**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
var expectedRange = new RangeModel(new Position(1, 1), new Position(1, 6));
Assert.Equal(expectedRange, hover.Range);
}
@ -200,14 +200,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1 bool-val=\"aslj alsk<strong>";
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("bool-val"), -1, -1);
var location = new SourceLocation(txt.IndexOf("bool-val", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
// Assert
Assert.Contains("**BoolVal**", hover.Contents.MarkupContent.Value);
Assert.DoesNotContain("**IntVal**", hover.Contents.MarkupContent.Value);
Assert.Contains("**BoolVal**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
Assert.DoesNotContain("**IntVal**", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
var expectedRange = new RangeModel(new Position(1, 7), new Position(1, 15));
Assert.Equal(expectedRange, hover.Range);
}
@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var txt = $"@addTagHelper *, TestAssembly{Environment.NewLine}<p><strong></strong></p>";
var codeDocument = CreateCodeDocument(txt);
var service = GetDefaultRazorHoverInfoService();
var location = new SourceLocation(txt.IndexOf("strong"), -1, -1);
var location = new SourceLocation(txt.IndexOf("strong", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
@ -238,13 +238,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var languageServer = LanguageServer;
languageServer.ClientSettings.Capabilities.TextDocument.Hover.Value.ContentFormat = new Container<MarkupKind>(MarkupKind.PlainText);
var service = GetDefaultRazorHoverInfoService(languageServer);
var location = new SourceLocation(txt.IndexOf("test1"), -1, -1);
var location = new SourceLocation(txt.IndexOf("test1", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
// Assert
Assert.Contains("Test1TagHelper", hover.Contents.MarkupContent.Value);
Assert.Contains("Test1TagHelper", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
Assert.Equal(MarkupKind.PlainText, hover.Contents.MarkupContent.Kind);
var expectedRange = new RangeModel(new Position(1, 1), new Position(1, 6));
Assert.Equal(expectedRange, hover.Range);
@ -260,14 +260,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var languageServer = LanguageServer;
languageServer.ClientSettings.Capabilities.TextDocument.Hover.Value.ContentFormat = new Container<MarkupKind>(MarkupKind.PlainText);
var service = GetDefaultRazorHoverInfoService(languageServer);
var location = new SourceLocation(txt.IndexOf("bool-val"), -1, -1);
var location = new SourceLocation(txt.IndexOf("bool-val", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
// Assert
Assert.Contains("BoolVal", hover.Contents.MarkupContent.Value);
Assert.DoesNotContain("IntVal", hover.Contents.MarkupContent.Value);
Assert.Contains("BoolVal", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
Assert.DoesNotContain("IntVal", hover.Contents.MarkupContent.Value, StringComparison.Ordinal);
Assert.Equal(MarkupKind.PlainText, hover.Contents.MarkupContent.Kind);
var expectedRange = new RangeModel(new Position(1, 7), new Position(1, 15));
Assert.Equal(expectedRange, hover.Range);
@ -283,7 +283,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var languageServer = LanguageServer;
languageServer.ClientSettings.Capabilities.TextDocument.Hover.Value.ContentFormat = new Container<MarkupKind>(MarkupKind.PlainText);
var service = GetDefaultRazorHoverInfoService(languageServer);
var location = new SourceLocation(txt.IndexOf("strong"), -1, -1);
var location = new SourceLocation(txt.IndexOf("strong", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);
@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Hover
var languageServer = LanguageServer;
languageServer.ClientSettings.Capabilities.TextDocument.Hover.Value.ContentFormat = new Container<MarkupKind>(MarkupKind.PlainText);
var service = GetDefaultRazorHoverInfoService(languageServer);
var location = new SourceLocation(txt.IndexOf("weak"), -1, -1);
var location = new SourceLocation(txt.IndexOf("weak", StringComparison.Ordinal), -1, -1);
// Act
var hover = service.GetHoverInfo(codeDocument, location);

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

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Globalization;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// Assert
Assert.Equal(razorDiagnostic.Id, diagnostic.Code);
Assert.Equal(razorDiagnostic.GetMessage(), diagnostic.Message);
Assert.Equal(razorDiagnostic.GetMessage(CultureInfo.InvariantCulture), diagnostic.Message);
Assert.Null(diagnostic.Range);
Assert.Equal(DiagnosticSeverity.Error, diagnostic.Severity);
}

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

@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Test.Semantic
1, 1, 5, 0, 0, //line, character pos, length, tokenType, modifier
};
var startIndex = txt.IndexOf("test1");
var startIndex = txt.IndexOf("test1", StringComparison.Ordinal);
var endIndex = startIndex + 5;
var codeDocument = CreateCodeDocument(txt, DefaultTagHelpers);

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

@ -53,11 +53,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
<div>
Hello!
</div>
".Replace(Environment.NewLine, "\r\n"));
".Replace(Environment.NewLine, "\r\n", StringComparison.Ordinal));
var newText = SourceText.From(@"
<div>
Hola!
</div>".Replace(Environment.NewLine, "\r\n"));
</div>".Replace(Environment.NewLine, "\r\n", StringComparison.Ordinal));
// Act 1
var characterChanges = SourceTextDiffer.GetMinimalTextChanges(oldText, newText, lineDiffOnly: false);

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

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis;
@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
// Assert
var project = Assert.Single(Workspace.CurrentSolution.Projects);
Assert.Contains(project.Documents, roslynDocument => roslynDocument.FilePath.StartsWith(document.FilePath));
Assert.Contains(project.Documents, roslynDocument => roslynDocument.FilePath.StartsWith(document.FilePath, StringComparison.Ordinal));
}
[Fact]
@ -89,7 +90,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
// Assert
var project = Assert.Single(Workspace.CurrentSolution.Projects);
Assert.Contains(project.Documents, roslynDocument => roslynDocument.FilePath.StartsWith(document.FilePath));
Assert.Contains(project.Documents, roslynDocument => roslynDocument.FilePath.StartsWith(document.FilePath, StringComparison.Ordinal));
}
[Fact]

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

@ -3,6 +3,7 @@
using System;
using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -286,7 +287,7 @@ namespace Microsoft.AspNetCore.Razor.OmnisharpPlugin
var intermediateOutputPath = "C:/project\\obj";
projectRootElement.AddProperty(MSBuildProjectManager.IntermediateOutputPathPropertyName, intermediateOutputPath);
var projectInstance = new ProjectInstance(projectRootElement);
var expectedPath = string.Format("C:{0}project{0}obj{0}{1}", Path.DirectorySeparatorChar, LanguageServerConstants.ProjectConfigurationFile);
var expectedPath = string.Format(CultureInfo.InvariantCulture, "C:{0}project{0}obj{0}{1}", Path.DirectorySeparatorChar, LanguageServerConstants.ProjectConfigurationFile);
// Act
var result = MSBuildProjectManager.TryResolveConfigurationOutputPath(projectInstance, out var path);
@ -315,7 +316,7 @@ namespace Microsoft.AspNetCore.Razor.OmnisharpPlugin
{
// Arrange
var projectRootElement = ProjectRootElement.Create();
var intermediateOutputPath = string.Format("C:{0}project{0}obj", Path.DirectorySeparatorChar);
var intermediateOutputPath = string.Format(CultureInfo.InvariantCulture, "C:{0}project{0}obj", Path.DirectorySeparatorChar);
projectRootElement.AddProperty(MSBuildProjectManager.IntermediateOutputPathPropertyName, intermediateOutputPath);
var projectInstance = new ProjectInstance(projectRootElement);
var expectedPath = Path.Combine(intermediateOutputPath, LanguageServerConstants.ProjectConfigurationFile);

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

@ -18,7 +18,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildPackageVersion)" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="$(MicrosoftBuildLocatorPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
</ItemGroup>
</Project>

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

@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
// FilePaths in Razor are **always** are of the form '/a/b/c.cshtml'
filePath = physicalPath.Replace('\\', '/');
if (!filePath.StartsWith("/"))
if (!filePath.StartsWith("/", StringComparison.OrdinalIgnoreCase))
{
filePath = '/' + filePath;
}
@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
throw new InvalidOperationException(message);
}
var suffixIndex = FileName.LastIndexOf("_");
var suffixIndex = FileName.LastIndexOf("_", StringComparison.Ordinal);
var normalizedFileName = suffixIndex == -1 ? FileName : FileName.Substring(0, suffixIndex);
var sourceFileName = Path.ChangeExtension(normalizedFileName, FileExtension);
var testFile = TestFile.Create(sourceFileName, GetType().GetTypeInfo().Assembly);
@ -191,8 +191,8 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
sourceFileName = sourceFileName.Replace('\\', '/');
// FilePaths in Razor are **always** are of the form '/a/b/c.cshtml'
filePath = filePath ?? sourceFileName;
if (!filePath.StartsWith("/"))
filePath ??= sourceFileName;
if (!filePath.StartsWith("/", StringComparison.Ordinal))
{
filePath = '/' + filePath;
}
@ -511,7 +511,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
}
// See #2594
if (string.Equals("@", expectedSpan))
if (string.Equals("@", expectedSpan, StringComparison.Ordinal))
{
// For now we don't verify an escaped transition. In some cases one of the @ tokens in @@foo
// will be mapped as C# but will not be present in the output buffer because it's not actually C#.

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

@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
private void AssertNodeEquals(IntermediateNode node, IEnumerable<IntermediateNode> ancestors, string expected, string actual)
{
if (string.Equals(expected, actual))
if (string.Equals(expected, actual, StringComparison.Ordinal))
{
// YAY!!! everything is great.
return;
@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
var expectedName = GetName(expected, charsVerified);
var actualName = GetName(actual, charsVerified);
if (!string.Equals(expectedName, actualName))
if (!string.Equals(expectedName, actualName, StringComparison.Ordinal))
{
var message = $"Node names are not equal.";
throw new IntermediateNodeBaselineException(node, ancestors.ToArray(), expected, actual, message);
@ -155,13 +155,13 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
return;
}
var expectedDelimiter = expected.IndexOf(" - ", charsVerified);
var expectedDelimiter = expected.IndexOf(" - ", charsVerified, StringComparison.Ordinal);
if (expectedDelimiter != charsVerified && expectedDelimiter != -1)
{
throw new InvalidOperationException($"Baseline text is not well-formed: '{actual}'.");
}
var actualDelimiter = actual.IndexOf(" - ", charsVerified);
var actualDelimiter = actual.IndexOf(" - ", charsVerified, StringComparison.Ordinal);
if (actualDelimiter != charsVerified && actualDelimiter != -1)
{
throw new InvalidOperationException($"Baseline text is not well-formed: '{actual}'.");
@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
var expectedLocation = GetLocation(expected, charsVerified);
var actualLocation = GetLocation(actual, charsVerified);
if (!string.Equals(expectedLocation, actualLocation))
if (!string.Equals(expectedLocation, actualLocation, StringComparison.Ordinal))
{
var message = $"Locations are not equal.";
throw new IntermediateNodeBaselineException(node, ancestors.ToArray(), expected, actual, message);
@ -191,7 +191,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
var expectedContent = GetContent(expected, charsVerified);
var actualContent = GetContent(actual, charsVerified);
if (!string.Equals(expectedContent, actualContent))
if (!string.Equals(expectedContent, actualContent, StringComparison.Ordinal))
{
var message = $"Contents are not equal.";
throw new IntermediateNodeBaselineException(node, ancestors.ToArray(), expected, actual, message);
@ -202,7 +202,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
private string GetName(string text, int start)
{
var delimiter = text.IndexOf(" - ", start);
var delimiter = text.IndexOf(" - ", start, StringComparison.Ordinal);
if (delimiter == -1)
{
throw new InvalidOperationException($"Baseline text is not well-formed: '{text}'.");
@ -213,7 +213,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
private string GetLocation(string text, int start)
{
var delimiter = text.IndexOf(" - ", start);
var delimiter = text.IndexOf(" - ", start, StringComparison.Ordinal);
return delimiter == -1 ? text.Substring(start) : text.Substring(start, delimiter - start);
}

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

@ -3,10 +3,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Razor.Language.Components;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
@ -115,27 +114,27 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public override void VisitTagHelper(TagHelperIntermediateNode node)
{
WriteContentNode(node, node.TagName, string.Format("{0}.{1}", nameof(TagMode), node.TagMode));
WriteContentNode(node, node.TagName, string.Format(CultureInfo.InvariantCulture, "{0}.{1}", nameof(TagMode), node.TagMode));
}
public override void VisitTagHelperProperty(TagHelperPropertyIntermediateNode node)
{
WriteContentNode(node, node.AttributeName, node.BoundAttribute.DisplayName, string.Format("HtmlAttributeValueStyle.{0}", node.AttributeStructure));
WriteContentNode(node, node.AttributeName, node.BoundAttribute.DisplayName, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", node.AttributeStructure));
}
public override void VisitTagHelperHtmlAttribute(TagHelperHtmlAttributeIntermediateNode node)
{
WriteContentNode(node, node.AttributeName, string.Format("HtmlAttributeValueStyle.{0}", node.AttributeStructure));
WriteContentNode(node, node.AttributeName, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", node.AttributeStructure));
}
public override void VisitTagHelperDirectiveAttribute(TagHelperDirectiveAttributeIntermediateNode node)
{
WriteContentNode(node, node.AttributeName, node.BoundAttribute.DisplayName, string.Format("HtmlAttributeValueStyle.{0}", node.AttributeStructure));
WriteContentNode(node, node.AttributeName, node.BoundAttribute.DisplayName, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", node.AttributeStructure));
}
public override void VisitTagHelperDirectiveAttributeParameter(TagHelperDirectiveAttributeParameterIntermediateNode node)
{
WriteContentNode(node, node.AttributeName, string.Format("HtmlAttributeValueStyle.{0}", node.AttributeStructure));
WriteContentNode(node, node.AttributeName, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", node.AttributeStructure));
}
public override void VisitComponent(ComponentIntermediateNode node)
@ -145,7 +144,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public override void VisitComponentAttribute(ComponentAttributeIntermediateNode node)
{
WriteContentNode(node, node.AttributeName, node.PropertyName, string.Format("AttributeStructure.{0}", node.AttributeStructure));
WriteContentNode(node, node.AttributeName, node.PropertyName, string.Format(CultureInfo.InvariantCulture, "AttributeStructure.{0}", node.AttributeStructure));
}
public override void VisitComponentChildContent(ComponentChildContentIntermediateNode node)
@ -196,13 +195,13 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
WriteContentNode(n, n.VariableName);
break;
case PreallocatedTagHelperHtmlAttributeValueIntermediateNode n:
WriteContentNode(n, n.VariableName, n.AttributeName, n.Value, string.Format("HtmlAttributeValueStyle.{0}", n.AttributeStructure));
WriteContentNode(n, n.VariableName, n.AttributeName, n.Value, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", n.AttributeStructure));
break;
case PreallocatedTagHelperPropertyIntermediateNode n:
WriteContentNode(n, n.VariableName, n.AttributeName, n.PropertyName);
break;
case PreallocatedTagHelperPropertyValueIntermediateNode n:
WriteContentNode(n, n.VariableName, n.AttributeName, n.Value, string.Format("HtmlAttributeValueStyle.{0}", n.AttributeStructure));
WriteContentNode(n, n.VariableName, n.AttributeName, n.Value, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", n.AttributeStructure));
break;
case DefaultTagHelperCreateIntermediateNode n:
WriteContentNode(n, n.TypeName);
@ -211,10 +210,10 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
WriteBasicNode(n);
break;
case DefaultTagHelperHtmlAttributeIntermediateNode n:
WriteContentNode(n, n.AttributeName, string.Format("HtmlAttributeValueStyle.{0}", n.AttributeStructure));
WriteContentNode(n, n.AttributeName, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", n.AttributeStructure));
break;
case DefaultTagHelperPropertyIntermediateNode n:
WriteContentNode(n, n.AttributeName, n.BoundAttribute.DisplayName, string.Format("HtmlAttributeValueStyle.{0}", n.AttributeStructure));
WriteContentNode(n, n.AttributeName, n.BoundAttribute.DisplayName, string.Format(CultureInfo.InvariantCulture, "HtmlAttributeValueStyle.{0}", n.AttributeStructure));
break;
case DefaultTagHelperRuntimeIntermediateNode n:
WriteBasicNode(n);
@ -276,7 +275,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
protected void WriteName(IntermediateNode node)
{
var typeName = node.GetType().Name;
if (typeName.EndsWith("IntermediateNode"))
if (typeName.EndsWith("IntermediateNode", StringComparison.Ordinal))
{
_writer.Write(typeName.Substring(0, typeName.Length - "IntermediateNode".Length));
}
@ -315,43 +314,6 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
_writer.Write(")");
}
protected void WriteDiagnostics(IntermediateNode node)
{
if (node.HasDiagnostics)
{
_writer.Write("| ");
for (var i = 0; i < node.Diagnostics.Count; i++)
{
var diagnostic = node.Diagnostics[i];
_writer.Write("{");
WriteSourceRange(diagnostic.Span);
_writer.Write(": ");
_writer.Write(diagnostic.Severity);
_writer.Write(" ");
_writer.Write(diagnostic.Id);
_writer.Write(": ");
// Purposefully not writing out the entire message to ensure readable IR and because messages
// can span multiple lines. Not using string.GetHashCode because we can't have any collisions.
using (var md5 = MD5.Create())
{
var diagnosticMessage = diagnostic.GetMessage();
var messageBytes = Encoding.UTF8.GetBytes(diagnosticMessage);
var messageHash = md5.ComputeHash(messageBytes);
var stringHashBuilder = new StringBuilder();
for (var j = 0; j < messageHash.Length; j++)
{
stringHashBuilder.Append(messageHash[j].ToString("x2"));
}
var stringHash = stringHashBuilder.ToString();
_writer.Write(stringHash);
}
_writer.Write("} ");
}
}
}
protected void WriteContent(string content)
{

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

@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
// FilePaths in Razor are **always** are of the form '/a/b/c.cshtml'
var filePath = cshtmlRelativePath.Replace('\\', '/');
if (!filePath.StartsWith("/"))
if (!filePath.StartsWith("/", StringComparison.Ordinal))
{
filePath = '/' + filePath;
}

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

@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void AssertEqual(ClassifiedSpanInternal span, string expected, string actual)
{
if (string.Equals(expected, actual))
if (string.Equals(expected, actual, StringComparison.Ordinal))
{
return;
}

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

@ -143,14 +143,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
else
{
var classifiedSpanBaseline = new string[0];
var classifiedSpanBaseline = Array.Empty<string>();
classifiedSpanBaseline = classifiedSpanFile.ReadAllText().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
ClassifiedSpanVerifier.Verify(syntaxTree, classifiedSpanBaseline);
}
// Verify tag helper spans
var tagHelperSpanFile = TestFile.Create(baselineTagHelperSpansFileName, GetType().GetTypeInfo().Assembly);
var tagHelperSpanBaseline = new string[0];
var tagHelperSpanBaseline = Array.Empty<string>();
if (tagHelperSpanFile.Exists())
{
tagHelperSpanBaseline = tagHelperSpanFile.ReadAllText().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

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

@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void AssertNodeEquals(SyntaxNode node, IEnumerable<SyntaxNode> ancestors, string expected, string actual)
{
if (string.Equals(expected, actual))
if (string.Equals(expected, actual, StringComparison.Ordinal))
{
// YAY!!! everything is great.
return;
@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var expectedName = GetName(expected, charsVerified);
var actualName = GetName(actual, charsVerified);
if (!string.Equals(expectedName, actualName))
if (!string.Equals(expectedName, actualName, StringComparison.Ordinal))
{
var message = $"Node names are not equal.";
throw new SyntaxNodeBaselineException(node, ancestors.ToArray(), expected, actual, message);
@ -176,13 +176,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
return;
}
var expectedDelimiter = expected.IndexOf(" - ", charsVerified);
var expectedDelimiter = expected.IndexOf(" - ", charsVerified, StringComparison.Ordinal);
if (expectedDelimiter != charsVerified && expectedDelimiter != -1)
{
throw new InvalidOperationException($"Baseline text is not well-formed: '{actual}'.");
}
var actualDelimiter = actual.IndexOf(" - ", charsVerified);
var actualDelimiter = actual.IndexOf(" - ", charsVerified, StringComparison.Ordinal);
if (actualDelimiter != charsVerified && actualDelimiter != -1)
{
throw new InvalidOperationException($"Baseline text is not well-formed: '{actual}'.");
@ -198,7 +198,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var expectedLocation = GetLocation(expected, charsVerified);
var actualLocation = GetLocation(actual, charsVerified);
if (!string.Equals(expectedLocation, actualLocation))
if (!string.Equals(expectedLocation, actualLocation, StringComparison.Ordinal))
{
var message = $"Locations are not equal.";
throw new SyntaxNodeBaselineException(node, ancestors.ToArray(), expected, actual, message);
@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
var expectedContent = GetContent(expected, charsVerified);
var actualContent = GetContent(actual, charsVerified);
if (!string.Equals(expectedContent, actualContent))
if (!string.Equals(expectedContent, actualContent, StringComparison.Ordinal))
{
var message = $"Contents are not equal.";
throw new SyntaxNodeBaselineException(node, ancestors.ToArray(), expected, actual, message);
@ -223,7 +223,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private string GetName(string text, int start)
{
var delimiter = text.IndexOf(" - ", start);
var delimiter = text.IndexOf(" - ", start, StringComparison.Ordinal);
if (delimiter == -1)
{
throw new InvalidOperationException($"Baseline text is not well-formed: '{text}'.");
@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private string GetLocation(string text, int start)
{
var delimiter = text.IndexOf(" - ", start);
var delimiter = text.IndexOf(" - ", start, StringComparison.Ordinal);
return delimiter == -1 ? text.Substring(start) : text.Substring(start, delimiter - start);
}

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

@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void AssertEqual(TagHelperSpanInternal span, string expected, string actual)
{
if (string.Equals(expected, actual))
if (string.Equals(expected, actual, StringComparison.Ordinal))
{
return;
}

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

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using Xunit;
@ -35,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var stream = Assembly.GetManifestResourceStream(ResourceName);
if (stream == null)
{
Assert.True(false, string.Format("Manifest resource: {0} not found", ResourceName));
Assert.True(false, string.Format(CultureInfo.InvariantCulture, "Manifest resource: {0} not found", ResourceName));
}
return stream;

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

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Language
private readonly Dictionary<string, RazorProjectItem> _lookup;
public TestRazorProjectFileSystem()
: this(new RazorProjectItem[0])
: this(Array.Empty<RazorProjectItem>())
{
}

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

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
/// </summary>
public abstract class ReadOnlyTagHelperAttributeList : ReadOnlyCollection<TagHelperAttribute>
{
private static readonly IReadOnlyList<TagHelperAttribute> EmptyList = new TagHelperAttribute[0];
private static readonly IReadOnlyList<TagHelperAttribute> EmptyList = Array.Empty<TagHelperAttribute>();
/// <summary>
/// Instantiates a new instance of <see cref="ReadOnlyTagHelperAttributeList"/> with an empty
@ -187,4 +187,4 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return string.Equals(name, attribute.Name, StringComparison.OrdinalIgnoreCase);
}
}
}
}

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

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
/// </summary>
public abstract class ReadOnlyTagHelperAttributeList : ReadOnlyCollection<TagHelperAttribute>
{
private static readonly IReadOnlyList<TagHelperAttribute> EmptyList = new TagHelperAttribute[0];
private static readonly IReadOnlyList<TagHelperAttribute> EmptyList = Array.Empty<TagHelperAttribute>();
/// <summary>
/// Instantiates a new instance of <see cref="ReadOnlyTagHelperAttributeList"/> with an empty
@ -187,4 +187,4 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return string.Equals(name, attribute.Name, StringComparison.OrdinalIgnoreCase);
}
}
}
}

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

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
/// </summary>
public abstract class ReadOnlyTagHelperAttributeList : ReadOnlyCollection<TagHelperAttribute>
{
private static readonly IReadOnlyList<TagHelperAttribute> EmptyList = new TagHelperAttribute[0];
private static readonly IReadOnlyList<TagHelperAttribute> EmptyList = Array.Empty<TagHelperAttribute>();
/// <summary>
/// Instantiates a new instance of <see cref="ReadOnlyTagHelperAttributeList"/> with an empty
@ -187,4 +187,4 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return string.Equals(name, attribute.Name, StringComparison.OrdinalIgnoreCase);
}
}
}
}

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

@ -12,7 +12,6 @@
<PackageReference Include="xunit.core" Version="$(XUnitVersion)" />
<PackageReference Include="xunit.extensibility.core" Version="$(XUnitVersion)" />
<PackageReference Include="xunit.extensibility.execution" Version="$(XUnitVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(Tooling_MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Razor" Version="$(MicrosoftCodeAnalysisRazorPackageVersion)" />
</ItemGroup>

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

@ -17,7 +17,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(Tooling_MicrosoftCodeAnalysisWorkspacesCommonPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(Tooling_MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(Tooling_MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion)" />

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

@ -139,7 +139,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
// Assert
Assert.NotNull(ComponentCshtmlHostDocument.GeneratedDocumentContainer.OutputCSharp);
Assert.Contains("using Microsoft.AspNetCore.Components", ComponentCshtmlHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode);
Assert.Contains("using Microsoft.AspNetCore.Components", ComponentCshtmlHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode, StringComparison.Ordinal);
}
[Fact]
public async Task GetGeneratedOutputAsync_Component()
@ -149,7 +149,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
// Assert
Assert.NotNull(ComponentHostDocument.GeneratedDocumentContainer.OutputCSharp);
Assert.Contains("ComponentBase", ComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode);
Assert.Contains("ComponentBase", ComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode, StringComparison.Ordinal);
}
[Fact]
@ -160,9 +160,9 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
// Assert
Assert.NotNull(NestedComponentHostDocument.GeneratedDocumentContainer.OutputCSharp);
Assert.Contains("ComponentBase", NestedComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode);
Assert.Contains("namespace SomeProject.Nested", NestedComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode);
Assert.Contains("class File3", NestedComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode);
Assert.Contains("ComponentBase", NestedComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode, StringComparison.Ordinal);
Assert.Contains("namespace SomeProject.Nested", NestedComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode, StringComparison.Ordinal);
Assert.Contains("class File3", NestedComponentHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode, StringComparison.Ordinal);
}
// This is a sanity test that we invoke legacy codegen for .cshtml files. It's a little fragile but
@ -175,7 +175,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
// Assert
Assert.NotNull(LegacyHostDocument.GeneratedDocumentContainer.OutputCSharp);
Assert.Contains("Template", LegacyHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode);
Assert.Contains("Template", LegacyHostDocument.GeneratedDocumentContainer.OutputCSharp.GeneratedCode, StringComparison.Ordinal);
}
[Fact]

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

@ -17,7 +17,9 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
public void SetOutput_AcceptsSameVersionedDocuments()
{
// Arrange
var services = TestWorkspace.Create().Services;
using var workspace = TestWorkspace.Create();
var services = workspace.Services;
var hostProject = new HostProject("C:/project.csproj", RazorConfiguration.Default, "project");
var projectState = ProjectState.Create(services, hostProject);
var project = new DefaultProjectSnapshot(projectState);
@ -47,7 +49,9 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
public void SetOutput_AcceptsInitialOutput()
{
// Arrange
var services = TestWorkspace.Create().Services;
using var workspace = TestWorkspace.Create();
var services = workspace.Services;
var hostProject = new HostProject("C:/project.csproj", RazorConfiguration.Default, "project");
var projectState = ProjectState.Create(services, hostProject);
var project = new DefaultProjectSnapshot(projectState);
@ -74,7 +78,9 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
public void SetOutput_InvokesChangedEvent()
{
// Arrange
var services = TestWorkspace.Create().Services;
using var workspace = TestWorkspace.Create();
var services = workspace.Services;
var hostProject = new HostProject("C:/project.csproj", RazorConfiguration.Default, "project");
var projectState = ProjectState.Create(services, hostProject);
var project = new DefaultProjectSnapshot(projectState);

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

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
@ -49,7 +50,7 @@ namespace Microsoft.CodeAnalysis.Razor
var generated = output.GetCSharpDocument();
var symbol = "SomeProperty";
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol), symbol.Length);
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol, StringComparison.Ordinal), symbol.Length);
// Act
var result = RazorSpanMappingService.TryGetLinePositionSpan(span, await document.GetTextAsync(), generated, out var mapped);
@ -84,7 +85,7 @@ namespace Microsoft.CodeAnalysis.Razor
var symbol = "SomeProperty";
// Second occurrence
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol, generated.GeneratedCode.IndexOf(symbol) + symbol.Length), symbol.Length);
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol, generated.GeneratedCode.IndexOf(symbol, StringComparison.Ordinal) + symbol.Length, StringComparison.Ordinal), symbol.Length);
// Act
var result = RazorSpanMappingService.TryGetLinePositionSpan(span, await document.GetTextAsync(), generated, out var mapped);
@ -118,7 +119,7 @@ namespace Microsoft.CodeAnalysis.Razor
var generated = output.GetCSharpDocument();
var symbol = "SomeProperty";
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol), symbol.Length);
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol, StringComparison.Ordinal), symbol.Length);
// Act
var result = RazorSpanMappingService.TryGetLinePositionSpan(span, await document.GetTextAsync(), generated, out var mapped);
@ -152,7 +153,7 @@ namespace Microsoft.CodeAnalysis.Razor
var generated = output.GetCSharpDocument();
var symbol = "ExecuteAsync";
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol), symbol.Length);
var span = new TextSpan(generated.GeneratedCode.IndexOf(symbol, StringComparison.Ordinal), symbol.Length);
// Act
var result = RazorSpanMappingService.TryGetLinePositionSpan(span, await document.GetTextAsync(), generated, out var mapped);
@ -161,4 +162,4 @@ namespace Microsoft.CodeAnalysis.Razor
Assert.False(result);
}
}
}
}

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

@ -30,11 +30,13 @@ namespace Microsoft.CodeAnalysis.Razor
public (SourceText sourceText, TextSpan span) CreateText(string text)
{
// Since we're using positions, normalize to Windows style
#pragma warning disable CA1307 // Specify StringComparison
text = text.Replace("\r", "").Replace("\n", "\r\n");
var start = text.IndexOf('|');
var length = text.IndexOf('|', start + 1) - start - 1;
text = text.Replace("|", "");
#pragma warning restore CA1307 // Specify StringComparison
if (start < 0 || length < 0)
{

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

@ -31,7 +31,7 @@ namespace Microsoft.VisualStudio.Text
while (delimiterIndex != -1)
{
var delimiterLength = 2;
delimiterIndex = Content.IndexOf("\r\n", start);
delimiterIndex = Content.IndexOf("\r\n", start, StringComparison.Ordinal);
if (delimiterIndex == -1)
{
@ -206,7 +206,7 @@ namespace Microsoft.VisualStudio.Text
_contentWithLineBreak = contentWithLineBreak;
_content = contentWithLineBreak;
if (_content.EndsWith("\r\n"))
if (_content.EndsWith("\r\n", StringComparison.Ordinal))
{
_content = _content.Substring(0, _content.Length - 2);
}

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

@ -27,7 +27,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
var previousLineEndIndex = DefaultRazorIndentationFactsService.GetPreviousLineEndIndex(textSnapshot, line);
// Assert
Assert.Equal(txt.IndexOf("</p>") + 2 + Environment.NewLine.Length, previousLineEndIndex);
Assert.Equal(txt.IndexOf("</p>", StringComparison.Ordinal) + 2 + Environment.NewLine.Length, previousLineEndIndex);
}
[Fact]

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

@ -523,7 +523,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
{
// Verify if the syntax tree represents the expected input.
var syntaxTreeContent = manager.PartialParsingSyntaxTreeRoot.ToFullString();
Assert.Contains(expectedCode, syntaxTreeContent);
Assert.Contains(expectedCode, syntaxTreeContent, StringComparison.Ordinal);
}
var sourceDocument = TestRazorSourceDocument.Create(content);
@ -745,6 +745,8 @@ namespace Microsoft.VisualStudio.Editor.Razor
public void Dispose()
{
_parser.Dispose();
_parserComplete.Dispose();
_reparseComplete.Dispose();
}
}
@ -753,4 +755,4 @@ namespace Microsoft.VisualStudio.Editor.Razor
public override bool IsCompletionActive(ITextView textView) => false;
}
}
}
}

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

@ -85,7 +85,7 @@ namespace Microsoft.VisualStudio.Test
_attachedChangedEvents.Remove(value);
}
}
public event EventHandler<TextContentChangedEventArgs> ChangedLowPriority;
public event EventHandler<TextContentChangedEventArgs> ChangedHighPriority;
@ -99,7 +99,8 @@ namespace Microsoft.VisualStudio.Test
public ITextEdit CreateEdit() => new BufferEdit(this);
public void ChangeContentType(IContentType newContentType, object editTag) => throw new NotImplementedException();
public void ChangeContentType(IContentType newContentType, object editTag){
}
public bool CheckEditAccess() => throw new NotImplementedException();

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

@ -29,7 +29,6 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsPackageVersion)"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion1_XPackageVersion)"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsVersion2_XPackageVersion)"/>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(Tooling_MicrosoftCodeAnalysisCommonPackageVersion)" />
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<PackageReference Include="xunit.analyzers" Version="$(XunitAnalyzersPackageVersion)" />

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

@ -20,7 +20,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
// Arrange
var syntaxTree = GetSyntaxTree(str);
var location = new SourceSpan(str.IndexOf("tag") - 1, 13);
var location = new SourceSpan(str.IndexOf("tag", StringComparison.Ordinal) - 1, 13);
var service = new DefaultRazorSyntaxFactsService();
// Act

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

@ -7,7 +7,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
</ItemGroup>

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

@ -16,8 +16,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
public DefaultLSPDocumentManagerTest()
{
ChangeTriggers = Enumerable.Empty<LSPDocumentManagerChangeTrigger>();
var joinableTaskContext = new JoinableTaskContextNode(new JoinableTaskContext());
JoinableTaskContext = joinableTaskContext.Context;
JoinableTaskContext = new JoinableTaskContext();
TextBuffer = Mock.Of<ITextBuffer>();
Uri = new Uri("C:/path/to/file.razor");
UriProvider = Mock.Of<FileUriProvider>(provider => provider.GetOrCreate(TextBuffer) == Uri);

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

@ -129,7 +129,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
var synchronizer = new DefaultLSPDocumentSynchronizer(fileUriProvider);
synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
NotifyLSPDocumentAdded(lspDocument, synchronizer);
var cts = new CancellationTokenSource();
using var cts = new CancellationTokenSource();
// Act
@ -199,4 +199,4 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
edit.Apply();
}
}
}
}

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

@ -25,7 +25,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
var snapshot = Mock.Of<ITextSnapshot>(s => s.Version == Mock.Of<ITextVersion>());
var textBuffer = Mock.Of<ITextBuffer>(buffer => buffer.CurrentSnapshot == snapshot);
var virtualDocument = new TestVirtualDocument();
var document = new DefaultLSPDocument(Uri, textBuffer, new[] { virtualDocument });
using var document = new DefaultLSPDocument(Uri, textBuffer, new[] { virtualDocument });
var changes = Array.Empty<ITextChange>();
var originalSnapshot = document.CurrentSnapshot;

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

@ -22,7 +22,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
public void TryGetVirtualDocument_NoCSharpDocument_ReturnsFalse()
{
// Arrange
var lspDocument = new DefaultLSPDocument(Uri, Mock.Of<ITextBuffer>(), new[] { Mock.Of<VirtualDocument>() });
using var lspDocument = new DefaultLSPDocument(Uri, Mock.Of<ITextBuffer>(), new[] { Mock.Of<VirtualDocument>() });
// Act
var result = lspDocument.TryGetVirtualDocument<TestVirtualDocument>(out var virtualDocument);
@ -37,7 +37,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
{
// Arrange
var testVirtualDocument = new TestVirtualDocument(Uri, Mock.Of<ITextBuffer>());
var lspDocument = new DefaultLSPDocument(Uri, Mock.Of<ITextBuffer>(), new[] { Mock.Of<VirtualDocument>(), testVirtualDocument });
using var lspDocument = new DefaultLSPDocument(Uri, Mock.Of<ITextBuffer>(), new[] { Mock.Of<VirtualDocument>(), testVirtualDocument });
// Act
var result = lspDocument.TryGetVirtualDocument<TestVirtualDocument>(out var virtualDocument);
@ -47,4 +47,4 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
Assert.Same(testVirtualDocument, virtualDocument);
}
}
}
}

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

@ -11,7 +11,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(Tooling_MicrosoftCodeAnalysisAnalyzersPackageVersion)" NoWarn="NU1608" />
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
</ItemGroup>

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

@ -19,7 +19,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
{
// Arrange
var textBuffer = new TestTextBuffer(StringTextSnapshot.Empty);
var document = new TestVirtualDocument(Uri, textBuffer);
using var document = new TestVirtualDocument(Uri, textBuffer);
var originalSnapshot = document.CurrentSnapshot;
// Act
@ -36,7 +36,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
// Arrange
var insert = new VisualStudioTextChange(0, 0, "inserted text");
var textBuffer = new TestTextBuffer(StringTextSnapshot.Empty);
var document = new TestVirtualDocument(Uri, textBuffer);
using var document = new TestVirtualDocument(Uri, textBuffer);
// Act
document.Update(new[] { insert }, hostDocumentVersion: 1);
@ -52,7 +52,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
// Arrange
var textBuffer = new TestTextBuffer(new StringTextSnapshot("original"));
var replace = new VisualStudioTextChange(0, textBuffer.CurrentSnapshot.Length, "replaced text");
var document = new TestVirtualDocument(Uri, textBuffer);
using var document = new TestVirtualDocument(Uri, textBuffer);
// Act
document.Update(new[] { replace }, hostDocumentVersion: 1);
@ -68,7 +68,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
// Arrange
var textBuffer = new TestTextBuffer(new StringTextSnapshot("Hello World"));
var delete = new VisualStudioTextChange(6, 5, string.Empty);
var document = new TestVirtualDocument(Uri, textBuffer);
using var document = new TestVirtualDocument(Uri, textBuffer);
// Act
document.Update(new[] { delete }, hostDocumentVersion: 1);
@ -85,7 +85,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
var textBuffer = new TestTextBuffer(new StringTextSnapshot("Hello World"));
var replace = new VisualStudioTextChange(6, 5, "Replaced");
var delete = new VisualStudioTextChange(0, 6, string.Empty);
var document = new TestVirtualDocument(Uri, textBuffer);
using var document = new TestVirtualDocument(Uri, textBuffer);
// Act
document.Update(new[] { replace, delete }, hostDocumentVersion: 1);
@ -109,7 +109,7 @@ namespace Microsoft.VisualStudio.LanguageServer.ContainedLanguage
called += 1;
};
var document = new TestVirtualDocument(Uri, textBuffer);
using var document = new TestVirtualDocument(Uri, textBuffer);
// Act
document.Update(Array.Empty<ITextChange>(), hostDocumentVersion: 1);

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше