Change product code to work with editor expectations.
- Descriptor providers should not be pushing `null` descriptors into the overall list of `TagHelperDescriptor`s; this causes null refs on the editor side of things at design time. - Expose `FilePath` on `RazorEditorParser` for the editor. The editor currenlty uses the `RazorEditorParser` as a place to hold some state about the Razor document.
This commit is contained in:
parent
8fac9141d8
commit
006b4651da
|
|
@ -55,7 +55,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||||
var factory = new ViewComponentTagHelperDescriptorFactory(compilation);
|
var factory = new ViewComponentTagHelperDescriptorFactory(compilation);
|
||||||
for (var i = 0; i < types.Count; i++)
|
for (var i = 0; i < types.Count; i++)
|
||||||
{
|
{
|
||||||
context.Results.Add(factory.CreateDescriptor(types[i]));
|
var descriptor = factory.CreateDescriptor(types[i]);
|
||||||
|
|
||||||
|
if (descriptor != null)
|
||||||
|
{
|
||||||
|
context.Results.Add(descriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,11 @@ namespace Microsoft.CodeAnalysis.Razor
|
||||||
for (var i = 0; i < types.Count; i++)
|
for (var i = 0; i < types.Count; i++)
|
||||||
{
|
{
|
||||||
var descriptor = factory.CreateDescriptor(types[i]);
|
var descriptor = factory.CreateDescriptor(types[i]);
|
||||||
context.Results.Add(descriptor);
|
|
||||||
|
if (descriptor != null)
|
||||||
|
{
|
||||||
|
context.Results.Add(descriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateEngine = templateEngine;
|
TemplateEngine = templateEngine;
|
||||||
|
FilePath = filePath;
|
||||||
_parser = new BackgroundParser(templateEngine, filePath);
|
_parser = new BackgroundParser(templateEngine, filePath);
|
||||||
_parser.ResultsReady += (sender, args) => OnDocumentParseComplete(args);
|
_parser.ResultsReady += (sender, args) => OnDocumentParseComplete(args);
|
||||||
_parser.Start();
|
_parser.Start();
|
||||||
|
|
@ -42,6 +43,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
|
||||||
|
|
||||||
public RazorTemplateEngine TemplateEngine { get; }
|
public RazorTemplateEngine TemplateEngine { get; }
|
||||||
|
|
||||||
|
public string FilePath { get; }
|
||||||
|
|
||||||
// Internal for testing.
|
// Internal for testing.
|
||||||
internal RazorSyntaxTree CurrentSyntaxTree { get; private set; }
|
internal RazorSyntaxTree CurrentSyntaxTree { get; private set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
// 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.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.AspNetCore.Razor.Language;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.CodeAnalysis.Razor
|
||||||
|
{
|
||||||
|
public class DefaultTagHelperDescriptorProviderTest
|
||||||
|
{
|
||||||
|
private static readonly Assembly _assembly = typeof(DefaultTagHelperDescriptorProviderTest).GetTypeInfo().Assembly;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Execute_DoesNotAddEditorBrowsableNeverDescriptorsAtDesignTime()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var editorBrowsableTypeName = "Microsoft.CodeAnalysis.Razor.Workspaces.Test.EditorBrowsableTagHelper";
|
||||||
|
var compilation = TestCompilation.Create(_assembly);
|
||||||
|
var descriptorProvider = new DefaultTagHelperDescriptorProvider()
|
||||||
|
{
|
||||||
|
DesignTime = true,
|
||||||
|
};
|
||||||
|
var context = TagHelperDescriptorProviderContext.Create();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
descriptorProvider.Execute(context);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(compilation.GetTypeByMetadataName(editorBrowsableTypeName));
|
||||||
|
var nullDescriptors = context.Results.Where(descriptor => descriptor == null);
|
||||||
|
Assert.Empty(nullDescriptors);
|
||||||
|
var editorBrowsableDescriptor = context.Results.Where(descriptor => descriptor.GetTypeName() == editorBrowsableTypeName);
|
||||||
|
Assert.Empty(editorBrowsableDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue