Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new FilePosition instance for the specified file by
 /// copying the specified BufferPosition
 /// </summary>
 /// <param name="scriptFile">The ScriptFile in which the position is located.</param>
 /// <param name="copiedPosition">The original BufferPosition from which the line and column will be copied.</param>
 public FilePosition(
     ScriptFile scriptFile,
     BufferPosition copiedPosition)
     : this(scriptFile, copiedPosition.Line, copiedPosition.Column)
 {
     scriptFile.ValidatePosition(copiedPosition);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new FilePosition instance for the specified file by
 /// copying the specified BufferPosition
 /// </summary>
 /// <param name="document">The document in which the position is located.</param>
 /// <param name="copiedPosition">The original BufferPosition from which the line and column will be copied.</param>
 public DocumentPosition(
     TextDocument document,
     BufferPosition copiedPosition)
     : this(document, copiedPosition.Line, copiedPosition.Column)
 {
     document.ValidatePosition(copiedPosition);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets a selection in the host editor's active buffer.
 /// </summary>
 /// <param name="startPosition">The starting position of the selection.</param>
 /// <param name="endPosition">The ending position of the selection.</param>
 public void SetSelection(
     BufferPosition startPosition,
     BufferPosition endPosition)
 {
     this.SetSelection(
         new BufferRange(
             startPosition,
             endPosition));
 }
 /// <summary>
 /// Creates a new instance of the EditorContext class.
 /// </summary>
 /// <param name="editorOperations">An IEditorOperations implementation which performs operations in the editor.</param>
 /// <param name="currentFile">The ScriptFile that is in the active editor buffer.</param>
 /// <param name="cursorPosition">The position of the user's cursor in the active editor buffer.</param>
 /// <param name="selectedRange">The range of the user's selection in the active editor buffer.</param>
 public EditorContext(
     IEditorOperations editorOperations,
     ScriptFile currentFile,
     BufferPosition cursorPosition,
     BufferRange selectedRange)
 {
     this.editorOperations = editorOperations;
     this.CurrentFile      = new FileContext(currentFile, this, editorOperations);
     this.SelectedRange    = selectedRange;
     this.CursorPosition   = new FilePosition(currentFile, cursorPosition);
 }
 /// <summary>
 /// Creates a new instance of the EditorContext class.
 /// </summary>
 /// <param name="editorOperations">An IEditorOperations implementation which performs operations in the editor.</param>
 /// <param name="currentFile">The ScriptFile that is in the active editor buffer.</param>
 /// <param name="cursorPosition">The position of the user's cursor in the active editor buffer.</param>
 /// <param name="selectedRange">The range of the user's selection in the active editor buffer.</param>
 /// <param name="language">Determines the language of the file.false If it is not specified, then it defaults to "Unknown"</param>
 internal EditorContext(
     IEditorOperations editorOperations,
     ScriptFile currentFile,
     BufferPosition cursorPosition,
     BufferRange selectedRange,
     string language = "Unknown")
 {
     this.editorOperations = editorOperations;
     this.CurrentFile      = new FileContext(currentFile, this, editorOperations, language);
     this.SelectedRange    = new BufferFileRange(selectedRange);
     this.CursorPosition   = new BufferFilePosition(cursorPosition);
 }
Ejemplo n.º 6
0
        public void GetOffsetAtPositionTest()
        {
            ScriptFile scriptFile = GetTestScriptFile();
            int        offset     = scriptFile.GetOffsetAtPosition(2, 5);
            int        expected   = 35 + Environment.NewLine.Length;

            Assert.True(offset == expected, "Offset is at expected location");

            BufferPosition position = scriptFile.GetPositionAtOffset(offset);

            Assert.True(position.Line == 2 && position.Column == 5, "Position is at expected location");
        }
Ejemplo n.º 7
0
        public byte Peek(BufferPosition position, int offset)
        {
            var index = position.Index + offset;

            if (index < _startIndex)
            {
                throw StartOfStreamExeption();
            }
            if (index >= _index)
            {
                throw EndOfWrittenExeption();
            }
            return(_buffer[index]);
        }
Ejemplo n.º 8
0
 /// <summary>Attempts to get a <typeparamref name="T"/> value at the given BufferPosition, and advance the buffer by one position.</summary>
 /// <param name="position">[in,out] The position.</param>
 /// <param name="value">[out] The value.</param>
 /// <returns>True if it succeeds, false if it fails.</returns>
 public static bool TryGetValue(ref BufferPosition position, out T value)
 {
     if (position.Index < position.Buffer.head)
     {
         value    = position.Buffer.data[position.Index];
         position = new BufferPosition(position.Buffer, position.Index + 1);
         return(true);
     }
     if (position.Buffer.next?.head > 0)
     {
         value    = position.Buffer.next.data[0];
         position = new BufferPosition(position.Buffer.next, 1);
         return(true);
     }
     value = default(T);
     return(false);
 }
Ejemplo n.º 9
0
        public Task ValidateTextDocument(TextDocument document, EventContext context)
        {
            int problems = 0;
            List <Diagnostic> diagnostics = new List <Diagnostic>();

            foreach (Match m in Pattern.Matches(document.Contents))
            {
                problems++;

                BufferPosition start = document.GetPositionAtOffset(m.Index);
                BufferPosition end   = document.GetPositionAtOffset(m.Index + m.Value.Length);

                diagnostics.Add(new Diagnostic
                {
                    Severity = DiagnosticSeverity.Warning,
                    Code     = "ex",
                    Message  = string.Format("'{0}' is all uppercase.", m.Value),
                    Range    = new Range
                    {
                        Start = new Position {
                            Line = start.Line - document.BaseOffset, Character = start.Column - document.BaseOffset
                        },
                        End = new Position {
                            Line = end.Line - document.BaseOffset, Character = end.Column - document.BaseOffset
                        },
                    }
                });

                // TODO: check client capability for related information

                // TODO: check problem count against settings
            }

            context.SendEvent(
                PublishDiagnosticsNotification.Type,
                new PublishDiagnosticsNotification
            {
                Uri         = document.ClientFilePath,
                Diagnostics = diagnostics.ToArray()
            }
                );

            return(Task.FromResult(true));
        }
Ejemplo n.º 10
0
        public void WriteCopy(BufferPosition position, int count)
        {
            if (count <= 0)
            {
                return;
            }
            var i = _index;

            if (position.Index + count > _index)
            {
                throw EndOfWrittenExeption();
            }
            if (i + count > _length)
            {
                throw OutOfBufferException();
            }
            Array.Copy(_buffer, position.Index, _buffer, i, count);
            _index = i + count;
        }
Ejemplo n.º 11
0
        public void CorrectlyReportsPosition()
        {
            // Arrange.
            TextBuffer buffer = new TextBuffer(string.Format("Abc{0}Defg{0}C", "\r\n"));

            // Act.
            buffer.NextChar();
            buffer.NextChar();
            buffer.NextChar();
            buffer.NextChar();
            buffer.NextChar();
            buffer.NextChar();

            BufferPosition position = buffer.Position;

            // Assert.
            Assert.AreEqual(2, position.Column);
            Assert.AreEqual(1, position.Line);
            Assert.AreEqual(7, position.Offset);
        }
Ejemplo n.º 12
0
 public PreprocessorIntToken(int value, BufferPosition position)
     : base(PreprocessorTokenType.Int, position)
 {
     Value = value;
 }
Ejemplo n.º 13
0
 public Token(TokenType type, string sourcePath, BufferPosition position)
 {
     Type       = type;
     SourcePath = sourcePath;
     Position   = position;
 }
Ejemplo n.º 14
0
 public byte Peek(BufferPosition position)
 {
     return(_buffer[position.Index]);
 }
Ejemplo n.º 15
0
 public BufferFilePosition(BufferPosition position)
 {
     _position = position;
 }
Ejemplo n.º 16
0
 internal UIntToken(uint value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.UInt, sourcePath, position)
 {
     _value = value;
 }
Ejemplo n.º 17
0
 internal Token(TokenType type, string sourcePath, BufferPosition position)
 {
     Type          = type;
     SourcePath    = sourcePath;
     this.position = position;
 }
Ejemplo n.º 18
0
 public FloatToken(float value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Float, sourcePath, position)
 {
     Value = value;
 }
Ejemplo n.º 19
0
 public IntToken(int value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Int, sourcePath, position)
 {
     Value = value;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Inserts a text string at the specified buffer position.
 /// </summary>
 /// <param name="textToInsert">The text string to insert.</param>
 /// <param name="insertPosition">The position at which the text will be inserted.</param>
 public void InsertText(string textToInsert, BufferPosition insertPosition)
 {
     this.InsertText(
         textToInsert,
         new BufferRange(insertPosition, insertPosition));
 }
Ejemplo n.º 21
0
 public AsciiBuffer(int left, int top, int width, int height)
 {
     Data           = new AsciiPixel[width, height];
     BufferPosition = new BufferPosition(top, left, width, height);
 }
 internal LiteralToken(LiteralTokenType literalType, string sourcePath, BufferPosition position)
     : base(TokenType.Literal, sourcePath, position)
 {
     _literalType = literalType;
 }
Ejemplo n.º 23
0
 internal ULongToken(ulong value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.ULong, sourcePath, position)
 {
     _value = value;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// GetHashCode()
 /// </summary>
 /// <returns></returns>
 public override int GetHashCode() => (int)Column ^ BufferPosition.GetHashCode() ^ CellPosition.GetHashCode();
Ejemplo n.º 25
0
 public bool Equals(BufferPosition other)
 {
     return(this.Buffer.Equals(other.Buffer) && this.Index == other.Index);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// ToString()
 /// </summary>
 /// <returns></returns>
 public override string ToString() => "[" + Column.ToString() + "," + BufferPosition.ToString() + "," + CellPosition.ToString() + "]";
Ejemplo n.º 27
0
 internal DoubleToken(double value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Double, sourcePath, position)
 {
     Value = value;
 }
Ejemplo n.º 28
0
 internal CharToken(char value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.Char, sourcePath, position)
 {
     _value = value;
 }
Ejemplo n.º 29
0
 public PreprocessorIdentifierToken(Name value, BufferPosition position)
     : base(PreprocessorTokenType.Identifier, position)
 {
     Value = value;
 }
Ejemplo n.º 30
0
 internal StringToken(string value, string sourcePath, BufferPosition position)
     : base(LiteralTokenType.String, sourcePath, position)
 {
     Value = value;
 }