Compartir a través de


Parameter Info in a legacy language service 1

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

The IntelliSense Parameter Info tooltip provides users with hints about where they are in a language construct.

Legacy language services are implemented as part of a VSPackage, but the newer way to implement language service features is to use MEF extensions. To find out more, see Extending the Editor and Language Services.

Note

We recommend that you begin to use the new editor API as soon as possible. This will improve the performance of your language service and let you take advantage of new editor features.

How Parameter Info Tooltips Work

When you type a statement in the editor, the VSPackage displays a small tooltip window containing the definition of the statement being typed. For example, if you type a Microsoft Foundation Classes (MFC) statement (such as pMainFrame ->UpdateWindow) and press the opening parenthesis key to begin listing parameters, a method tip appears displaying the definition of the UpdateWindow method.

Parameter Info tooltips are usually used in conjunction with statement completion. They are most useful for languages that have parameters or other formatted information after the method name or keyword.

The Parameter Info tooltips are initiated by the language service through command interception. To intercept user characters, your language service object must implement the IOleCommandTarget interface and pass the text view a pointer to your IOleCommandTarget implementation, by calling the AddCommandFilter method in the IVsTextView interface. The command filter intercepts commands that you type into the code window. Monitor the command information to know when to display parameter information to the user. You can use the same command filter for statement completion, error markers, and so forth.

When you type a keyword for which the language service can provide hints, then the language service creates an IVsMethodTipWindow object and calls the UpdateTipWindow method in the IVsTextView interface to notify the IDE to display a hint. Create the IVsMethodTipWindow object using VSLocalCreateInstance and specifying the coclass CLSID_VsMethodTipWindow. VsLocalCreateInstance is a function defined in the header file vsdoc.h that calls QueryService for the local registry and calls CreateInstance on this object for the CLSID_VsMethodTipWindow.

Providing a Method Tip

To provide a method tip, call the SetMethodData method in the IVsMethodTipWindow interface, passing it your implementation of the IVsMethodData interface.

When your IVsMethodData class is invoked, its methods are called in the following order:

  • GetContextStream

    Returns the position and length of the relevant data in the current text buffer. This instructs the IDE to not obscure that data with the tooltip window.

  • GetCurMethod

    Returns the method number (zero-based index) you want to be displayed initially. For example, if you return zero, then the first overloaded method is initially presented.

  • GetOverloadCount

    Returns the number of overloaded methods that are applicable in the current context. If you return a value greater than 1 for this method, then the text view displays up and down arrows for you. If you click the down arrow, the IDE calls the NextMethod method. If you click the up arrow, the IDE calls the PrevMethod method.

  • GetMethodText

    The text of the Parameter Info tooltip is constructed during several calls to the GetMethodText and GetParameterText methods.

  • GetParameterCount

    Returns the number of parameters to display in the method.

  • GetParameterText

    If you return a method number corresponding with the overload you want displayed, this method is called, followed by a call to the UpdateView method.

  • UpdateView

    Informs your language service to update the editor when a method tip is displayed. In the UpdateView method, call the following:

    <pTxWin> ->UpdateTipWindow(<pTip>, UTW_CONTENTCHANGED | UTW_CONTEXTCHANGED).
    
  • OnDismiss

    You receive a call to the OnDismiss method when you close the method tip window.