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.
Implementations of orion.edit.contentAssist must define the following function:
Returns an Array giving possible completions that may be inserted into the editor. Result elements must be "proposal" objects having the following properties:
"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:
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 eclipse.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 = keywordsi; 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 eclipse.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();
![]() |
![]() |
![]() |
orion.edit.command | orion.edit.editor |