How to: Enable Parameter Info ToolTips

Parameter info ToolTips display parameter information about the method being typed. A method tip usually appears when the user types a parameter list token, such as an open parenthesis. You can enable Parameter info by performing the following steps:

  • Adding Parameter Information

  • Adding Parameter Triggers

This topic is based on the Visual Studio Language Package solution, which provides a basic implementation of the Babel package. For more information about creating one of these solutions, see Walkthrough: Creating a Language Service Package.

Adding Parameter Information

The startParameters, parameter, and endParameters methods support parameter information. The startParameters method should be called whenever the parse finds the parameter start token. The parameter method is called for every parameter separator found, and the endParameters method is called for the parameter end token. The following is an example of a rule in a parser.y file:

ParenArguments
    : StartArg EndArg            { g_service->matchPair($1,$2); } 
    | StartArg Arguments1 EndArg { g_service->matchPair($1,$3); }
    | StartArg Arguments1 error  
                { g_service->endParameters(@3); 
                  g_service->expectError( "unmatched parenthesis", ")" ); }
    ;

StartArg
    : '('       { g_service->startParameters($1); }
    ;

EndArg
    : ')'       { g_service->endParameters($1); }
    ;    

Arguments1
    : Expr ','  { g_service->parameter($2); }  Arguments1
    | Expr
    ;

In the language being defined, parentheses enclose a parameter list. The Arguments1 rule uses a mid-rule action (the parameter method called in the above example) to call the parameter method at the right location.

The same kind of problem occurs when calling the startParameter and endParameter methods, which is why the StartArg and EndArg productions are explicitly added.

Adding Parameter Triggers

The trigger values TriggerParamStart, TriggerParamEnd, and TriggerParamNext trigger a Parameter Info ToolTip (see TriggerClass Enumeration for more details about these and other trigger values). Simply add the relevant entries to the tokenInfoTable in the method Service::getTokenInfo. The following is an example of adding the start and end parentheses and the comma as parameter triggers:

   { '(', ClassText,  "'('", 
          CharDelimiter, TriggerParamStart | TriggerMatchBraces }, 
   { ')', ClassText,  "')'", 
          CharDelimiter, TriggerParamEnd | TriggerMatchBraces   },
   { ',', ClassText,  "','", CharDelimiter, TriggerParamNext    },     
   ...

Not all languages distinguish the parameter list open token from the parameter separator or closing token. It is acceptable to combine triggers. Although triggers start a parser action in order to display or dismiss a Parameter Info ToolTip, the distinction in triggers is only used to optimize some common cases. The parser always has the final decision as to when to show the information.

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.