Session
Import :
const Session = brackets.getModule("JSUtils/Session")
Session
Kind: global class
- Session
- new Session(editor)
- .getPath() ⇒
String
- .getCursor() ⇒
Object
- .getLine(line) ⇒
String
- .getOffset() ⇒
number
- .getOffsetFromCursor(the) ⇒
number
- .getToken(cursor) ⇒
Object
- .getNextTokenOnLine(cursor) ⇒
Object
- .getNextCursorOnLine() ⇒
Object
- .getNextToken(cursor, skipWhitespace) ⇒
Object
- .getQuery() ⇒
String
- .getContext(cursor, [depth]) ⇒
String
- .findPreviousDot() ⇒
Object
- .getFunctionInfo() ⇒
Object
- .getType() ⇒
Object
- .getHints(query, matcher) ⇒
Object
- .setFnType(newFnType)
- .setFunctionCallPos(functionCallPos)
- .getParameterHint() ⇒
Object
- .getJavascriptText() ⇒
String
- .isFunctionName() ⇒
Boolean
new Session(editor)
Session objects encapsulate state associated with a hinting session and provide methods for updating and querying the session.
Param | Type | Description |
---|---|---|
editor | Editor | the editor context for the session |
session.getPath() ⇒ String
Get the name of the file associated with the current session
Kind: instance method of Session
Returns: String
- - the full pathname of the file associated with the
current session
session.getCursor() ⇒ Object
Get the current cursor position.
Kind: instance method of Session
Returns: Object
- - the current cursor position
session.getLine(line) ⇒ String
Get the text of a line.
Kind: instance method of Session
Returns: String
- - the text of the line
Param | Type | Description |
---|---|---|
line | number | the line number |
session.getOffset() ⇒ number
Get the offset of the current cursor position
Kind: instance method of Session
Returns: number
- - the offset into the current document of the current
cursor
session.getOffsetFromCursor(the) ⇒ number
Get the offset of a cursor position
Kind: instance method of Session
Returns: number
- - the offset into the current document of the cursor
Param | Type | Description |
---|---|---|
the | Object | line/col info |
session.getToken(cursor) ⇒ Object
Get the token at the given cursor position, or at the current cursor if none is given.
Kind: instance method of Session
Returns: Object
- - the CodeMirror token at the given cursor position
Param | Type | Description |
---|---|---|
cursor | Object | the cursor position at which to retrieve a token |
session.getNextTokenOnLine(cursor) ⇒ Object
Get the token after the one at the given cursor position
Kind: instance method of Session
Returns: Object
- - the CodeMirror token after the one at the given
cursor position
Param | Type | Description |
---|---|---|
cursor | Object | cursor position before which a token should be retrieved |
session.getNextCursorOnLine() ⇒ Object
Get the next cursor position on the line, or null if there isn't one.
Kind: instance method of Session
Returns: Object
- - the cursor position
immediately following the current cursor position, or null if
none exists.
session.getNextToken(cursor, skipWhitespace) ⇒ Object
Get the token after the one at the given cursor position
Kind: instance method of Session
Returns: Object
- - the CodeMirror token after the one at the given
cursor position
Param | Type | Description |
---|---|---|
cursor | Object | cursor position after which a token should be retrieved |
skipWhitespace | Boolean | true if this should skip over whitespace tokens |
session.getQuery() ⇒ String
Calculate a query String relative to the current cursor position and token. E.g., from a state "identi--cursor--er", the query String is "identi".
Kind: instance method of Session
Returns: String
- - the query String for the current cursor position
session.getContext(cursor, [depth]) ⇒ String
Find the context of a property lookup. For example, for a lookup foo(bar, baz(quux)).prop, foo is the context.
Kind: instance method of Session
Returns: String
- - the context for the property that was looked up
Param | Type | Description |
---|---|---|
cursor | Object | the cursor position at which context information is to be retrieved |
[depth] | number | the current depth of the parenthesis stack, or undefined if the depth is 0. |
session.findPreviousDot() ⇒ Object
Kind: instance method of Session
Returns: Object
- - the line, col info for where the previous "."
in a property lookup occurred, or undefined if no previous "." was found.
session.getFunctionInfo() ⇒ Object
Determine if the caret is either within a function call or on the function call itself.
Kind: instance method of Session
Returns: Object
- inFunctionCall - true if the caret if either within a function call or on the
function call itself.
functionCallPos - the offset of the '(' character of the function call if inFunctionCall
is true, otherwise undefined.
session.getType() ⇒ Object
Get the type of the current session, i.e., whether it is a property lookup and, if so, what the context of the lookup is.
Kind: instance method of Session
Returns: Object
- - an Object consisting
of a "property" that indicates whether or not the type of
the session is a property lookup, and a "context" that
indicates the object context (as described in getContext above) of
the property lookup, or null if there is none. The context is
always null for non-property lookups.
session.getHints(query, matcher) ⇒ Object
Retrieves a list of hints for the current session based on the current scope information.
Kind: instance method of Session
Returns: Object
- An object containing:
hints
: An array of matching hints.needGuesses
: A Boolean indicating whether the caller needs to request guesses and call getHints again.
Param | Type | Description |
---|---|---|
query | String | The query prefix used to filter hints. |
matcher | StringMatcher | The class used to find query matches and sort the results. |
session.setFnType(newFnType)
Set a new function type hint.
Kind: instance method of Session
Param | Type | Description |
---|---|---|
newFnType | Object | Array of function hints |
session.setFunctionCallPos(functionCallPos)
The position of the function call for the current fnType.
Kind: instance method of Session
Param | Type | Description |
---|---|---|
functionCallPos | Object | the offset of the function call. |
session.getParameterHint() ⇒ Object
Get the function type hint. This will format the hint, showing the parameter at the cursor in bold.
Kind: instance method of Session
Returns: Object
- An Object where the
"parameters" property is an array of parameter objects;
the "currentIndex" property index of the hint the cursor is on, may be
-1 if the cursor is on the function identifier.
session.getJavascriptText() ⇒ String
Get the javascript text of the file open in the editor for this Session. For a javascript file, this is just the text of the file. For an HTML file, this will be only the text in the script tags. This is so that we can pass just the javascript text to tern, and avoid confusing it with HTML tags, since it only knows how to parse javascript.
Kind: instance method of Session
Returns: String
- - the "javascript" text that can be sent to Tern.
session.isFunctionName() ⇒ Boolean
Determine if the cursor is located in the name of a function declaration. This is so we can suppress hints when in a function name, as we do for variable and parameter declarations, but we can tell those from the token itself rather than having to look at previous tokens.
Kind: instance method of Session
Returns: Boolean
- - true if the current cursor position is in the name of a function
declaration.