C# Class Microsoft.R.Editor.Tree.EditorTree

Document tree for the editor. It does not derive from AST and rather aggregates it. The reason is that editor tree can be read and updated from different threads and hence we need to control access to the tree elements using appropriate locks. Typically there are three threads: main application thread which should be creating editor tree, incremental parse thread and validation (syntx check) thread.
Inheritance: IEditorTree, IDisposable
Show file Open project: Microsoft/RTVS Class Usage Examples

Private Properties

Property Type Description
ApplyChangesFromQueue List
Dispose void
FireOnNodesRemoved void
FireOnPositionsOnlyChanged void
FireOnUpdateBegin void
FireOnUpdateCompleted void
FireOnUpdatesPending void
FirePostUpdateEvents void
GetAstRootUnsafe Microsoft.R.Core.AST.AstRoot
InvalidateInRange bool
NotifyTextChange void
OnTextBufferChanged void
ProcessChanges void
TakeThreadOwnerShip void
ToString string

Public Methods

Method Description
AcquireReadLock ( System.Guid treeUserId ) : AstRoot
AcquireWriteLock ( ) : bool
Build ( ) : void

Builds initial AST. Subsequent updates should be coming from a background thread.

Dispose ( ) : void
EditorTree ( ITextBuffer textBuffer, ICoreShell shell, IExpressionTermFilter filter = null ) : System

Creates document tree on a given text buffer.

EnsureTreeReady ( ) : void

Ensures tree is up to date, matches current text buffer snapshot and all changes since the last update were processed. Blocks until all changes have been processed. Does not pump messages.

GetCommentBlockContainingRange ( ITextRange range ) : ITextRange

Determines if a given range is inside a comment and returns range of the comment block.

GetCommentBlockFromPosition ( int position ) : ITextRange

Determines if a given position is inside a comment and returns range of the comment block.

GetPositionElement ( int position, IAstNode &node ) : PositionType

Determines position type and enclosing element node for a given position in the document text.

Invalidate ( ) : void

Removes all elements from the tree

InvokeWhenReady ( Action action, object p, Type type, bool processNow = false ) : void

Provides a way to automatically invoke particular action once when tree becomes ready again. Typically used in asynchronous completion and signature help scenarios.

IsRangeInComment ( ITextRange range ) : bool

Determines if a given range is inside a comment.

IsRangeInComment ( int position ) : bool

Determines if a given position is inside a comment of any kind. Comment may be plain HTML comment or artifact type comment like <%--...--%> in ASP.NET or @* ... *@ in Razor.

ReleaseReadLock ( System.Guid treeUserId ) : bool
ReleaseWriteLock ( ) : bool

Private Methods

Method Description
ApplyChangesFromQueue ( Queue queue ) : List
Dispose ( bool disposing ) : void
FireOnNodesRemoved ( IReadOnlyCollection nodes ) : void

Fires 'nodes removed' event on the main thread context

FireOnPositionsOnlyChanged ( ) : void

Fires 'positions changed starting inside this element' event on the main thread context

FireOnUpdateBegin ( ) : void

Fires 'update begin' event on the main thread context

FireOnUpdateCompleted ( TreeUpdateType updateType ) : void

Fires 'update end' event on the main thread context

FireOnUpdatesPending ( IReadOnlyCollection textChanges ) : void

Fires 'tree updates pending' event on the main thread context

FirePostUpdateEvents ( List changes, bool fullParse ) : void
GetAstRootUnsafe ( ) : AstRoot
InvalidateInRange ( ITextRange range ) : bool

Removes nodes from the tree collection if node range is partially or entirely within the deleted region. This is needed since parsing is asynchronous and without node removal intellisense and syntax checker may end up processing nodes that are out of date. Where possible stops at the nearest scope level so scope nodes may still be used in smart indenter.

NotifyTextChange ( int start, int oldLength, int newLength ) : void
OnTextBufferChanged ( object sender, TextContentChangedEventArgs e ) : void
ProcessChanges ( ) : void

Initiates processing of pending changes synchronously.

TakeThreadOwnerShip ( ) : void

Makes current thread owner of the tree. Normally only one thread can access the tree.

ToString ( ) : string

Method Details

AcquireReadLock() public method

public AcquireReadLock ( System.Guid treeUserId ) : AstRoot
treeUserId System.Guid
return Microsoft.R.Core.AST.AstRoot

AcquireWriteLock() public method

public AcquireWriteLock ( ) : bool
return bool

Build() public method

Builds initial AST. Subsequent updates should be coming from a background thread.
public Build ( ) : void
return void

Dispose() public method

public Dispose ( ) : void
return void

EditorTree() public method

Creates document tree on a given text buffer.
public EditorTree ( ITextBuffer textBuffer, ICoreShell shell, IExpressionTermFilter filter = null ) : System
textBuffer ITextBuffer Text buffer
shell ICoreShell
filter IExpressionTermFilter
return System

EnsureTreeReady() public method

Ensures tree is up to date, matches current text buffer snapshot and all changes since the last update were processed. Blocks until all changes have been processed. Does not pump messages.
public EnsureTreeReady ( ) : void
return void

GetCommentBlockContainingRange() public method

Determines if a given range is inside a comment and returns range of the comment block.
public GetCommentBlockContainingRange ( ITextRange range ) : ITextRange
range ITextRange Text range to check
return ITextRange

GetCommentBlockFromPosition() public method

Determines if a given position is inside a comment and returns range of the comment block.
public GetCommentBlockFromPosition ( int position ) : ITextRange
position int Position to check
return ITextRange

GetPositionElement() public method

Determines position type and enclosing element node for a given position in the document text.
public GetPositionElement ( int position, IAstNode &node ) : PositionType
position int Position in the document text
node IAstNode Node that contains position
return PositionType

Invalidate() public method

Removes all elements from the tree
public Invalidate ( ) : void
return void

InvokeWhenReady() public method

Provides a way to automatically invoke particular action once when tree becomes ready again. Typically used in asynchronous completion and signature help scenarios.
public InvokeWhenReady ( Action action, object p, Type type, bool processNow = false ) : void
action Action Action to invoke
p object Parameter to pass to the action
type System.Type Action identifier
processNow bool /// If true, change processing begins now. /// If false, next regular parsing pass with process pending changes. ///
return void

IsRangeInComment() public method

Determines if a given range is inside a comment.
public IsRangeInComment ( ITextRange range ) : bool
range ITextRange Text range
return bool

IsRangeInComment() public method

Determines if a given position is inside a comment of any kind. Comment may be plain HTML comment or artifact type comment like <%--...--%> in ASP.NET or @* ... *@ in Razor.
public IsRangeInComment ( int position ) : bool
position int Position in the document
return bool

ReleaseReadLock() public method

public ReleaseReadLock ( System.Guid treeUserId ) : bool
treeUserId System.Guid
return bool

ReleaseWriteLock() public method

public ReleaseWriteLock ( ) : bool
return bool