CodeSnippetProvider Class
Implements a code snippet provider that can manage the available code snippets and handle requests for display of IntelliPrompt code snippet sessions.
public class CodeSnippetProvider : ICodeSnippetProvider, IOrderable, IKeyedObject, IEditorViewKeyInputEventSink, ITextViewLifecycleEventSink, ITextViewTaggerProvider
- Inheritance:
- object object
- Implements:
- ICodeSnippetProvider IOrderable IKeyedObject IEditorViewKeyInputEventSink ITextViewLifecycleEventSink ITextViewTaggerProvider
Remarks
Instances of this object can be registered with an ISyntaxLanguage using the RegisterService(object, object) method. Once an instance is registered with the language as a service, its features can be used by the language.
Constructors
CodeSnippetProvider()
Initializes a new instance of the CodeSnippetProvider
class.
public CodeSnippetProvider()
CodeSnippetProvider(string)
Initializes a new instance of the CodeSnippetProvider
class.
public CodeSnippetProvider(string key)
Parameter | Type | Description |
---|---|---|
key | string | The string-based key that identifies the provider. |
CodeSnippetProvider(string, params Ordering[])
Initializes a new instance of the CodeSnippetProvider
class.
public CodeSnippetProvider(string key, params Ordering[] orderings)
Parameter | Type | Description |
---|---|---|
key | string | The string-based key that identifies the provider. |
orderings | Ordering[] | The array of Ordering objects, used to determine how this object is positioned relative to other objects. |
Properties
IsCaseSensitive
Gets or sets whether code snippet shortcut matching requires a case-sensitive match.
public bool IsCaseSensitive { get; set; }
Property Value
- bool:
true
if code snippet shortcut matching requires a case-sensitive match; otherwise,false
. The default value istrue
.
Key
Gets the string-based key that identifies the provider.
public string Key { get; }
Property Value
- string:
The string-based key that identifies the provider.
Orderings
Gets the collection of Ordering objects, used to determine how this object is positioned relative to other objects.
public IEnumerable<Ordering> Orderings { get; }
Property Value
- IEnumerable<Ordering>:
The collection of Ordering objects, used to determine how this object is positioned relative to other objects.
RootFolder
Gets or sets the root ICodeSnippetFolder containing code snippets that are accessible by this provider.
public ICodeSnippetFolder RootFolder { get; set; }
Property Value
- ICodeSnippetFolder:
The root ICodeSnippetFolder containing code snippets that are accessible by this provider.
Methods
CheckForShortcut(IEditorView)
Checks for a code snippet shortcut before the caret and opens a template session if one was found.
protected bool CheckForShortcut(IEditorView view)
Parameter | Type | Description |
---|---|---|
view | IEditorView | The IEditorView to examine. |
Returns
- bool:
true
if a template session was opened; otherwise,false
.
CreateSelectionSession(ICodeSnippetFolder, CodeSnippetTypes)
Creates an ICodeSnippetSelectionSession for use with a RequestSelectionSession(IEditorView, CodeSnippetTypes) call.
protected virtual ICodeSnippetSelectionSession CreateSelectionSession(ICodeSnippetFolder rootFolder, CodeSnippetTypes snippetType)
Parameter | Type | Description |
---|---|---|
rootFolder | ICodeSnippetFolder | The root ICodeSnippetFolder to display. |
snippetType | CodeSnippetTypes | A CodeSnippetTypes indicating the type of code snippets to include. |
Returns
- ICodeSnippetSelectionSession:
The ICodeSnippetSelectionSession that was created.
GetPossibleShortcutSnapshotRange(TextSnapshotOffset)
Returns a possible code snippet shortcut TextSnapshotRange, located immediately before the specified TextSnapshotOffset.
protected virtual TextSnapshotRange GetPossibleShortcutSnapshotRange(TextSnapshotOffset snapshotOffset)
Parameter | Type | Description |
---|---|---|
snapshotOffset | TextSnapshotOffset | The TextSnapshotOffset to examine. |
Returns
- TextSnapshotRange:
The TextSnapshotRange of the possible shortcut; or
TextSnapshotRange.Deleted
if there is no possible shortcut.
Remarks
Language implementations may wish to inherit this class and override this method to ensure the shortcut is not within a comment or other literal.
OnViewKeyDown(IEditorView, KeyEventArgs)
Occurs when a key is pressed down while focus is in the specified IEditorView.
protected virtual void OnViewKeyDown(IEditorView view, KeyEventArgs e)
Parameter | Type | Description |
---|---|---|
view | IEditorView | The IEditorView that received the event. |
e | KeyEventArgs | The |
OnViewKeyUp(IEditorView, KeyEventArgs)
Occurs when a key is released while focus is in the specified IEditorView.
protected virtual void OnViewKeyUp(IEditorView view, KeyEventArgs e)
Parameter | Type | Description |
---|---|---|
view | IEditorView | The IEditorView that received the event. |
e | KeyEventArgs | The |
RequestSelectionSession(IEditorView, CodeSnippetTypes)
Requests that an ICodeSnippetSelectionSession be opened for the specified IEditorView.
public bool RequestSelectionSession(IEditorView view, CodeSnippetTypes snippetType)
Parameter | Type | Description |
---|---|---|
view | IEditorView | The IEditorView that will host the session. |
snippetType | CodeSnippetTypes | A CodeSnippetTypes indicating the type of code snippets to include. |
Returns
- bool:
true
if a session was opened; otherwise,false
.
RequestTemplateSession(IEditorView, ICodeSnippet)
Requests that an ICodeSnippetTemplateSession be opened for the specified IEditorView.
public bool RequestTemplateSession(IEditorView view, ICodeSnippet codeSnippet)
Parameter | Type | Description |
---|---|---|
view | IEditorView | The IEditorView that will host the session. |
codeSnippet | ICodeSnippet | The ICodeSnippet template to use. |
Returns
- bool:
true
if a session was opened; otherwise,false
.