// Completing 'DateTime' in intellisense with a '.' could result in: '@DateT' -> '@DateT.' -> '@DateTime.' which is accepted. private static bool IsNewDotlessCommitInsertion(SyntaxNode target, SourceChange change) { return(!IsAtEndOfSpan(target, change) && change.Span.AbsoluteIndex > 0 && change.NewText.Length > 0 && target.GetContent().Last() == '.' && ParserHelpers.IsIdentifier(change.NewText, requireIdentifierStart: false) && (change.Span.Length == 0 || ParserHelpers.IsIdentifier(change.GetOriginalText(target), requireIdentifierStart: false))); }
public void GetOrigninalText_SpanIsOwner_ReturnsContent_ZeroLengthSpan() { // Arrange var builder = SyntaxListBuilder <SyntaxToken> .Create(); builder.Add(SyntaxFactory.Token(SyntaxKind.Marker, "Hello, ")); builder.Add(SyntaxFactory.Token(SyntaxKind.Marker, "World")); var node = SyntaxFactory.MarkupTextLiteral(builder.ToList()).CreateRed(null, 13); var change = new SourceChange(15, 0, "heyo"); // Act var result = change.GetOriginalText(node); // Act Assert.Equal(string.Empty, result); }
protected override PartialParseResultInternal CanAcceptChange(SyntaxNode target, SourceChange change) { if (AcceptedCharacters == AcceptedCharactersInternal.NonWhitespace) { var originalText = change.GetOriginalText(target); var editedContent = change.GetEditedContent(target); if (!ContainsWhitespace(originalText) && !ContainsWhitespace(editedContent)) { // Did not modify whitespace, directive format should be the same. // Return provisional so extensible IR/code gen pieces can see the full directive text // once the user stops editing the document. return(PartialParseResultInternal.Accepted | PartialParseResultInternal.Provisional); } } return(PartialParseResultInternal.Rejected); }
private PartialParseResultInternal HandleReplacement(Span target, SourceChange change) { // Special Case for IntelliSense commits. // When IntelliSense commits, we get two changes (for example user typed "Date", then committed "DateTime" by pressing ".") // 1. Insert "." at the end of this span // 2. Replace the "Date." at the end of the span with "DateTime." // We need partial parsing to accept case #2. var oldText = change.GetOriginalText(target); var result = PartialParseResultInternal.Rejected; if (EndsWithDot(oldText) && EndsWithDot(change.NewText)) { result = PartialParseResultInternal.Accepted; if (!AcceptTrailingDot) { result |= PartialParseResultInternal.Provisional; } } return(result); }