Using Quick Actions (Light Bulbs) in COBOL

Quick Actions (also known as light bulbs, ) is a feature in the editor of Visual Studio 2015 or later. It enables you to quickly resolve some issues in your code, implement constructs or execute other actions.
Note: In order for the light bulbs feature to work, you must have background parsing turned on in the IDE (enabled by default).

The following Quick Action fixes are available for COBOL:

Creating or finding a missing copybook

If your code references copybooks that are not located in any of the paths defined in the copybook paths of the project, the editor provides a quick action for you to either locate the copybook manually or to create the file and add it to the project.

To use a quick action to resolve a missing copybook:

  1. Hover the COPY statement in the editor until the light bulb appears then click the light bulb icon (light bulb) to see the suggested fixes:

    GUID-8970C8CC-CD02-498D-A042-CB1C12A021E5-low.png

  2. Choose one of the suggested actions.

    If you choose to create the copybook, the IDE adds the file to your project and adds its location to the copybook paths of the project.

    If you choose to find the missing copybooks, you can browse and select the file from your file system. The path to the location of the file is then added to the copybook paths of the project.

Creating a copybook from selected lines in the code

You can use the Extract to Copybook quick action as an alternative to the Extract to Copybook context menu command in the editor:

  1. Select the lines of code you want to move into a copybook.

    Note the light bulbs feature that appears in the margin:

    GUID-CCDE9A60-FF2F-4F19-9889-9EA556587B94-low.png

  2. Click the Extract to Copybook command.
  3. Specify a name and location for the copybook when prompted and then click Save.

    This creates the copybook file and adds it to the project.

Implementing unimplemented interfaces

You can use the light bulb feature to implement interfaces in managed OO COBOL programs. To use them:

  1. Type the definition of the implementing class or value type:
    class-id MyClass implements type Interface

    At this stage the class does not implement the interface and you get an error at its name. Hover the error until the light bulb appears (light bulb).

  2. Click the light bulb to see the suggested fixes and click the command to implement the interface:

    Implement an interface

    This adds the missing interface members to the implementing class or value type.

Note: This does not support generic interfaces and does not add event members from an interface.

Rename refactoring

You can use the Rename quick action to rename a variable, a section or paragraph name or an identifier in a file or in the entire solution:

  1. In the editor, rename one occurrence of the variable or the identifier in the code.

    The light bulb icon (light bulb) appears in the margin by the line which you have edited.

    GUID-EEA151E5-E815-4615-B4B3-F5DC73D38F4F-low.png

  2. Select a quick action from the list to rename all instances of the name in the current program or across the entire solution.

Resolving unknown types

When a type is specified without fully qualifying the namespace, use the light bulb feature to resolve that type. For example, you want to use System.IO.Path::GetFullPath and you might only have the following defined in the local-storage section:

01 var1 type Path

You get an error message that Path is an unknown type in the Output window, and when you click the line for this declaration, the light bulb icon appears in the margin of the program on this line.

Hover Path until the light bulb appears then click the light bulb icon (light bulb) to see the suggested fixes. Choose the fix that applies to your code:

Resolving namespaces

Simplifying the names of types

When referencing .NET types in your code, you can either use the fully-qualified namespace or only use the simplified name and omit the namespace if the simplified name can be resolved without ambiguity. For example, instead of typing System.String, you can simply type String provided that String is not used by any other class.

The editor provides a light bulb quick action, Simplify name Type, to automatically replace the fully-qualified name with the simplified name:

GUID-713EB049-CC82-4D91-8AEA-41D5ED12830D-low.png

You can choose to simplify the current occurrence of a fully-qualified name, all occurrences of that name in the current file (click Document), or all occurrences in the current file and any copybooks displayed in the expanded copybook view in it (click Program).

Converting .NET types to portable COBOL syntax

When writing managed COBOL code that should be used on any platform, a light bulb quick action enables you to convert .NET types with a corresponding predefined managed COBOL type to COBOL predefined types - this helps write platform independent applications which you can easily export from Visual Studio and edit with Visual COBOL for Eclipse.

To help with this, use the light bulb quick action, Convert to COBOL Syntax. The quick action is available for .NET types and enables you to quickly perform conversions such as System.UInt64 to binary-double unsigned.

The editor provides a light bulb quick action, Convert to portable COBOL syntax, to automatically replace the .NET type with a COBOL predefined type:

GUID-1662B4FF-134E-45E3-B95D-125E41BD2EFE-low.png