Ejemplo n.º 1
0
 public void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea,
                      ICSharpCode.AvalonEdit.Document.ISegment completionSegment,
                      EventArgs insertionRequestEventArgs)
 {
     if (textArea != null && textArea.Document != null)
     {
         textArea.Document.Replace(completionSegment, this.Text);
     }
 }
Ejemplo n.º 2
0
 public void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     try
     {
         textArea.Document.Replace(MainWindow.StartIndex, MainWindow.Length, this.Text);
     }
     catch (Exception)
     {
         //SetStatus?.BeginInvoke("代码提示模块出现错误", null, null);
     }
 }
Ejemplo n.º 3
0
 public void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     textArea.Selection.ReplaceSelectionWithText(_text);
 }
Ejemplo n.º 4
0
 public void Complete(TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     textArea.Document.Replace(completionSegment, this.Text + "\n");
 }
Ejemplo n.º 5
0
        public void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            var change = Content;

            textArea.Document.Replace(completionSegment, (string)change);
        }
        public override void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            var insertion = Action == null ? this.Text : Action.Invoke();

            textArea.Document.Replace(completionSegment, insertion);
            if (insertion.EndsWith("("))
            {
                _parent.ShowCompletions(_control);
            }
        }
 public string GetText(ICSharpCode.AvalonEdit.Document.ISegment segment)
 {
     throw new NotImplementedException();
 }
        public IEnumerable <ICSharpCode.AvalonEdit.Document.ISegment> GetDeletableSegments(ICSharpCode.AvalonEdit.Document.ISegment segment)
        {
            var firstOffset = _area.Document.Lines
                              .Reverse()
                              .First(l => _area.Document.GetText(l)
                                     .StartsWith(">")).Offset;
            var lastOffset = _area.Document.Lines.Last().EndOffset;

            if (segment.Offset < firstOffset + 1)
            {
                return(new List <Segment>());
            }

            var startingOffset = segment.Offset < firstOffset + 1 ? firstOffset + 1 : segment.Offset;
            var seg            = new Segment()
            {
                EndOffset = segment.EndOffset,
                Length    = segment.Length,
                Offset    = segment.Offset
            };

            return(new List <Segment>()
            {
                seg
            });
        }
Ejemplo n.º 9
0
 public virtual void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     textArea.Document.Replace(completionSegment, text_);
 }
Ejemplo n.º 10
0
 public override void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     // Removed hard written addition of '(' because it interferes with overload-insight
     if (func_.Inner != null && func_.Inner.Length > 2)
     {
         textArea.Document.Replace(completionSegment, func_.Name.Trim());
     }
     else
     {
         textArea.Document.Replace(completionSegment, text_);
     }
 }
Ejemplo n.º 11
0
        //TODO: this is never called, on completion
        public void XXXComplete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            if (declarationBegin > completionSegment.Offset)
            {
                base.Complete(textArea, completionSegment, insertionRequestEventArgs);
                return;
            }
            TypeSystemAstBuilder b = new TypeSystemAstBuilder(new CSharpResolver(contextAtCaret));

            b.ShowTypeParameterConstraints = false;
            b.GenerateBody = true;

            var entityDeclaration = b.ConvertEntity(this.Entity);

            entityDeclaration.Modifiers &= ~(Modifiers.Virtual | Modifiers.Abstract);
            entityDeclaration.Modifiers |= Modifiers.Override;

            if (!this.Entity.IsAbstract)
            {
                // modify body to call the base method
                if (this.Entity.EntityType == EntityType.Method)
                {
                    var baseCall = new BaseReferenceExpression().Invoke(this.Entity.Name, ParametersToExpressions(this.Entity));
                    var body     = entityDeclaration.GetChildByRole(Roles.Body);
                    body.Statements.Clear();
                    if (((IMethod)this.Entity).ReturnType.IsKnownType(KnownTypeCode.Void))
                    {
                        body.Statements.Add(new ExpressionStatement(baseCall));
                    }
                    else
                    {
                        body.Statements.Add(new ReturnStatement(baseCall));
                    }
                }
                else if (this.Entity.EntityType == EntityType.Indexer || this.Entity.EntityType == EntityType.Property)
                {
                    Expression baseCall;
                    if (this.Entity.EntityType == EntityType.Indexer)
                    {
                        baseCall = new BaseReferenceExpression().Indexer(ParametersToExpressions(this.Entity));
                    }
                    else
                    {
                        baseCall = new BaseReferenceExpression().Member(this.Entity.Name);
                    }
                    var getterBody = entityDeclaration.GetChildByRole(PropertyDeclaration.GetterRole).Body;
                    if (!getterBody.IsNull)
                    {
                        getterBody.Statements.Clear();
                        getterBody.Add(new ReturnStatement(baseCall.Clone()));
                    }
                    var setterBody = entityDeclaration.GetChildByRole(PropertyDeclaration.SetterRole).Body;
                    if (!setterBody.IsNull)
                    {
                        setterBody.Statements.Clear();
                        setterBody.Add(new AssignmentExpression(baseCall.Clone(), new IdentifierExpression("value")));
                    }
                }
            }

            var          document          = textArea.Document;
            StringWriter w                 = new StringWriter();
            var          formattingOptions = FormattingOptionsFactory.CreateSharpDevelop();
            var          segmentDict       = SegmentTrackingOutputFormatter.WriteNode(w, entityDeclaration, formattingOptions, textArea.Options);

            string newText = w.ToString().TrimEnd();

            document.Replace(declarationBegin, completionSegment.EndOffset - declarationBegin, newText);
            var throwStatement = entityDeclaration.Descendants.FirstOrDefault(n => n is ThrowStatement);

            if (throwStatement != null)
            {
                var segment = segmentDict[throwStatement];
                textArea.Selection = new RectangleSelection(textArea, new TextViewPosition(textArea.Document.GetLocation(declarationBegin + segment.Offset)), new TextViewPosition(textArea.Document.GetLocation(declarationBegin + segment.Offset + segment.Length)));
            }

            //format the inserted code nicely
            //AvalonEdit and NRefactory dont play nice together.
            //var formatter = new CSharpFormatter(formattingOptions);
            //formatter.AddFormattingRegion(new DomRegion(document.GetLocation(declarationBegin), document.GetLocation(declarationBegin + newText.Length)));
            //var syntaxTree = new CSharpParser().Parse(document);
            //formatter.AnalyzeFormatting(document, syntaxTree).ApplyChanges();
        }
 public void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, System.EventArgs insertionRequestEventArgs)
 {
 }
Ejemplo n.º 13
0
 public override void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
 {
     if (func_.Inner != null && func_.Inner.Length > 2)
     {
         textArea.Document.Replace(completionSegment, func_.Name.Trim() + "(");
     }
     else
     {
         textArea.Document.Replace(completionSegment, text_);
     }
 }