IVsContainedLanguageHost::GetNearestVisibleToken Method (TextSpan, array<TextSpan>^)

 

Returns the language token that is nearest the requested line.

Namespace:   Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop.8.0 (in Microsoft.VisualStudio.TextManager.Interop.8.0.dll)

int GetNearestVisibleToken(
	TextSpan tsSecondaryToken,
	array<TextSpan>^ ptsPrimaryToken
)

Parameters

tsSecondaryToken
Type: Microsoft.VisualStudio.TextManager.Interop::TextSpan

[in] A TextSpan object describing the position and extent of the token to search near. This position is based on the secondary buffer.

ptsPrimaryToken
Type: array<Microsoft.VisualStudio.TextManager.Interop::TextSpan>^

[out] Returns a TextSpan object describing the position and extent of the token that is nearest the specified token. The position is based on the primary buffer.

Return Value

Type: System::Int32

If successful, returns S_OK; otherwise, returns an error code.

From singlefileeditor.idl:

HRESULT GetNearestVisibleToken(
   [in]  TextSpan  tsSecondaryToken,
   [out] TextSpan* ptsPrimaryToken
);

If a contained language is not able to determine where to create a marker for a compile error that is visible to the user, the contained language should call the GetNearestVisibleToken method, so that the editor can provide the closest item to create marker on.

For example:

<script runat="server" language="vb">
        Sub TestSub()
</script>

Normally, Visual Basic would place the wavy underline (squiggles) indicating the point of error on the End Class statement or whatever Visual Basic code might follow the missing End Sub. However, in the above example from ASP.NET, any additional Visual Basic code is outside the visible code block. The contained language can determine this situation by calling the MapSecondaryToPrimarySpan method which fails if the text is outside of the visible range. In that case, the contained language can call the GetNearestVisibleToken method to obtain the span for the nearest visible token to put the squiggles on. In the above example, the squiggles should appear on the </script> tag and that is the span the editor returns from the GetNearestVisibleToken method.

Return to top
Show: