Skip to content

added caption field to Completion #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"dependencies": {
"purescript-console": "^0.1.1",
"purescript-dom": "^0.2.10",
"purescript-dom": "^0.2.12",
"purescript-arrays": "^0.4.3",
"purescript-foreign": "^0.7.2",
"purescript-nullable": "^0.2.1",
Expand Down
2 changes: 2 additions & 0 deletions example/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ main = onLoad $ do
(\_ _ _ inp cb -> do
cb $ pure [ { value: inp <> "!!"
, score: 100.0
, caption: pure "???"
, meta: "!!"
}
, { value: "abcde"
, score: 200.0
, caption: Nothing
, meta: "abcde"
} ] )
LanguageTools.addCompleter completer languageTools
Expand Down
22 changes: 18 additions & 4 deletions src/Ace/Ext/LanguageTools/Completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@ exports.mkCompleterImpl = function(getCompletionCb, isJust, fromJust) {
getCompletions: function(editor, session, pos, prefix, callback) {
return getCompletionCb(editor)(session)(pos)(prefix)(function(mb){
return function() {
if (isJust(mb)) {
return callback(null, fromJust(mb));
}
else {
if (!isJust(mb)) {
return callback("Error in getCompletion", null);

}
var result = [],
extracted = fromJust(mb),
i = 0,
item;
for (i; i < extracted.length; i++) {
item = extracted[i];
if (isJust(item.caption)) {
item.caption = fromJust(item.caption);
}
else {
item.caption = undefined;
}
result.push(item);
}
return callback(null, result);

};
})();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Ace/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Control.Bind ((>=>))
import Data.Either (Either(..))
import Data.Foreign (F(), ForeignError(..), readString)
import Data.Foreign.Class (IsForeign, readProp)
import Data.Maybe (Maybe())

type AnchorEvent =
{ old :: Position
Expand Down Expand Up @@ -145,4 +146,5 @@ type Completion =
{ value :: String
, score :: Number
, meta :: String
, caption :: Maybe String
}