Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add component source mapping #9672

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public abstract class CodeRenderingContext : IDisposable

public abstract void AddSourceMappingFor(SourceSpan node);

public abstract void AddGeneratedOnlyMapping(int length);

public abstract void RenderNode(IntermediateNode node);

public abstract void RenderNode(IntermediateNode node, IntermediateNodeWriter writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ public static CSharpCodeWritingScope BuildClassDeclaration(
}

writer.Write("class ");
context?.AddGeneratedOnlyMapping(name.Length);
writer.Write(name);

if (typeParameters != null && typeParameters.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class DefaultCodeRenderingContext : CodeRenderingContext
private readonly List<ScopeInternal> _scopes;

private readonly PooledObject<ImmutableArray<SourceMapping>.Builder> _sourceMappingsBuilder;
private readonly PooledObject<ImmutableArray<SourceSpan>.Builder> _generatedOnlyMappingsBuilder;

public DefaultCodeRenderingContext(
CodeWriter codeWriter,
Expand Down Expand Up @@ -61,6 +62,7 @@ public DefaultCodeRenderingContext(
Diagnostics = new RazorDiagnosticCollection();
Items = new ItemCollection();
_sourceMappingsBuilder = ArrayBuilderPool<SourceMapping>.GetPooledObject();
_generatedOnlyMappingsBuilder = ArrayBuilderPool<SourceSpan>.GetPooledObject();
LinePragmas = new List<LinePragma>();

var diagnostics = _documentNode.GetAllDiagnostics();
Expand Down Expand Up @@ -100,6 +102,8 @@ public DefaultCodeRenderingContext(

public ImmutableArray<SourceMapping>.Builder SourceMappings => _sourceMappingsBuilder.Object;

public ImmutableArray<SourceSpan>.Builder GeneratedOnlyMappings => _generatedOnlyMappingsBuilder.Object;

internal List<LinePragma> LinePragmas { get; }

public override IntermediateNodeWriter NodeWriter => Current.Writer;
Expand Down Expand Up @@ -142,6 +146,11 @@ public override void AddSourceMappingFor(SourceSpan source)
SourceMappings.Add(sourceMapping);
}

public override void AddGeneratedOnlyMapping(int length)
{
GeneratedOnlyMappings.Add(new SourceSpan(CodeWriter.Location, length));
}

public override void RenderChildren(IntermediateNode node)
{
if (node == null)
Expand Down Expand Up @@ -220,6 +229,7 @@ public override void AddLinePragma(LinePragma linePragma)
public override void Dispose()
{
_sourceMappingsBuilder.Dispose();
_generatedOnlyMappingsBuilder.Dispose();
}

private struct ScopeInternal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public override RazorCSharpDocument WriteDocument(RazorCodeDocument codeDocument
_options,
allOrderedDiagnostics.ToArray(),
context.SourceMappings.DrainToImmutable(),
context.GeneratedOnlyMappings.DrainToImmutable(),
context.LinePragmas.ToArray());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal class DefaultRazorCSharpDocument : RazorCSharpDocument
private readonly string _generatedCode;
private readonly RazorDiagnostic[] _diagnostics;
private readonly ImmutableArray<SourceMapping> _sourceMappings;
private readonly ImmutableArray<SourceSpan> _generatedOnlyMappings;
private readonly LinePragma[] _linePragmas;
private readonly RazorCodeGenerationOptions _options;
private readonly RazorCodeDocument _codeDocument;
Expand All @@ -25,6 +26,7 @@ public DefaultRazorCSharpDocument(
RazorCodeGenerationOptions options,
RazorDiagnostic[] diagnostics,
ImmutableArray<SourceMapping> sourceMappings,
ImmutableArray<SourceSpan> generatedOnlyMappings,
LinePragma[] linePragmas)
{
if (generatedCode == null)
Expand All @@ -43,6 +45,7 @@ public DefaultRazorCSharpDocument(

_diagnostics = diagnostics ?? Array.Empty<RazorDiagnostic>();
_sourceMappings = sourceMappings;
_generatedOnlyMappings = generatedOnlyMappings;
_linePragmas = linePragmas ?? Array.Empty<LinePragma>();
}

Expand All @@ -52,6 +55,8 @@ public DefaultRazorCSharpDocument(

public override ImmutableArray<SourceMapping> SourceMappings => _sourceMappings;

public override ImmutableArray<SourceSpan> GeneratedOnlyMappings => _generatedOnlyMappings;

internal override IReadOnlyList<LinePragma> LinePragmas => _linePragmas;

public override RazorCodeGenerationOptions Options => _options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ internal interface IRazorGeneratedDocument
string GeneratedCode { get; }
RazorCodeGenerationOptions Options { get; }
ImmutableArray<SourceMapping> SourceMappings { get; }
ImmutableArray<SourceSpan> GeneratedOnlyMappings { get; }
RazorCodeDocument? CodeDocument { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*REMOVED*~Microsoft.AspNetCore.Razor.Language.TagHelperDescriptor.TagMatchingRules.get -> System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Razor.Language.TagMatchingRuleDescriptor>
*REMOVED*~Microsoft.AspNetCore.Razor.Language.TagMatchingRuleDescriptor.Attributes.get -> System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Razor.Language.RequiredAttributeDescriptor>
*REMOVED*~virtual Microsoft.AspNetCore.Razor.Language.BoundAttributeDescriptor.BoundAttributeParameters.get -> System.Collections.Generic.IReadOnlyList<Microsoft.AspNetCore.Razor.Language.BoundAttributeParameterDescriptor>
abstract Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeRenderingContext.AddGeneratedOnlyMapping(int length) -> void
abstract Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeRenderingContext.AddSourceMappingFor(Microsoft.AspNetCore.Razor.Language.SourceSpan node) -> void
abstract Microsoft.AspNetCore.Razor.Language.CodeGeneration.CodeRenderingContext.Dispose() -> void
abstract Microsoft.AspNetCore.Razor.Language.MetadataCollection.ContainsKey(string! key) -> bool
Expand All @@ -17,6 +18,7 @@ abstract Microsoft.AspNetCore.Razor.Language.MetadataCollection.Keys.get -> Syst
abstract Microsoft.AspNetCore.Razor.Language.MetadataCollection.this[string! key].get -> string?
abstract Microsoft.AspNetCore.Razor.Language.MetadataCollection.TryGetValue(string! key, out string? value) -> bool
abstract Microsoft.AspNetCore.Razor.Language.MetadataCollection.Values.get -> System.Collections.Generic.IEnumerable<string?>!
abstract Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument.GeneratedOnlyMappings.get -> System.Collections.Immutable.ImmutableArray<Microsoft.AspNetCore.Razor.Language.SourceSpan>
abstract Microsoft.AspNetCore.Razor.Language.RazorSourceDocumentProperties.FilePath.get -> string?
abstract Microsoft.AspNetCore.Razor.Language.RazorSourceDocumentProperties.RelativePath.get -> string?
abstract Microsoft.AspNetCore.Razor.Language.TagHelperCollector<T>.Collect(Microsoft.CodeAnalysis.ISymbol! symbol, System.Collections.Generic.ICollection<Microsoft.AspNetCore.Razor.Language.TagHelperDescriptor!>! results) -> void
Expand Down Expand Up @@ -365,7 +367,7 @@ virtual Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.OnInitialized()
~static Microsoft.AspNetCore.Razor.Language.RazorCodeDocumentExtensions.SetImportSyntaxTrees(this Microsoft.AspNetCore.Razor.Language.RazorCodeDocument document, System.Collections.Immutable.ImmutableArray<Microsoft.AspNetCore.Razor.Language.RazorSyntaxTree> syntaxTrees) -> void
~static Microsoft.AspNetCore.Razor.Language.RazorCodeDocumentExtensions.SetPreTagHelperSyntaxTree(this Microsoft.AspNetCore.Razor.Language.RazorCodeDocument document, Microsoft.AspNetCore.Razor.Language.RazorSyntaxTree syntaxTree) -> void
~static Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument.Create(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, string generatedCode, Microsoft.AspNetCore.Razor.Language.RazorCodeGenerationOptions options, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.RazorDiagnostic> diagnostics) -> Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument
~static Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument.Create(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, string generatedCode, Microsoft.AspNetCore.Razor.Language.RazorCodeGenerationOptions options, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.RazorDiagnostic> diagnostics, System.Collections.Immutable.ImmutableArray<Microsoft.AspNetCore.Razor.Language.SourceMapping> sourceMappings, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.CodeGeneration.LinePragma> linePragmas) -> Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument
~static Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument.Create(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, string generatedCode, Microsoft.AspNetCore.Razor.Language.RazorCodeGenerationOptions options, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.RazorDiagnostic> diagnostics, System.Collections.Immutable.ImmutableArray<Microsoft.AspNetCore.Razor.Language.SourceMapping> sourceMappings, System.Collections.Immutable.ImmutableArray<Microsoft.AspNetCore.Razor.Language.SourceSpan> generatedOnlyMappings, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.CodeGeneration.LinePragma> linePragmas) -> Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument
~static Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument.Create(string generatedCode, Microsoft.AspNetCore.Razor.Language.RazorCodeGenerationOptions options, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.RazorDiagnostic> diagnostics, System.Collections.Immutable.ImmutableArray<Microsoft.AspNetCore.Razor.Language.SourceMapping> sourceMappings, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.CodeGeneration.LinePragma> linePragmas) -> Microsoft.AspNetCore.Razor.Language.RazorCSharpDocument
~static Microsoft.AspNetCore.Razor.Language.TagHelperDescriptorBuilderExtensions.SetMetadata(this Microsoft.AspNetCore.Razor.Language.TagHelperDescriptorBuilder builder, System.Collections.Generic.KeyValuePair<string, string> pair) -> void
~static Microsoft.AspNetCore.Razor.Language.TagHelperDescriptorBuilderExtensions.SetMetadata(this Microsoft.AspNetCore.Razor.Language.TagHelperDescriptorBuilder builder, System.Collections.Generic.KeyValuePair<string, string> pair1, System.Collections.Generic.KeyValuePair<string, string> pair2) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public abstract class RazorCSharpDocument : IRazorGeneratedDocument

public abstract ImmutableArray<SourceMapping> SourceMappings { get; }

/// <summary>
/// Maps spans from the generated source to the whole component.
/// </summary>
/// <remarks>
/// Used to map the component class name, so go-to-definition navigates to the .razor file.
/// </remarks>
public abstract ImmutableArray<SourceSpan> GeneratedOnlyMappings { get; }

public abstract IReadOnlyList<RazorDiagnostic> Diagnostics { get; }

public abstract RazorCodeGenerationOptions Options { get; }
Expand All @@ -31,7 +39,7 @@ public static RazorCSharpDocument Create(string generatedCode, RazorCodeGenerati

[Obsolete("For backwards compatibility only. Use the overload that takes a RazorCodeDocument")]
public static RazorCSharpDocument Create(string generatedCode, RazorCodeGenerationOptions options, IEnumerable<RazorDiagnostic> diagnostics, ImmutableArray<SourceMapping> sourceMappings, IEnumerable<LinePragma> linePragmas)
=> Create(codeDocument: null, generatedCode, options, diagnostics, sourceMappings, linePragmas);
=> Create(codeDocument: null, generatedCode, options, diagnostics, sourceMappings, ImmutableArray<SourceSpan>.Empty, linePragmas);

public static RazorCSharpDocument Create(RazorCodeDocument codeDocument, string generatedCode, RazorCodeGenerationOptions options, IEnumerable<RazorDiagnostic> diagnostics)
{
Expand All @@ -50,7 +58,7 @@ public static RazorCSharpDocument Create(RazorCodeDocument codeDocument, string
throw new ArgumentNullException(nameof(diagnostics));
}

return new DefaultRazorCSharpDocument(codeDocument, generatedCode, options, diagnostics.ToArray(), sourceMappings: ImmutableArray<SourceMapping>.Empty, linePragmas: null);
return new DefaultRazorCSharpDocument(codeDocument, generatedCode, options, diagnostics.ToArray(), sourceMappings: ImmutableArray<SourceMapping>.Empty, generatedOnlyMappings: ImmutableArray<SourceSpan>.Empty, linePragmas: null);
}

public static RazorCSharpDocument Create(
Expand All @@ -59,6 +67,7 @@ public static RazorCSharpDocument Create(
RazorCodeGenerationOptions options,
IEnumerable<RazorDiagnostic> diagnostics,
ImmutableArray<SourceMapping> sourceMappings,
ImmutableArray<SourceSpan> generatedOnlyMappings,
IEnumerable<LinePragma> linePragmas)
{
if (generatedCode == null)
Expand All @@ -76,6 +85,6 @@ public static RazorCSharpDocument Create(
throw new ArgumentNullException(nameof(diagnostics));
}

return new DefaultRazorCSharpDocument(codeDocument, generatedCode, options, diagnostics.ToArray(), sourceMappings, linePragmas.ToArray());
return new DefaultRazorCSharpDocument(codeDocument, generatedCode, options, diagnostics.ToArray(), sourceMappings, generatedOnlyMappings, linePragmas.ToArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal abstract class RazorHtmlDocument : IRazorGeneratedDocument

public abstract ImmutableArray<SourceMapping> SourceMappings { get; }

public ImmutableArray<SourceSpan> GeneratedOnlyMappings => ImmutableArray<SourceSpan>.Empty;

public abstract RazorCodeDocument CodeDocument { get; }

public static RazorHtmlDocument Create(RazorCodeDocument codeDocument, string generatedHtml, RazorCodeGenerationOptions options, ImmutableArray<SourceMapping> sourceMappings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void Setup()
RazorCodeGenerationOptions.CreateDesignTimeDefault(),
Array.Empty<RazorDiagnostic>(),
SourceMappings,
ImmutableArray<SourceSpan>.Empty,
new List<LinePragma>()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ public bool TryMapToHostDocumentPosition(IRazorGeneratedDocument generatedDocume
return true;
}

foreach (var mapping in generatedDocument.GeneratedOnlyMappings)
{
var generatedAbsoluteIndex = mapping.AbsoluteIndex;
var distanceIntoGeneratedSpan = generatedDocumentIndex - generatedAbsoluteIndex;
if (generatedAbsoluteIndex <= generatedDocumentIndex &&
distanceIntoGeneratedSpan <= mapping.Length)
{
hostDocumentIndex = 0;
hostDocumentPosition = new LinePosition(0, 0);
return true;
}
}

hostDocumentPosition = default;
hostDocumentIndex = default;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,14 @@ private async Task AddCSharpSpellCheckRangesAsync(List<SpellCheckRange> ranges,

// We need to map the start index to produce results, and we validate that we can map the end index so we don't have
// squiggles that go from C# into Razor/Html.
if (_documentMappingService.TryMapToHostDocumentPosition(csharpDocument, absoluteCSharpStartIndex, out var _1, out var hostDocumentIndex) &&
_documentMappingService.TryMapToHostDocumentPosition(csharpDocument, absoluteCSharpStartIndex + length, out var _2, out var _3))
if (_documentMappingService.TryMapToHostDocumentPosition(csharpDocument, absoluteCSharpStartIndex, out var _1, out var hostDocumentStartIndex) &&
_documentMappingService.TryMapToHostDocumentPosition(csharpDocument, absoluteCSharpStartIndex + length, out var _2, out var hostDocumentEndIndex))
{
ranges.Add(new(kind, hostDocumentIndex, length));
var mappedLength = hostDocumentEndIndex - hostDocumentStartIndex;
if (mappedLength > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me a little nervous, as it would be surprising if spell check was the only endpoint that needed special handling of 0-length spans. eg does renaming a component error? Are there any diagnostics that could be reported on the typename, and therefore does the diagnostics endpoints have to be updated?

Copy link
Member Author

@jjonescz jjonescz Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what renaming a component should do even today (like renaming a file in VS doesn't update component type references even without this PR), but it doesn't error with this PR. Although it's probably slightly broken since in some cases (renaming type reference from C#), the .razor is updated to contain the new name at the beginning of the file. Do you know where that should be fixed?

Diagnostics on the typename (e.g., when deriving from a static class) seem to be reported just fine on the first character of the razor file (even if the file is completely empty).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maryamariyan has good insight onto what renaming behavior is/should be

Copy link
Contributor

@davidwengier davidwengier Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For rename initiated from a Razor file, things would go through document mapping service, and we could add a bool flag for whether we want to consider generated only mappings. Could pass in false for that in spell check too, etc.

The problem is renames initiated in C# code, which are handled entirely in Roslyn using the SpanMappingService to change where edits occur. The problem there is that sometimes we want that service to consider generated only spans, eg in Go To Def and Go To All search results, but sometimes we don't, like rename. Sadly the current API doesn't let us know what operation is happening.

Maybe we just leave it like this and see if anyone complains? We could, presumably on the tooling side, follow up with an API change in Roslyn perhaps, to add a flag to the span mapping service to indicate if the operation is going to perform an edit, or is just data retrieval.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we just leave it like this and see if anyone complains?

I don't know, I would be inclined not to break the experience like this, but it seems like a tooling's call :D

We could, presumably on the tooling side, follow up with an API change in Roslyn perhaps, to add a flag to the span mapping service to indicate if the operation is going to perform an edit, or is just data retrieval.

The alternative is I guess to first do the API change and only then merge this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled down the branch and gave this a try, and Go To Def from a Razor file works, Go To Def from a C# file works, but then shows an error (Roslyn issue we can file once this is in), and All-In-One search navigation works, but the filename still shows the generated file:
image

The latter is presumably because there is no #line. Would it be a problem to add that in future?

All-in-all, from my testing, this PR doesn't make anything worse, and does fix a couple of gaps, so I have no problem with it going in. There might be oddities going on with rename making edits that then get overwritten or something, but it doesn't surface as any user facing problems, so its okay by me!

Copy link
Member Author

@jjonescz jjonescz Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go To Def from a C# file works, but then shows an error (Roslyn issue we can file once this is in)

This is reproducible even in main, so probably an orthogonal issue. It happens when you go to def from C# to a def of a C# class that's defined in razor (like a nested class, e.g., @code { public class MyNestedClass { } } that you can reference from a C# like _ = new MyComponent.MyNestedClass();).

The latter is presumably because there is no #line. Would it be a problem to add that in future?

I will look into that, thanks.

There might be oddities going on with rename making edits that then get overwritten or something, but it doesn't surface as any user facing problems, so its okay by me!

I'm not sure if you've seen this:

  1. Have a component Test1.razor referenced from another, e.g., <LayoutView Layout="@(typeof(Test1))" />.
  2. Hit F2 on the Test1 reference in the typeof.
  3. Rename to something else, e.g., Example.
  4. Inside Test1.razor, the word Example is written
    • Obviously, the component wasn't even renamed, since the filename stayed the same.
    • Plus, bogus text was written inside the razor file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, yeah. I didn't notice that because I was just renaming SurveyPrompt to SurveyPrompt1, and didn't notice that that had caused a 1 to be added to the start of the document. That's not good.

From a quick look, my suggestion for adding an element of why a span is being asked for won't work either, as it looks like Rename just uses Find All Refs to get refs to rename.

{
ranges.Add(new(kind, hostDocumentStartIndex, mappedLength));
}
}

absoluteCSharpStartIndex += length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ internal static bool TryGetMappedSpans(TextSpan span, SourceText source, RazorCS
}
}

foreach (var mapping in output.GeneratedOnlyMappings)
{
var generated = mapping.AsTextSpan();

if (generated.Contains(span))
{
mappedSpan = new TextSpan(0, 0);
linePositionSpan = new LinePositionSpan(new LinePosition(0, 0), new LinePosition(0, 0));
return true;
}
}

mappedSpan = default;
linePositionSpan = default;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ private static RazorCodeDocument CreateCodeDocumentWithCSharpProjection(
RazorCodeGenerationOptions.CreateDefault(),
Enumerable.Empty<RazorDiagnostic>(),
sourceMappings.ToImmutableArray(),
ImmutableArray<SourceSpan>.Empty,
Enumerable.Empty<LinePragma>());
codeDocument.SetCSharpDocument(csharpDocument);
return codeDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DocumentSymbolEndpointTest(ITestOutputHelper testOutput) : SingleSe
public Task DocumentSymbols_CSharpMethods()
=> VerifyDocumentSymbolsAsync(
"""
@functions {
{|AspNetCore.test:|}@functions {
davidwengier marked this conversation as resolved.
Show resolved Hide resolved
private void {|HandleString(string s):HandleString|}(string s)
{
s += "Hello";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static RazorCodeDocument CreateCodeDocument(string content, IReadOnlyLi
var codeDocument = RazorCodeDocument.Create(sourceDocument);
var syntaxTree = RazorSyntaxTree.Parse(sourceDocument, RazorParserOptions.CreateDefault());
var razorCSharpDocument = RazorCSharpDocument.Create(
codeDocument, content, RazorCodeGenerationOptions.CreateDefault(), Array.Empty<RazorDiagnostic>(), sourceMappings.ToImmutableArray(), Array.Empty<LinePragma>());
codeDocument, content, RazorCodeGenerationOptions.CreateDefault(), Array.Empty<RazorDiagnostic>(), sourceMappings.ToImmutableArray(), ImmutableArray<SourceSpan>.Empty, Array.Empty<LinePragma>());
codeDocument.SetSyntaxTree(syntaxTree);
codeDocument.SetCSharpDocument(razorCSharpDocument);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private static RazorCodeDocument CreateCodeDocumentWithCSharpProjection(string r
RazorCodeGenerationOptions.CreateDefault(),
Enumerable.Empty<RazorDiagnostic>(),
sourceMappings.ToImmutableArray(),
ImmutableArray<SourceSpan>.Empty,
Enumerable.Empty<LinePragma>());
codeDocument.SetCSharpDocument(csharpDocument);
return codeDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ private static RazorCodeDocument CreateCodeDocumentWithCSharpProjection(string r
RazorCodeGenerationOptions.CreateDefault(),
Enumerable.Empty<RazorDiagnostic>(),
sourceMappings.ToImmutableArray(),
ImmutableArray<SourceSpan>.Empty,
Enumerable.Empty<LinePragma>());
codeDocument.SetCSharpDocument(csharpDocument);
return codeDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ private static RazorCodeDocument CreateCodeDocumentWithCSharpProjection(string r
RazorCodeGenerationOptions.CreateDefault(),
Enumerable.Empty<RazorDiagnostic>(),
sourceMappings.ToImmutableArray(),
ImmutableArray<SourceSpan>.Empty,
Enumerable.Empty<LinePragma>());
codeDocument.SetCSharpDocument(csharpDocument);
return codeDocument;
Expand Down
Loading