/// <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); }
/// <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); }
/// <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); }
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"); }
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]); }
/// <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); }
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)); }
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; }
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); }
public PreprocessorIntToken(int value, BufferPosition position) : base(PreprocessorTokenType.Int, position) { Value = value; }
public Token(TokenType type, string sourcePath, BufferPosition position) { Type = type; SourcePath = sourcePath; Position = position; }
public byte Peek(BufferPosition position) { return(_buffer[position.Index]); }
public BufferFilePosition(BufferPosition position) { _position = position; }
internal UIntToken(uint value, string sourcePath, BufferPosition position) : base(LiteralTokenType.UInt, sourcePath, position) { _value = value; }
internal Token(TokenType type, string sourcePath, BufferPosition position) { Type = type; SourcePath = sourcePath; this.position = position; }
public FloatToken(float value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Float, sourcePath, position) { Value = value; }
public IntToken(int value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Int, sourcePath, position) { Value = value; }
/// <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)); }
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; }
internal ULongToken(ulong value, string sourcePath, BufferPosition position) : base(LiteralTokenType.ULong, sourcePath, position) { _value = value; }
/// <summary> /// GetHashCode() /// </summary> /// <returns></returns> public override int GetHashCode() => (int)Column ^ BufferPosition.GetHashCode() ^ CellPosition.GetHashCode();
public bool Equals(BufferPosition other) { return(this.Buffer.Equals(other.Buffer) && this.Index == other.Index); }
/// <summary> /// ToString() /// </summary> /// <returns></returns> public override string ToString() => "[" + Column.ToString() + "," + BufferPosition.ToString() + "," + CellPosition.ToString() + "]";
internal DoubleToken(double value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Double, sourcePath, position) { Value = value; }
internal CharToken(char value, string sourcePath, BufferPosition position) : base(LiteralTokenType.Char, sourcePath, position) { _value = value; }
public PreprocessorIdentifierToken(Name value, BufferPosition position) : base(PreprocessorTokenType.Identifier, position) { Value = value; }
internal StringToken(string value, string sourcePath, BufferPosition position) : base(LiteralTokenType.String, sourcePath, position) { Value = value; }