IBabelService::ColorLine Method
Returns colorization information for the specified line.
HRESULT ColorLine (
BSTR line,
IColorSink* sink,
long* state
);
Parameters
line
[in] Specifies the line of text to colorize.sink
[in] If not NULL, specifies an IColorSink Interface object that is used to set the color information for each token in the line.state
[in, out] Specifies the state at the end of the previous line and is used to set the new state at the end of the processed line.
Return Value
If the method succeeds, it returns S_OK. If it fails, it returns an error code.
Remarks
This method is called from the IColorSink Interface's implementation of the ColorizeLine method in the IVsColorizer interface, which Visual Studio calls to colorize a line of text. The IBabelService::ColorLine method parses the given line of text for each token and calls the IColorSink::Colorize Method to set the token information.
If the sink parameter is NULL, this method must still parse the line and return the state at the end of the line. The incoming state parameter is guaranteed to be the state from the end of the previous line or, if there is no previous line, the value returned from the GetStartState method (typically 0) in the IVsColorizer interface.
Example
Here is the default Babel implementation of this method. The switchBuffer method makes the incoming line of text available to the lexer for tokenizing. The yyleng variable is the length of the token just parsed.
STDMETHODIMP StdService::ColorLine( in BSTR line,
in IColorSink* sink,
inout long* state )
{
//TRACE(L"StdService::ColorLine");
if (!state) return E_POINTER;
enterLexer();
{
switchBuffer( m_lexerBuffer
, *state
, (line ? SysStringLen(line) : 0)
, line
, NULL
, ReasonColorize );
if (line)
{
int pos = 0;
Token token;
while ( (token = nextToken()) != 0)
{
if (sink)
{
const TokenInfo* tokenInfo = lookupTokenInfo(token);
sink->Colorize( pos
, pos + yyleng - 1
, tokenInfo->colorClass
, tokenInfo->charClass
, tokenInfo->trigger );
pos += yyleng;
}
}
}
*state = doneBuffer();
}
leaveLexer();
return S_OK;
};