public void SetLoc(CodeSpan span) { start.line = span.startLine; start.column = span.startColumn; end.line = span.endLine; end.column = span.endColumn; }
private string GetString(TextElement[] texts) { StringBuilder builder = new StringBuilder(); foreach (TextElement i in texts) { if (i is TextSpan) { TextSpan s = (TextSpan)i; builder.Append(Escape(s.Text)); } else if (i is CodeSpan) { CodeSpan s = (CodeSpan)i; builder.Append(Escape(s.Text)); } else if (i is HyperlinkSpan) { HyperlinkSpan s = (HyperlinkSpan)i; builder.Append(Escape(s.Text)); } } return(builder.ToString()); }
protected CodeBlockInfo ParseBlockStart(bool isTopLevel, bool captureTransition) { // Capture the transition token, if any, into a span Span transitionSpan = null; if (HaveContent && captureTransition) { transitionSpan = TransitionSpan.Create(Context, hidden: false, acceptedCharacters: AcceptedCharacters.None); Context.ResetBuffers(); } SourceLocation start = CurrentLocation; string identifier = Context.AcceptIdentifier(); Span initialSpan = null; if (isTopLevel) { initialSpan = CodeSpan.Create(Context); Context.ResetBuffers(); } CodeBlockInfo block = new CodeBlockInfo(identifier, start, isTopLevel, transitionSpan, initialSpan); return(block); }
public override void AddError(string path, string message, string lineText, CodeSpan location, int errorCode, Severity severity) { // keep the error list under 100 items which is a reasonable number and avoids spending too much time on error processing if (Errors.Count < 100) { int startIndex, endIndex; if (location.StartLine > 0 && location.EndLine > 0) { // get the error bounds to create a span pointing to the error text so it can be navigated to later on by the Error List startIndex = textBuffer.CurrentSnapshot.GetLineFromLineNumber(location.StartLine - 1).Start.Position + location.StartColumn; endIndex = textBuffer.CurrentSnapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndColumn; if (startIndex < endIndex && endIndex < textBuffer.CurrentSnapshot.GetText().Length) { // add the error with all its necessary information Errors.Add(new ValidationError(new Span(startIndex, endIndex - startIndex), message, GetSeverity(severity), ValidationErrorType.Syntactic)); if (Errors.Count == 100) { // add a friendly error telling the user the maximum number of errors has been reached Errors.Add(new ValidationError(new Span(startIndex, endIndex - startIndex), "The maximum number of errors or warnings has been reached.")); } } } } }
public static Dictionary <MemberIdentifier, CodeSpan> GenerateMemberMapping(string assemblyFilePath, StringWriter writer, List <WritingInfo> writingInfos) { string theText = writer.ToString(); Dictionary <MemberIdentifier, CodeSpan> mapping = new Dictionary <MemberIdentifier, CodeSpan>(); TwoDimensionalString twoDString = new TwoDimensionalString(theText, writer.NewLine, false); foreach (WritingInfo memberInfo in writingInfos) { foreach (KeyValuePair <IMemberDefinition, OffsetSpan> item in memberInfo.MemberDeclarationToCodePostionMap) { IMemberDefinition member = item.Key; OffsetSpan position = item.Value; // Get/set keywords are printed alone in a lane. // This should trim the tabulations before them. position = twoDString.TrimStart(position); CodeSpan codeSpan = GetSpan(twoDString, position); mapping.Add(GetIdentifier(assemblyFilePath, member), codeSpan); } } return(mapping); }
public void Constructor_WhenGivenANullExpression_ThrowsException() { var start = new Cursor("OK"); var end = start.Advance(2); var codeSpan = new CodeSpan("OK", start, end); Assert.That(() => new TypedExpression(codeSpan, null), Throws.InstanceOf <ArgumentNullException>()); }
public void ToString_WhenConstructedWithANullValue_ReturnsTheCodeVerbatim() { var start = new Cursor("OK"); var end = start.Advance(2); var codeSpan = new CodeSpan("OK", start, end); Assert.That(codeSpan.ToString(), Is.EqualTo("OK")); }
public void OwnsChangeReturnsTrueIfSpanContentEntirelyContainsOldSpan() { // Arrange Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz"); TextChange change = new TextChange(45, 3, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo")); // Act/Assert Assert.IsTrue(span.OwnsChange(change)); }
public void OwnsChangeReturnsTrueIfChangeIsInsertionAtSpanEndAndCanGrowIsTrue() { // Arrange Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz"); TextChange change = new TextChange(51, 0, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo")); // Act/Assert Assert.IsTrue(span.OwnsChange(change)); }
public void OwnsChangeReturnsFalseIfChangeIsReplacementOrDeleteAtSpanEnd() { // Arrange Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz"); TextChange change = new TextChange(51, 2, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo")); // Act/Assert Assert.IsFalse(span.OwnsChange(change)); }
public void TryMergeWithReturnsFalseWhenMergingRightIntoLeftIfSpansNotAdjacent() { // Arrange Span left = new CodeSpan(new SourceLocation(100, 0, 0), "Foo"); Span right = new CodeSpan(SourceLocation.Zero, "Bar"); // Act/Assert Assert.IsFalse(left.TryMergeWith(right)); }
public void OwnsChangeReturnsFalseIfOldSpanOverlapsNeighbouringSpan() { // Arrange Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz"); TextChange change = new TextChange(44, 50, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo")); // Act/Assert Assert.IsFalse(span.OwnsChange(change)); }
public void OwnsChangeReturnsFalseIfChangeIsInsertionAtSpanEndAndCanGrowIsFalse() { // Arrange Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz", hidden: false, acceptedCharacters: AcceptedCharacters.None); TextChange change = new TextChange(51, 0, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo")); // Act/Assert Assert.IsFalse(span.OwnsChange(change)); }
public void OwnsChangeReturnsFalseIfChangeStartsAfterSpanEnds() { // Arrange Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz"); TextChange change = new TextChange(52, 3, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo")); // Act/Assert Assert.IsFalse(span.OwnsChange(change)); }
INode RenderObject(IDocument document, InlineObject obj) { return(obj switch { CodeSpan robj => RenderObject(document, robj), Image robj => RenderObject(document, robj), Link robj => RenderObject(document, robj), Text robj => RenderObject(document, robj), _ => throw new NotImplementedException(), });
public ICode Printout() { var code = new CodeSpan(Expression); if (NameLabel != null) { code.Prepend($"{NameLabel}: "); } return(code); }
public override ICode Printout() { var code = new CodeSpan("throw"); if (Expr != null) { code.Append(" ").Append(Expr.Printout()); } return(code); }
public ICode Printout() { var code = new CodeSpan(IsBreak ? "break" : "continue"); if (Label != null) { code.Append(" ").Append(Label); } return(code); }
public void ApplyChangeReturnsRejectedIfTerminatorStringNull() { // Arrange var span = new CodeSpan(new SourceLocation(0, 0, 0), "foo"); var change = new TextChange(0, 0, new StringTextBuffer("foo"), 1, new StringTextBuffer("bfoo")); // Act PartialParseResult result = span.ApplyChange(change); // Assert Assert.AreEqual(PartialParseResult.Rejected, result); }
public ICode Printout() { var code = new CodeSpan(Name); if (Parameters.Any()) { code.Append("<"); code.Append(Parameters, ","); code.Append(">"); } return(code); }
public override ICode Printout() { var code = new CodeSpan($"new {(this.IsHeapInitialization ? "*" : "")}").Append(allocTypeName).Append("(") .Append(InitConstructorCall.UserArguments, ",") .Append(")"); if (this.objectInitialization.Any()) { code.Append("{").Append(this.objectInitialization, ",").Append("}"); } return(code); }
public void TryMergeWithReturnsTrueAndCorrectlyMergesWhenMergingRightIntoLeftIfSpansAreAdjacent() { // Arrange Span left = new CodeSpan(new SourceLocation(3, 0, 0), "Foo"); Span right = new CodeSpan(SourceLocation.Zero, "Bar"); // Act bool success = left.TryMergeWith(right); // Assert Assert.IsTrue(success); Assert.AreEqual("BarFoo", left.Content); Assert.AreEqual(SourceLocation.Zero, left.Start); }
public void TryMergeWithLeavesTypeVisibilityAndTrackingModeUnchanged() { // Arrange Span left = new CodeSpan(SourceLocation.Zero, "Foo", hidden: true, acceptedCharacters: AcceptedCharacters.None); Span right = new MetaCodeSpan(new SourceLocation(3, 0, 0), "Bar"); // Act bool success = left.TryMergeWith(right); // Assert Assert.IsTrue(success); Assert.AreEqual(SpanKind.Code, left.Kind); Assert.IsTrue(left.Hidden); }
public void GetAutoCompleteStringReturnsAutoCompleteString() { // Arrange var span = new CodeSpan(new SourceLocation(0, 0, 0), "foo\r\nbar\r\nbaz") { AutoCompleteString = "Foo" }; // Act string actual = span.AutoCompleteString; // Assert Assert.AreEqual("Foo", actual); }
private void NavigateToTypeDeclaration(ITypeDeclaration typeDeclaration, CodeSpan selection) { if (typeDeclaration.Identifier.CodeSpan.Intersects(selection)) { ITypeDeclaration enclosingType = typeDeclaration.Enclosing <ITypeDeclaration>(); if (enclosingType.ExistsTextuallyInFile) { enclosingType.Identifier.Select(); } } else { typeDeclaration.Identifier.Select(); } }
public void ApplyChangeReturnsRejectedWithoutAutoCompleteBlockIfTerminatorStringNonNullAndEditIsNewlineInsertOnSecondLine() { // Arrange var span = new CodeSpan(new SourceLocation(0, 0, 0), "foo\r\nbar\r\nbaz") { AutoCompleteString = "}" }; var change = new TextChange(8, 0, new StringTextBuffer("foo\r\nbar\r\nbaz"), 2, new StringTextBuffer("foo\r\nb\r\nar\r\nbaz")); // Act PartialParseResult result = span.ApplyChange(change); // Assert Assert.AreEqual(PartialParseResult.Rejected, result); }
/// <summary> /// Converts between an IronPython's CodeSpan and the new text editor's Span /// </summary> /// <param name="location"></param> /// <returns></returns> private Span ConvertCodeSpanToSpan(CodeSpan location) { if (location.StartLine > 0 && location.EndLine > 0) { var startIndex = snapshot.GetLineFromLineNumber(location.StartLine - 1).Start.Position + location.StartColumn - 1; var endIndex = snapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndColumn - 1; if (startIndex != -1 && startIndex < endIndex && endIndex < snapshot.GetText().Length) { return(new Span(startIndex, endIndex - startIndex)); } } return(new Span()); }
public ICode Printout() { string variadic_str = this.Variadic.ToString(); if (variadic_str != "") { variadic_str = " " + variadic_str; } var code = new CodeSpan(this.Name).Append(this.IsNameRequired ? ": " : " ").Append(this.ElementTypeName) .Append(variadic_str); if (this.IsOptional) { code.Append(" = ").Append(DefaultValue); } return(code); }
public override ICode Printout() { CodeSpan code = new CodeSpan(this, Name).Prepend(this.Modifier.HasReassignable ? "var " : "let "); if (this.TypeName != null) { code.Append(" of ").Append(this.TypeName); } if (this.InitValue != null) { code.Append(" " + (this.ReadMode == ExpressionReadMode.ReadRequired ? "<-" : "=") + " ").Append(this.InitValue); } if (this.ReadMode == ExpressionReadMode.ReadRequired) { code.Prepend("(").Append(")"); } return(code); }
public void LocateOwnerReturnsSpanWhichReturnsTrueForOwnsSpan() { // Arrange Span expected = new CodeSpan(new SourceLocation(5, 0, 5), "bar"); Block block = new MarkupBlock(new SyntaxTreeNode[] { new MarkupSpan(SourceLocation.Zero, "Foo "), new StatementBlock(new SyntaxTreeNode[] { new TransitionSpan(new SourceLocation(4, 0, 4), "@"), expected, }), new MarkupSpan(new SourceLocation(8, 0, 8), " Baz") }); TextChange change = new TextChange(6, 1, new StringTextBuffer("Foo @bar Baz"), 1, new StringTextBuffer("Foo @bor Baz")); // Act Span actual = block.LocateOwner(change); // Assert Assert.AreSame(expected, actual); }
public void CodeSpan(CodeSpan cs) { char fenceChar = '`'; string fence = new string(fenceChar, 1); while (cs.Content.Contains(fence)) fence = fence + fenceChar; Write(fence); Write(cs.Content); Write(fence); }
private void NavigateToTypeDeclaration(ITypeDeclaration typeDeclaration, CodeSpan selection) { if (typeDeclaration.Identifier.CodeSpan.Intersects(selection)) { ITypeDeclaration enclosingType = typeDeclaration.Enclosing<ITypeDeclaration>(); if (enclosingType.ExistsTextuallyInFile) { enclosingType.Identifier.Select(); } } else { typeDeclaration.Identifier.Select(); } }
/// <summary> /// Initializes a new instance of the <see cref="AndCodeExpression"/> class. /// </summary> /// <param name="code">The code to execute for the assertion.</param> public AndCodeExpression(CodeSpan code) { this.code = code; }
private IConstructEnumerable<IFieldDeclaration> FindFields(FileModel fileModel, CodeSpan selection) { return from declaration in fileModel.InnerMost<IClassDeclaration>(selection).ContainedDeclarations where declaration.Is<IFieldDeclaration>() && declaration.ExistsTextuallyInFile && !declaration.As<IFieldDeclaration>().IsReadOnly() && declaration.CodeSpan.Intersects(selection) select declaration.As<IFieldDeclaration>(); }
public void CodeSpan(CodeSpan cs) { Write("code {0}", format_str(cs.Content)); }
public override void ExecuteCodeCleaningStep(CodeCleaningStep step, FileModel fileModel, CodeSpan span) { fileModel.All<IPreProcessorDirectiveLine>() .Where(line => line.IsRegion()) .ForEach(region => region.Delete()); }
public void CodeSpan(CodeSpan cs) { writer.Write("<code>"); writer.Write(EscapeHtml(cs.Content, false)); writer.Write("</code>"); }