Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit ff1c073

Browse files
committed
Rewrite partial parsing logic
1 parent f32e82f commit ff1c073

File tree

114 files changed

+1804
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1804
-464
lines changed

src/Microsoft.AspNetCore.Razor.Language/ClassifiedSpanVisitor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics;
76
using Microsoft.AspNetCore.Razor.Language.Legacy;
87
using Microsoft.AspNetCore.Razor.Language.Syntax;
98

src/Microsoft.AspNetCore.Razor.Language/DirectiveTokenEditHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
using System;
55
using System.Collections.Generic;
66
using Microsoft.AspNetCore.Razor.Language.Legacy;
7-
using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
7+
using Microsoft.AspNetCore.Razor.Language.Syntax;
88

99
namespace Microsoft.AspNetCore.Razor.Language
1010
{
1111
internal class DirectiveTokenEditHandler : SpanEditHandler
1212
{
13-
public DirectiveTokenEditHandler(Func<string, IEnumerable<SyntaxToken>> tokenizer) : base(tokenizer)
13+
public DirectiveTokenEditHandler(Func<string, IEnumerable<Syntax.InternalSyntax.SyntaxToken>> tokenizer) : base(tokenizer)
1414
{
1515
}
1616

17-
protected override PartialParseResultInternal CanAcceptChange(Span target, SourceChange change)
17+
protected override PartialParseResultInternal CanAcceptChange(SyntaxNode target, SourceChange change)
1818
{
1919
if (AcceptedCharacters == AcceptedCharactersInternal.NonWhitespace)
2020
{
@@ -31,7 +31,6 @@ protected override PartialParseResultInternal CanAcceptChange(Span target, Sourc
3131
}
3232

3333
return PartialParseResultInternal.Rejected;
34-
3534
}
3635

3736
private static bool ContainsWhitespace(string content)

src/Microsoft.AspNetCore.Razor.Language/Legacy/AutoCompleteEditHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
6+
using Microsoft.AspNetCore.Razor.Language.Syntax;
77
using Microsoft.Extensions.Internal;
88

99
namespace Microsoft.AspNetCore.Razor.Language.Legacy
@@ -12,18 +12,18 @@ internal class AutoCompleteEditHandler : SpanEditHandler
1212
{
1313
private static readonly int TypeHashCode = typeof(AutoCompleteEditHandler).GetHashCode();
1414

15-
public AutoCompleteEditHandler(Func<string, IEnumerable<SyntaxToken>> tokenizer)
15+
public AutoCompleteEditHandler(Func<string, IEnumerable<Syntax.InternalSyntax.SyntaxToken>> tokenizer)
1616
: base(tokenizer)
1717
{
1818
}
1919

20-
public AutoCompleteEditHandler(Func<string, IEnumerable<SyntaxToken>> tokenizer, bool autoCompleteAtEndOfSpan)
20+
public AutoCompleteEditHandler(Func<string, IEnumerable<Syntax.InternalSyntax.SyntaxToken>> tokenizer, bool autoCompleteAtEndOfSpan)
2121
: this(tokenizer)
2222
{
2323
AutoCompleteAtEndOfSpan = autoCompleteAtEndOfSpan;
2424
}
2525

26-
public AutoCompleteEditHandler(Func<string, IEnumerable<SyntaxToken>> tokenizer, AcceptedCharactersInternal accepted)
26+
public AutoCompleteEditHandler(Func<string, IEnumerable<Syntax.InternalSyntax.SyntaxToken>> tokenizer, AcceptedCharactersInternal accepted)
2727
: base(tokenizer, accepted)
2828
{
2929
}
@@ -32,7 +32,7 @@ public AutoCompleteEditHandler(Func<string, IEnumerable<SyntaxToken>> tokenizer,
3232

3333
public string AutoCompleteString { get; set; }
3434

35-
protected override PartialParseResultInternal CanAcceptChange(Span target, SourceChange change)
35+
protected override PartialParseResultInternal CanAcceptChange(SyntaxNode target, SourceChange change)
3636
{
3737
if (((AutoCompleteAtEndOfSpan && IsAtEndOfSpan(target, change)) || IsAtEndOfFirstLine(target, change)) &&
3838
change.IsInsert &&

src/Microsoft.AspNetCore.Razor.Language/Legacy/CodeBlockEditHandler.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Globalization;
7-
using Microsoft.AspNetCore.Razor.Language.Syntax.InternalSyntax;
7+
using Microsoft.AspNetCore.Razor.Language.Syntax;
88

99
namespace Microsoft.AspNetCore.Razor.Language.Legacy
1010
{
1111
internal class CodeBlockEditHandler : SpanEditHandler
1212
{
13-
public CodeBlockEditHandler(Func<string, IEnumerable<SyntaxToken>> tokenizer) : base(tokenizer)
13+
public CodeBlockEditHandler(Func<string, IEnumerable<Syntax.InternalSyntax.SyntaxToken>> tokenizer) : base(tokenizer)
1414
{
1515
}
1616

17-
protected override PartialParseResultInternal CanAcceptChange(Span target, SourceChange change)
17+
protected override PartialParseResultInternal CanAcceptChange(SyntaxNode target, SourceChange change)
1818
{
1919
if (IsAcceptableDeletion(target, change))
2020
{
@@ -35,7 +35,7 @@ protected override PartialParseResultInternal CanAcceptChange(Span target, Sourc
3535
}
3636

3737
// Internal for testing
38-
internal static bool IsAcceptableReplacement(Span target, SourceChange change)
38+
internal static bool IsAcceptableReplacement(SyntaxNode target, SourceChange change)
3939
{
4040
if (!change.IsReplace)
4141
{
@@ -56,7 +56,7 @@ internal static bool IsAcceptableReplacement(Span target, SourceChange change)
5656
}
5757

5858
// Internal for testing
59-
internal static bool IsAcceptableDeletion(Span target, SourceChange change)
59+
internal static bool IsAcceptableDeletion(SyntaxNode target, SourceChange change)
6060
{
6161
if (!change.IsDelete)
6262
{
@@ -72,11 +72,11 @@ internal static bool IsAcceptableDeletion(Span target, SourceChange change)
7272
}
7373

7474
// Internal for testing
75-
internal static bool ModifiesInvalidContent(Span target, SourceChange change)
75+
internal static bool ModifiesInvalidContent(SyntaxNode target, SourceChange change)
7676
{
77-
var relativePosition = change.Span.AbsoluteIndex - target.Start.AbsoluteIndex;
77+
var relativePosition = change.Span.AbsoluteIndex - target.Position;
7878

79-
if (target.Content.IndexOfAny(new[] { '{', '}' }, relativePosition, change.Span.Length) >= 0)
79+
if (target.GetContent().IndexOfAny(new[] { '{', '}' }, relativePosition, change.Span.Length) >= 0)
8080
{
8181
return true;
8282
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.AspNetCore.Razor.Language.Syntax;
5+
46
namespace Microsoft.AspNetCore.Razor.Language.Legacy
57
{
68
internal class EditResult
79
{
10+
public EditResult(PartialParseResultInternal result, SyntaxNode editedNode)
11+
{
12+
Result = result;
13+
EditedNode = editedNode;
14+
}
15+
816
public EditResult(PartialParseResultInternal result, SpanBuilder editedSpan)
917
{
1018
Result = result;
1119
EditedSpan = editedSpan;
1220
}
1321

1422
public PartialParseResultInternal Result { get; set; }
23+
public SyntaxNode EditedNode { get; set; }
1524
public SpanBuilder EditedSpan { get; set; }
1625
}
1726
}

0 commit comments

Comments
 (0)