CodeRush Plugins – Plugin Components

So you’ve created your base plugin project.

Now you’ll need to decide on which components are necessary to implement the functionality you’re after.

In order to do that, you’ll need at least a brief overview of some of the more common components and what they are used for.

In a nutshell these components are: Action, StringProvider, TextCommand, RefactoringProvider, CodeProvider, IssueProvider and MetricProvider.

iconActionAction
The simplest of plugin component: Actions wrap managed code which can then be bound to either mouse or keyboard shortcuts by the end user/developer. Actions can also be rendered as menu options on any of the standard Studio menus.

iconStringProviderStringProvider
Used within Templates, Selection Embedding and similar features, StringProviders return strings to the features which they are placed within. The string in question can be sourced from anywhere: Settings, Envrionment, DateTime, the Clipboard or even a Web Service. Built-in examples include «?Username», «?FieldPrefix», «?DayOfWeek», «?Paste» and «?SolutionName».

iconTextCommandTextCommand
TextCommands, like StringProviders, are used in higher level features to provide blocks of functionality to those features. They may be considered ‘Void Proc’ versions of the StringProviders, in that they are unable to return any value to said calling function. Instead they provide functionality via the current TextDocument (Internal representation of the current text file) which they can both access and affect. Examples of shipping TextCommands include: «Caret», «BlockAnchor», «AddAssemblyReference» and «Marker».

iconRefactoringProviderRefactoringProvider
This component is used to add items to the Refactor menu within the CodeRush SmartTag. The RefactoringProvider provides events both for determining if your refactoring is suitable based on the current circumstances, and also for applying the refactoring itself when it is chosen. The RefactoringProvider should be used when providing a true refactoring to the end user. ie When the operation is required to not change the functionality of the code being acted upon.

iconCodeProviderCodeProvider
The CodeProvider compliments the RefactoringProvider and is use to add items to the Code menu within the CodeRush SmartTag. The CodeProvider should be used instead of a RefactoringProvider when the operation is required to change the functionality of the code being acted upon. Examples of CodeProviders include the ‘Declare X’ range of items of the Code menu, used to declare things like variables, enums and classes based on examples of their usage.

iconIssueProviderIssueProvider
Used to define your own Code Issues (inline hints, warnings and errors) which will then be presented within the environment. This component can be combined with either the CodeProvider or RefactoringProvider in order to provide a method of fixing the raised CodeIssue. Some good examples of using this component can be found in the CR_StyleNinja community plugin.

iconCodeMetricProviderMetricProvider
This component allows you to provide an algorithm, which produces a numeric value based on a code element (usually a member of a type). Said value is then shown inline in the editor or within the Metrics Toolwindow. Examples of existing metrics shipping with CodeRush include the ‘Line Count’, ‘Cyclomatic Complexity’ and ‘Maintenance Complexity’.

This list is by no means definitive, but is intended only to represent the most commonly used components.

It should be noted that your plugin can have many of these components on it’s design surface, and is not limited to just one or indeed even just one type. Your plugin might ultimately make use of 2 Actions, 3 RefactoringProviders and a MetricProvider. However, for the purposes of these first few examples, we’ll be concentrating on just one component at a time.

In the coming posts I’ll be explaining these components in much greater detail. I’ll cover the specific use of each, and couple that with a complete example. Soon you’ll creating your own plugins to achieve all manner of clever things.

The steps here are common to all plugins, and I’ll be referring back to them from each of my plugin examples.

Next up we’ll create our first complete plugin – “DX_HelloWorld”

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.