-
Notifications
You must be signed in to change notification settings - Fork 33
Modern completion API
Contents #
- CompletionContext
- CompletionFilter
- CompletionFilterChangedEventArgs
- CompletionFilterWithState
- CompletionItem
- CompletionItemWithHighlight
- CompletionList
- CompletionPresentation
- CompletionTrigger
- CompletionTriggerReason
-
IAsyncCompletionBroker
- Commit(view,edit)
- Dismiss(view)
- IsCompletionActive(view)
- OpenOrUpdate(view,trigger,trackedEdit,triggerLocation)
- SelectDown(view)
- SelectPageDown(view)
- SelectPageUp(view)
- SelectUp(view)
- ShouldCommitCompletion(view,edit,triggerLocation)
- ShouldTriggerCompletion(view,edit,triggerLocation)
- TriggerCompletion(view,triggerLocation)
- IAsyncCompletionItemSource
- IAsyncCompletionService
- IAsyncCompletionSession
- ICompletionUI
- ICompletionUIProvider
- ImageMoniker
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
This struct is used to transfer data from IAsyncCompletionItemSource to IAsyncCompletionBroker and further to IAsyncCompletionService
Constructs CompletionContext with CompletionItem applicable to a SnapshotSpan
Name | Type | Description |
---|---|---|
items | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem} | Available completion items |
applicableSpan | Microsoft.VisualStudio.Text.SnapshotSpan | Completion list will be filtered by contents of this span |
Constructs CompletionContext with CompletionItem applicable to a SnapshotSpan and CompletionFilter available for these items.
Name | Type | Description |
---|---|---|
items | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem} | Available completion items |
applicableSpan | Microsoft.VisualStudio.Text.SnapshotSpan | Completion list will be filtered by contents of this span |
availableFilters | System.Collections.Immutable.ImmutableArray{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilter} | Completion filters available for these completion items |
#ctor(items,applicableSpan,availableFilters,useSoftSelection,useSuggestionMode,suggestionModeDescription) constructor
# =
Constructs CompletionContext with CompletionItem applicable to a SnapshotSpan, CompletionFilter available for these items and instructions on suggestion mode and soft selection.
Name | Type | Description |
---|---|---|
items | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem} | Available completion items |
applicableSpan | Microsoft.VisualStudio.Text.SnapshotSpan | Completion list will be filtered by contents of this span |
availableFilters | System.Collections.Immutable.ImmutableArray{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilter} | Completion filters available for these completion items |
useSoftSelection | System.Boolean | Whether UI should use soft selection |
useSuggestionMode | System.Boolean | Whether UI should enter suggestion mode |
suggestionModeDescription | System.String | Why suggestion mode is active. It is displayed when applicableSpan is empty. Otherwise, UI uses applicableSpan to populate the suggestion mode item. |
Location pertinent to the completion items
Filters available for the provided items
Set of completion items available at a location
Displayed when UI is in suggestion mode, yet there is no code to suggest
When set to true, the completion list will be initially soft-selected, such that only hitting Tab will commit the soft-selected item. Selecting another item will use full selection.
When set to true, the completion list will be in the "builder" mode, such that hitting Space will not commit it, but append it to the constructed item.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Identifies a filter that toggles exclusive display of associated CompletionItem.
static CompletionFilter MyFilter = new CompletionFilter("My items", "m", MyItemsImageMoniker);
These instances should be singletons, such that all CompletionItems that need to be filtered using the same filter button need to use the same instance of CompletionFilter, and this instance needs to be also referenced in AvailableFilters
Constructs an instance of
Name | Type | Description |
---|---|---|
displayText | System.String | |
accessKey | System.String | |
icon | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.ImageMoniker |
Key used to create a keyboard shortcut that toggles this filter.
Name of this filter.
ImageMoniker that represents this filter.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
This class is used to notify completion's logic of selection change in the filter UI
Constructs instance of CompletionFilterChangedEventArgs.
Name | Type | Description |
---|---|---|
filters | System.Collections.Immutable.ImmutableArray{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilterWithState} | Current state of the filters |
Current state of the filters
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Immutable data transfer object used to communicate between the completion session and completion UI
Constructs a new instance of CompletionFilterWithState.
Name | Type | Description |
---|---|---|
filter | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilter | Reference to CompletionFilter |
isAvailable | System.Boolean | Whether this CompletionFilter is available |
Constructs a new instance of CompletionFilterWithState when selected state is known.
Name | Type | Description |
---|---|---|
filter | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilter | Reference to CompletionFilter |
isAvailable | System.Boolean | Whether this CompletionFilter is available |
isSelected | System.Boolean | Whether this CompletionFilter is selected |
Reference to the completion filter
Whether the filter is available. Filter should be available when there are visible CompletionItems that define this Filter in their Filters
Whether the filter is selected by the user.
Returns instance of CompletionFilterWithState with specified IsAvailable
Updated instance of CompletionFilterWithState
Name | Type | Description |
---|---|---|
availability | System.Boolean | Value to use for IsAvailable |
Returns instance of CompletionFilterWithState with specified IsSelected
Updated instance of CompletionFilterWithState
Name | Type | Description |
---|---|---|
availability | System.Boolean | Value to use for IsSelected |
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
This class, returned from IAsyncCompletionItemSource, represents a single entry to be displayed in the completion UI. This class implements IPropertyOwner
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Wraps CompletionItem with information about highlighted parts of its DisplayText. The CompletionItem property may be null.
Constructs CompletionItemWithHighlight without any highlighting.
Name | Type | Description |
---|---|---|
completionItem | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem | Instance of CompletionItem |
Constructs CompletionItemWithHighlight with given highlighting.
Name | Type | Description |
---|---|---|
completionItem | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem | Instance of CompletionItem |
highlightedSpans | System.Collections.Immutable.ImmutableArray{Microsoft.VisualStudio.Text.Span} | Spans of DisplayText to highlight |
Represents no CompletionItem
The completion item
Which parts of DisplayText to highlight
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
This struct, returned from IAsyncCompletionService, contains completion items to display in the UI, recommended item to display and available filters.
Constructs CompletionList with completion filters.
Name | Type | Description |
---|---|---|
items | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItemWithHighlight} | Items to display in the completion UI. |
selectedItemIndex | System.Int32 | Recommended item index to select. |
filters | System.Collections.Immutable.ImmutableArray{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilterWithState} | Completion filters with their availability and selection state. |
Constructs CompletionList without completion filters.
Name | Type | Description |
---|---|---|
items | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItemWithHighlight} | Items to display in the completion UI. |
selectedItemIndex | System.Int32 | Recommended item index to select. |
Completion filters with their availability and selection state.
Items to display in the completion UI.
Recommended item index to select.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
This struct, contains completion items, filters and other pieces of information used by ICompletionUI to render the completion UI.
#ctor(items,filters,applicableSpan,useSoftSelection,useSuggestionMode,selectSuggestionMode,selectedItemIndex,suggestionModeItem) constructor
# =
Constructs CompletionPresentation
Name | Type | Description |
---|---|---|
items | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItemWithHighlight} | Completion items to display with their highlighted spans |
filters | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilterWithState} | Completion filters with their available and selected state |
applicableSpan | Microsoft.VisualStudio.Text.ITrackingSpan | Span pertinent to the completion session |
useSoftSelection | System.Boolean | Controls whether selected item should be soft selected |
useSuggestionMode | System.Boolean | Controls whether suggestion mode item is visible |
selectSuggestionMode | System.Boolean | Controls whether suggestion mode item is selected |
selectedItemIndex | System.Int32 | Controls which item is selected. Use -1 in suggestion mode |
suggestionModeItem | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItemWithHighlight | Suggestion mode item to display |
Span pertinent to the completion session.
Completion filters with their available and selected state.
Completion items to display with their highlighted spans.
Controls which item is selected. Use -1 in suggestion mode.
Controls whether suggestion mode item is selected.
Suggestion mode item to display.
Controls whether selected item should be soft selected.
Controls whether suggestion mode item is visible.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
What triggered the completion (but not where it happened)
Creates a CompletionTrigger associated with a text edit
Name | Type | Description |
---|---|---|
kind | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionTriggerReason | The kind of action that triggered completion to start |
edit | System.String | Associated text edit |
Creates a CompletionTrigger not associated with a text edit
Name | Type | Description |
---|---|---|
kind | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionTriggerReason | The kind of action that triggered completion to start |
The text edit associated with the triggering action.
The reason that completion was started.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
The kind of action that triggered completion to start.
Completion was triggered by a direct invocation of the completion feature (ctrl-j in Visual Studio).
Completion was triggered via an action deleting a character from the document.
Completion was triggered via an action inserting a character into the document.
Completion was triggered with a request to commit if a unique item would be selected (ctrl-space in Visual Studio).
Completion was triggered for snippets only.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Represents a class that manages the completion feature.
[Export(typeof(IAsyncCompletionBroker))] public class MyCompletionBroker : IAsyncCompletionBroker
This is a MEF component and there should be only one exported at a time.
Commits selected item, passing in associated text edit, then dismisses the UI
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
edit | System.String | The text edit which caused this action |
Immediately dismisses completion and closes its UI.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
Returns whether completion is active in given view
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
Dispatches a worker to compute, sort and filter CompletionItems to be displayed display in the UI, and displays the UI. This method is called on initial text edit and on subsequent typing events.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
trigger | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionTrigger | What caused completion |
trackedEdit | Microsoft.VisualStudio.Text.ITrackingSpan | Span which tracks the location of the completion session and user's input |
triggerLocation | Microsoft.VisualStudio.Text.SnapshotPoint | Location of the trigger on the view's top buffer |
Selects an item below the current item
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
Select an item one page below the current item. Page size is determined by ICompletionUIProvider.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
Select an item one page above the current item. Page size is determined by ICompletionUIProvider.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
Selects an item above the current item
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
Returns whether completion should commit, given the originating text view and the typed character
False if there is no completion or typed character is not a commit character
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
edit | System.String | The text edit to evaluate |
triggerLocation | Microsoft.VisualStudio.Text.SnapshotPoint | Location of the text edit on the view's top buffer |
Returns whether completion should trigger as a result of the text edit.
true if completion should trigger
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
edit | System.String | The text edit to evaluate |
triggerLocation | Microsoft.VisualStudio.Text.SnapshotPoint | Location of the text edit on the view's top buffer |
Activates completion. Must be called before other methods.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
triggerLocation | Microsoft.VisualStudio.Text.SnapshotPoint | Location of completion on the view's top buffer. Used to pick relevant IAsyncCompletionItemSources and IAsyncCompletionService |
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Represents a class that provides CompletionItems and other information relevant to the completion feature at a specific SnapshotPoint
[Export(typeof(IAsyncCompletionItemSource))] [Name(nameof(MyCompletionItemSource))] [ContentType("text")] public class MyCompletionItemSource : IAsyncCompletionItemSource
This is a MEF component and should be exported with [ContentType] and [Name] attributes. Completion feature will request data from all exported IAsyncCompletionItemSources whose ContentType matches content type of any buffer in the completion's trigger location.
Custom commit behavior for completion item created by this completion item source. Called if CustomCommit is set.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
buffer | Microsoft.VisualStudio.Text.ITextBuffer | Reference to the buffer with matching content type to perform text edits etc. |
item | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem | Which completion item is to be applied |
applicableSpan | Microsoft.VisualStudio.Text.ITrackingSpan | Span augmented by completion |
edit | System.String | Text change associated with this commit |
Called once per completion session to fetch the set of all completion items available at a given location.
A struct that holds completion items and applicable span
Name | Type | Description |
---|---|---|
trigger | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionTrigger | What caused the completion |
triggerLocation | Microsoft.VisualStudio.Text.SnapshotPoint | Where completion was triggered |
Returns tooltip associated with provided completion item
Return type is pending what we agree to describe GUI in cross platform fashion
Name | Type | Description |
---|---|---|
item | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem |
Returns characters that may commit completion. When text edit matches one of these characters, ShouldCommitCompletion is called.
This method has no parameters.
Fired when a view, previously involved in completion, closes
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that closes |
Returns whether this character is a commit character in a given location.
This method has no parameters.
Returns whether this character is a trigger character in a given context
This method has no parameters.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Represents a class that filters and sorts available CompletionItems given the current state of the editor. It also declares which completion filters are available for the returned subset of CompletionItems.
[Export(typeof(IAsyncCompletionService))] [Name(nameof(MyCompletionService))] [ContentType("text")] [Order(Before = "OtherCompletionService")] public class MyCompletionService : IAsyncCompletionService
This is a MEF component and should be exported with [ContentType] and [Name] attributes and optional [Order] attribute. An instance of IAsyncCompletionService is selected first by matching ContentType with content type of the view's top buffer, and then by Order. Only one IAsyncCompletionService is used in a given view.
This method is first called before completion is about to appear, and then on subsequent typing events and when user toggles completion filters. user's input tracked with ITrackingSpan on given ITextSnapshot and a collection of CompletionFilterWithStates that indicate user's filter selection.
Instance of CompletionList that contains completion items to render, filters to display and recommended item to select
Name | Type | Description |
---|---|---|
originalList | System.Collections.Generic.IEnumerable{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem} | Set of CompletionItems to filter and sort |
snapshot | Microsoft.VisualStudio.Text.ITextSnapshot | Current text snapshot of the view's top buffer |
applicableToSpan | Microsoft.VisualStudio.Text.ITrackingSpan | Span which tracks the location of the completion session and user's input |
availableFilters | System.Collections.Immutable.ImmutableArray{Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionFilterWithState} | Filters, their availability and selection state |
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Represents a class that tracks completion within an editor. Constructed by an implementation of IAsyncCompletionBroker
Commits the currently selected CompletionItem. Runs on UI thread.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
edit | System.String | The text edit which caused this action. May be null. |
Commits the specified CompletionItem. Runs on UI thread.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
edit | System.String | The text edit which caused this action. May be null. |
itemToCommit | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionItem | Specific item to commit. |
Hides the UI and cleans up resources.
This method has no parameters.
Request completion to be opened or updated in a given location, completion items filtered and sorted, and the UI updated.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | View that hosts completion and relevant buffers |
trigger | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionTrigger | What caused completion |
applicableSpan | Microsoft.VisualStudio.Text.ITrackingSpan | Span which tracks the location of the completion session and user's input |
triggerLocation | Microsoft.VisualStudio.Text.SnapshotPoint | Location of the trigger on the view's top buffer |
Selects an item below the current item
This method has no parameters.
Select an item one page below the current item. Page size is determined by ICompletionUIProvider.
This method has no parameters.
Select an item one page above the current item. Page size is determined by ICompletionUIProvider.
This method has no parameters.
Selects an item above the current item
This method has no parameters.
Returns whether given text edit should result in committing this session.
Name | Type | Description |
---|---|---|
view | Microsoft.VisualStudio.Text.Editor.ITextView | |
edit | System.String | |
triggerLocation | Microsoft.VisualStudio.Text.SnapshotPoint | Location on the view's top buffer |
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Represents a class that manages user interface for the completion feature
Hides the completion UI
This method has no parameters.
Opens the UI and displays provided data
Name | Type | Description |
---|---|---|
presentation | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionPresentation |
Selects item with the specified index
Name | Type | Description |
---|---|---|
selectedIndex | System.Int32 | Index of item to select. -1 removes selection. |
Displays provided data on the UI
Name | Type | Description |
---|---|---|
presentation | Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition.CompletionPresentation |
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Represents a class that produces instances of ICompletionUI
[Export(typeof(ICompletionUIFactory))] [Name(nameof(MyCompletionUIFactory))] [ContentType("any")] [Order(Before = nameof(MyOtherCompletionUIFactory))] public class MyCompletionUIFactory : ICompletionUIFactory
This is a MEF component and should be exported with [ContentType] and [Name] attributes and optional [Order] attribute. An instance of ICompletionUIProvider is selected first by matching ContentType with content type of the view's top buffer, and then by Order. Only one ICompletionUIProvider is used in a given view.
Declares size of the jump when user presses PageUp and PageDown keys.
This value is read by the controller that processes scrolling and selection. The ICompletionUI is just a view that doesn't participate in keyboard scrolling.
Returns instance of ICompletionUI that will host completion for given ITextView
Instance of ICompletionUI
Name | Type | Description |
---|---|---|
textView | Microsoft.VisualStudio.Text.Editor.ITextView | Text view that will host the completion. Completion acts on buffers of this view. |
It is encouraged to reuse the UI over creating new UI each time this method is called.
Microsoft.VisualStudio.Language.Intellisense.Prototype.Definition
Contains the GUID and ID of the image.
The GUID of the moniker.
The ID of the moniker.