Context sensitive auto complete list - gregfullman/VSGenero GitHub Wiki

Overview

VSGenero includes a "context-sensitive" mode for Intellisense auto-completion. This mode tries to determine the code context where you're typing, and displays a list of completions that make sense in that context. The context engine is driven by the context map, a set of rules that define how the completion list is populated. Prior to version 0.9.7.5, the context map was hardcoded within VSGenero, which meant updates to the map would only be received by the end-user when a new release was made available and downloaded.

In version 0.9.7.5, I converted the context map to a XML file that lives in the VSGenero extension folder. This allows for the user to add new context rules and update the context map with the latest map, without having to install a new version of VSGenero.

Getting the latest map

To get the latest context map, (within Visual Studio) open Tools -> Options..., and then go to Text Editor -> Genero4GL -> Intellisense. You should see this screen:

alt text

Click "Download latest contexts". This will download the latest context map from Github and update the map in Visual Studio. Note: You may not receive the latest context map if it was only updated in the last couple hours. The map is provided via GitCDN, which can take a few hours to cache the latest content. If you are in dire need of a new update and are not receiving it via this method, you can always download the raw file directly from my Github, here: https://github.com/gregfullman/VSGenero/blob/master/VSGenero/CompletionContexts.xml.

Modifying the current map

To update the current context map, you must first find the VSGenero extension folder. In C:\Users{user_name}\AppData\Local\Microsoft\VisualStudio{12.0 or 14.0}\Extensions, there will be several folders with random names. Find the folder that contains the CompletionContexts.xml file.

The CompletionContexts.xml file follows the CompletionContextSchema, found here: https://github.com/gregfullman/VSGenero/blob/master/VSGenero/CompletionContextSchema.xsd. To ensure any edits to the CompletionContexts.xml file are valid, please use this schema for validation.

For details and an example of modifying the context map, see Details.

After you're done making changes, open Tools -> Options..., and then go to Text Editor -> Genero4GL -> Intellisense. Click "Reload completion contexts". The latest changes should now be loaded into Visual Studio. If you're confident that your changes work correctly and you'd like to contribute your changes to the VSGenero project, create a Pull Request to submit your change(s) for review.

Details

The context completion map contains the following items.

ContextEntry

This element contains each map item's key information. In addition to one or more ContextPossibility elements, it has the following attributes:

  1. Entry - the TokenKind or TokenCategory just prior to the location at which the user is typing.
  2. Type - this value must be either "keyword" or "category". In reality, "keyword" is a bit of a generalization, since it also accounts for symbol tokens. However, you follow these rules:

ContextPossibility

This element must contain one or more unique elements described below:

  1. SingleTokens - defines single keyword tokens that should be included in the completion list for this context. Each keyword should be included in a Token element.
  2. ContextSetProviders - defines provider functions that should include additional entries in the completion list. For example, the GetVariables provider function retrieves all variables that would apply in the current context (i.e. global, module, and local variables). The complete set of available provider functions is listed in https://github.com/gregfullman/VSGenero/blob/master/VSGenero/CompletionContextSchema.xsd
  3. BackwardSearchItems - defines a set of "backward search scopes" that will be used to further identify the current context. These search scopes are used to disambiguate the current context by search backward past the ContextEntry's key.