Udostępnij za pośrednictwem


IVsContainedLanguageHost.GetNearestVisibleToken(TextSpan, TextSpan[]) Method

Definition

Returns the language token that is nearest the requested line.

public:
 int GetNearestVisibleToken(Microsoft::VisualStudio::TextManager::Interop::TextSpan tsSecondaryToken, cli::array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> ^ ptsPrimaryToken);
public:
 int GetNearestVisibleToken(Microsoft::VisualStudio::TextManager::Interop::TextSpan tsSecondaryToken, Platform::Array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> ^ ptsPrimaryToken);
int GetNearestVisibleToken(Microsoft::VisualStudio::TextManager::Interop::TextSpan tsSecondaryToken, std::Array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> const & ptsPrimaryToken);
public int GetNearestVisibleToken (Microsoft.VisualStudio.TextManager.Interop.TextSpan tsSecondaryToken, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] ptsPrimaryToken);
abstract member GetNearestVisibleToken : Microsoft.VisualStudio.TextManager.Interop.TextSpan * Microsoft.VisualStudio.TextManager.Interop.TextSpan[] -> int
Public Function GetNearestVisibleToken (tsSecondaryToken As TextSpan, ptsPrimaryToken As TextSpan()) As Integer

Parameters

tsSecondaryToken
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
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.

Returns

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

Remarks

COM Signature

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.

Applies to