Skip to main content

TokenUtils

Import :

const TokenUtils = brackets.getModule("utils/TokenUtils")

_

Functions for iterating through tokens in the current editor buffer. Useful for doing light parsing that can rely purely on information gathered by the code coloring mechanism.

Kind: global variable

getTokenAt(cm, pos, precise) ⇒ Object

Like cm.getTokenAt, but with caching. Way more performant for long lines.

Kind: global function
Returns: Object - Token for position

ParamTypeDescription
cmCodeMirror
posObject
precisebooleanIf given, results in more current results. Suppresses caching.

getInitialContext(cm, pos) ⇒ Object

Creates a context object for the given editor and position, suitable for passing to the move functions.

Kind: global function

ParamType
cmCodeMirror
posObject

movePrevToken(ctx, [precise]) ⇒ boolean

Moves the given context backwards by one token.

Kind: global function
Returns: boolean - whether the context changed

ParamTypeDescription
ctxObject
[precise]booleanIf code is being edited, use true (default) for accuracy. If parsing unchanging code, use false to use cache for performance.

isAtStart(ctx) ⇒ boolean

Kind: global function
Returns: boolean - true if movePrevToken() would return false without changing pos

ParamType
ctxObject

moveNextToken(ctx, [precise]) ⇒ boolean

Moves the given context forward by one token.

Kind: global function
Returns: boolean - whether the context changed

ParamTypeDescription
ctxObject
[precise]booleanIf code is being edited, use true (default) for accuracy. If parsing unchanging code, use false to use cache for performance.

isAtEnd(ctx) ⇒ boolean

Kind: global function
Returns: boolean - true if moveNextToken() would return false without changing pos

ParamType
ctxObject

moveSkippingWhitespace(moveFxn, ctx) ⇒ boolean

Moves the given context in the given direction, skipping any whitespace it hits.

Kind: global function
Returns: boolean - whether the context changed

ParamTypeDescription
moveFxnfunctionthe function to move the context
ctxObject

offsetInToken(context) ⇒ number

In the given context, get the character offset of pos from the start of the token.

Kind: global function

ParamType
contextObject

getModeAt(cm, pos, precise) ⇒ Object

Returns the mode object and mode name string at a given position

Kind: global function

ParamTypeDescription
cmCodeMirrorCodeMirror instance
posObjectPosition to query for mode
precisebooleanIf given, results in more current results. Suppresses caching.