Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
Marco Antonio Arruda edited this page Jul 4, 2017 · 13 revisions

Use the API

API version: 1.1

Your plugin can add by several ways suggestions.

CompletePlus uses amplify.js to get suggestion of other plugins.

  • amplify.publish("Complete.Init"); - called after loading of CompletePlus

  • amplify.publish("Complete.Normal", publishObj); and

  • amplify.publish("Complete.Major", publishObj); both called every time CompletePlus gets called or suggestions get updated

  • amplify.publish( "Complete.Session", publishObj); - called each time complete dialog gets visible

  • publishObj contains:

  • the current prefix

  • the current syntax of the file

  • the content before the cursor

  • the text of the current line

  • the current token

  • the current position of the cursor

  • the current file

{"prefix", "before", "syntax", "line", "token", "position", "file"}

Use amplify to subscribe to a publication and the following functions to contribute suggestions

bool pluginInit(suggestion)

These suggestions get selected and ranked by CompletePlus. Use this for suggestions you want to make available every time CompletePlus is called.

  • suggestion - (Required) - Either suggestionObject or an array of suggestionObjects

bool pluginNormal(suggestion)

These suggestions get selected and ranked by CompletePlus. Use this normally for your suggestions.

  • suggestion - (Required) - Either suggestionObject or an array of suggestionObjects

bool pluginSession(suggestion)

These suggestions get selected and ranked by CompletePlus. In difference to pluginNormal these ones are saved until autocomplete either gets closed or is completed.

  • suggestion - (Required) - Either suggestionObject or an array of suggestionObjects

bool pluginMajor(suggestion)

! Do not use this function for every suggestion!

These suggesstions are displayed without any ranking or selection. Use the published pieces of information to select an appropriated suggestion.

  • suggestion - (Required) - Either suggestionObject or an array of suggestionObjects

Life duration of a suggestion

Suggestions of pluginNormal and pluginMajor were delete every time the user types a letter or close the autocomplete.

Structure of a suggestionObject

{"title": Title of the suggestion - displayed in the autocomplete dialog,
"suggestion": Suggestion text - Information to rank and select the suggestions,
"ranking": Text to rank the suggestion,
"callback": Callback topic for amplify (If callback is an emptry string (""), CompletePlus completes suggestion with suggestion information),
"isSnippet": Wheater the suggestion is an snippet or not}

Parse a suggestion

To parse a suggestion use codiad.Complete.pluginParser(suggestion, ranking, title, callback, isSnippet)

  • suggestion - (Required) - {String} - Suggestion text
  • ranking - (Optional) - {String} - Text to rank the suggestion, if not given or null, ranking = suggestion
  • title - (Optional) - {String} - Title to display in the autocomplete dialog, if not given or null, title = suggestion
  • callback - (Optional) - {String} - Callback topic for amplify, if not given or null, CompletePlus will finish the completion itself
  • isSnippet - (Optional) - {Boolean} - Wheater the suggestion is an snippet or not (snippets allows f.e. tabstops)

Replace prefix after callback

To replace the prefix use codiad.Complete.replacePrefix(newValue, isSnippet)

  • newValue - (Required) - {String} - Text to replace prefix with
  • isSnippet - (Optional) - {Boolean} - If true run suggestion as snippet

Examples

init: function() {
  amplify.subscribe("Complete.Normal", function(publishObj) {
    if (publishObj.syntax == "php") {
      var suggestion = codiad.Complete.pluginParser("strtolower");
      codiad.Complete.pluginNormal(suggestion);
});}