示例#1
0
        public static IErrorMarker CreateErrorMarker(TextEditor editor, Error info)
        {
            int offset    = editor.LocationToOffset(info.Region.BeginLine, info.Region.BeginColumn);
            int endOffset = editor.LocationToOffset(info.Region.EndLine, info.Region.EndColumn);

            if (endOffset <= offset)
            {
                endOffset = offset + 1;
                while (endOffset < editor.Length && IsIdentifierPart(editor.GetCharAt(endOffset)))
                {
                    endOffset++;
                }
                if (endOffset == offset + 1)
                {
                    if (endOffset - 1 < editor.Length)
                    {
                        var c = editor.GetCharAt(endOffset - 1);
                        while ((c == '\n' || c == '\r') && endOffset < editor.Length)
                        {
                            c = editor.GetCharAt(endOffset);
                            endOffset++;
                        }
                    }
                    else
                    {
                        endOffset = editor.Length;
                    }
                }
            }
            return(editor.TextMarkerFactory.CreateErrorMarker(editor, info, offset, endOffset - offset));
        }
 static bool IsMatchAt(TextEditor editor, int offset, string abbrevWord)
 {
     if (offset + abbrevWord.Length >= editor.Length)
     {
         return(false);
     }
     if (offset > 0 && IsIdentifierPart(editor.GetCharAt(offset - 1)))
     {
         return(false);
     }
     if (offset + abbrevWord.Length < editor.Length && !IsIdentifierPart(editor.GetCharAt(offset + abbrevWord.Length)))
     {
         return(false);
     }
     return(editor.GetTextAt(offset, abbrevWord.Length) == abbrevWord);
 }
 static int SearchEndPos(int offset, TextEditor editor)
 {
     while (offset < editor.Length && IsIdentifierPart(editor.GetCharAt(offset)))
     {
         offset++;
     }
     return(offset);
 }
        public override async System.Threading.Tasks.Task <ICompletionDataList> HandleCodeCompletionAsync(CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, System.Threading.CancellationToken token)
        {
            if (triggerInfo.CompletionTriggerReason == CompletionTriggerReason.CompletionCommand)
            {
                if (hiddenInfo != null && (isInCSharpContext || Tracker.Engine.CurrentState is RazorState) &&
                    !(Tracker.Engine.Nodes.Peek() is XElement))
                {
                    InitializeCodeCompletion();
                    return(await completionBuilder.HandlePopupCompletion(defaultEditor, defaultDocumentContext, hiddenInfo));
                }
            }
            char previousChar = defaultEditor.CaretOffset > 1 ? defaultEditor.GetCharAt(
                defaultEditor.CaretOffset - 2) : ' ';

            if (triggerInfo.CompletionTriggerReason != CompletionTriggerReason.CharTyped)
            {
                return(null);
            }
            // Don't show completion window when directive's name is being typed
            var directive = Tracker.Engine.Nodes.Peek() as RazorDirective;

            if (directive != null && !directive.FirstBracket.HasValue)
            {
                return(null);
            }
            var completionChar = triggerInfo.TriggerCharacter.Value;

            if (hiddenInfo != null && isInCSharpContext)
            {
                var list = (CompletionDataList)await completionBuilder.HandleCompletion(defaultEditor, defaultDocumentContext, completionContext,
                                                                                        hiddenInfo, completionChar, token);

                if (list != null)
                {
                    //filter out the C# templates, many of them are not valid
                    int oldCount = list.Count;
                    list = FilterCSharpTemplates(list);
                    int templates = list.Count - oldCount;

                    if (previousChar == '@')
                    {
                        RazorCompletion.AddAllRazorSymbols(list, razorDocument.PageInfo.HostKind);
                    }
                    if (templates > 0)
                    {
                        AddFilteredRazorTemplates(list, previousChar == '@', true);
                    }
                }
                return(list);
            }

            return(await base.HandleCodeCompletionAsync(completionContext, triggerInfo, token));
        }
示例#5
0
        public static IErrorMarker CreateErrorMarker(TextEditor editor, Error info)
        {
            int offset    = editor.LocationToOffset(info.Region.BeginLine, info.Region.BeginColumn);
            int endOffset = editor.LocationToOffset(info.Region.EndLine, info.Region.EndColumn);

            if (endOffset < offset)
            {
                endOffset = offset + 1;
                while (endOffset < editor.Length && IsIdentifierPart(editor.GetCharAt(endOffset)))
                {
                    endOffset++;
                }
            }
            return(editor.TextMarkerFactory.CreateErrorMarker(editor, info, offset, endOffset - offset));
        }
        static string GetWordBeforeCaret(TextEditor editor)
        {
            int startOffset = editor.CaretOffset;
            int offset      = startOffset - 1;

            while (offset > 0)
            {
                char ch = editor.GetCharAt(offset);
                if (!IsIdentifierPart(ch))
                {
                    offset++;
                    break;
                }
                offset--;
            }
            if (offset >= startOffset)
            {
                return("");
            }
            return(editor.GetTextBetween(offset, startOffset));
        }
 public char GetChar(int offset)
 {
     return(editor.GetCharAt(offset));
 }
示例#8
0
        public static void TransposeCharacters(TextEditor textEditor)
        {
            // Code from Mono.TextEditor.MiscActions.TransposeCharacters
            if (textEditor.CaretOffset == 0)
            {
                return;
            }
            var line = textEditor.GetLine(textEditor.CaretLine);

            if (line == null)
            {
                return;
            }
            using (var undoGroup = textEditor.OpenUndoGroup()) {
                int  transposeOffset = textEditor.CaretOffset - 1;
                char ch;
                if (textEditor.CaretColumn == 0)
                {
                    var lineAbove = textEditor.GetLine(textEditor.CaretLine - 1);
                    if (lineAbove.Length == 0 && line.Length == 0)
                    {
                        return;
                    }

                    if (line.Length != 0)
                    {
                        ch = textEditor.GetCharAt(textEditor.CaretOffset);
                        textEditor.RemoveText(textEditor.CaretOffset, 1);
                        textEditor.InsertText(lineAbove.Offset + lineAbove.Length, ch.ToString());
                        return;
                    }

                    int lastCharOffset = lineAbove.Offset + lineAbove.Length - 1;
                    ch = textEditor.GetCharAt(lastCharOffset);
                    textEditor.RemoveText(lastCharOffset, 1);
                    textEditor.InsertAtCaret(ch.ToString());
                    return;
                }

                int offset = textEditor.CaretOffset;
                if (textEditor.CaretColumn >= line.Length + 1)
                {
                    offset          = line.Offset + line.Length - 1;
                    transposeOffset = offset - 1;
                    // case one char in line:
                    if (transposeOffset < line.Offset)
                    {
                        var lineAbove = textEditor.GetLine(textEditor.CaretLine - 1);
                        transposeOffset = lineAbove.Offset + lineAbove.Length;
                        ch = textEditor.GetCharAt(offset);
                        textEditor.RemoveText(offset, 1);
                        textEditor.InsertText(transposeOffset, ch.ToString());
                        textEditor.CaretOffset = line.Offset;
                        return;
                    }
                }

                ch = textEditor.GetCharAt(offset);
                textEditor.ReplaceText(offset, 1, textEditor.GetCharAt(transposeOffset).ToString());
                textEditor.ReplaceText(transposeOffset, 1, ch.ToString());
                if (textEditor.CaretColumn < line.Length + 1)
                {
                    textEditor.CaretOffset = offset + 1;
                }
            }
        }