orion.edit.contentAssist | ||
---|---|---|
![]() |
![]() |
|
orion.edit.command | orion.edit.editor |
The orion.edit.contentAssist
service contributes content assist providers to the editor. A content assist provider produces suggestions for text that may be inserted into the editor at a given point. Providers are invoked when the user triggers the "content assist" action by pressing Ctrl+Space in the editor.
ObjectReference
The
Editor Context object.
Object
String
The line delimiter being used in the editor (CRLF, LF, etc.)
String
The leading whitespace at the start of the line.
Number
The text of the line.
Number
The offset at which content assist is being requested. Relative to the document.
String
The substring extending from the first non-word character preceding the editing caret up to the editing caret. This may give a clue about what the user was in the process of typing. It can be used to narrow down the results to be returned. The prefix is just a guess; it is not appropriate for all types of document, depending on their syntax rules.
orion.editor.Selection
The current selection in the editor.
String
The tab character being used in the editor. Typical values are a Tab character, or a sequence of four spaces.
String
The entire buffer being edited.
Number
Offset in the text buffer at which content assist is being invoked.
Object
Additional contextual information about the content assist invocation. This object has the following properties:
String
Text of the entire line that the editing caret is on.
String
The substring extending from the first non-word character preceding the editing caret up to the editing caret. This may give a clue about what the user intended to type, and can be used to narrow down the results to be returned. The prefix is just a guess; it is not appropriate for all types of document, depending on their syntax rules.
orion.editor.Selection
The current selection in the editor.
Returns an Array
giving possible completions that may be inserted into the editor. Result elements must be "proposal" objects having the following properties:
String
completion text that will be inserted in the editor if chosen. The text is inserted at the offset.String
describing the completion. This text will be shown in the content assist popup.Array
of positions within the completion proposal that require user input. Supplying this property will cause the editor to enter linked mode, and the user can use the Tab key to iterate through the regions of the proposal that require user input. For example if the completion is a function, the positions could indicate the function arguments that need to be supplied. Entries in this position array must be objects with two integer properties: offset, and length describing the regions requiring user input.Number
indicating the offset the cursor should have in the document after the completion is inserted. If this value is not supplied, the cursor will be positioned at the end of the inserted text."default"
(no styling, also used if this property is not present), "emphasis"
(proposal displayed in bold), "noemphasis"
(proposal is greyed out with a colored background), "hr"
(proposal displayed as a <hr/> and is not selectable by up and down arrows).Alternatively, a Deferred may be returned, which allows the suggestions to be computed asynchronously.
Implementations of orion.edit.contentAssist
must define the following attributes:
String
Name for the content assist provider.Array
An array of
Content Type IDs that this provider can provide content assist for. The provider's computeProposals
function will be called only for files having one of these content types.
The example below provides content assist suggestions for files whose name ends in .js
. It offers JavaScript keywords as suggestions, by checking them against the prefix provided by the content assist engine.
var provider = new orion.PluginProvider(); provider.registerServiceProvider("orion.edit.contentAssist", { computeProposals: function(buffer, offset, context) { var keywords = [ "break", "case", "catch", "continue", "debugger", "default", "delete", "do", "else", "finally", "for", "function", "if", "in", "instanceof", "new", "return", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with" ]; var proposals = []; for (var i=0; i < keywords.length; i++) { var keyword = keywords[i]; if (keyword.indexOf(context.prefix) === 0) { proposals.push({ proposal: keyword.substring(context.prefix.length), description: keyword }); } } return proposals; } }, { name: "JavaScript content assist", contentType: ["application/javascript"] }); provider.connect();
The example below will provide completion on the character 'a' that will insert an HTML anchor element. After completion the cursor will be positioned within the href
attribute.
var provider = new orion.PluginProvider(); provider.registerServiceProvider('orion.edit.contentAssist', { computeProposals: function(buffer, offset, context) { var proposals = []; if (context.prefix === 'a') { proposals.push({ proposal: ' href=""></a>', description: '<a></a> - HTML anchor element', escapePosition: offset+7}); } return proposals; }, { name: 'HTML content assist', contentType: ['text/html'] }); provider.connect();
Here is an identical example to the HTML provider, but written against the Orion 4.0 API:
define(["orion/plugin"], function(PluginProvider) { var provider = new PluginProvider(); provider.registerServiceProvider('orion.edit.contentAssist', { computeContentAssist: function(editorContext, options) { var proposals = []; if (options.prefix === 'a') { proposals.push({ proposal: ' href=""></a>', description: '<a></a> - HTML anchor element', escapePosition: offset+7}); } return proposals; }, { name: 'HTML content assist', contentType: ['text/html'] }); provider.connect(); });
More advanced content assist providers will generally use the buffer text or the AST provided in the editorContext object.
![]() |
![]() |
![]() |
orion.edit.command | orion.edit.editor |