Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 521635 - Provide keyword content assist for async / await (#166)
  • Loading branch information
mrennie committed Aug 30, 2017
1 parent c5c5e88 commit 8675913
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
Expand Up @@ -176,6 +176,8 @@ define([
});

var operators = {
'async': true,
'await': true,
'delete': true,
'new': true,
'instanceof': true,
Expand All @@ -194,6 +196,10 @@ define([
function getKeywordLink(keyword) {
var key = keyword;
switch(keyword) {
case 'async': {
key = 'async_function';
break;
}
case 'do': {
key = 'do...while'; //$NON-NLS-1$
break;
Expand Down
Expand Up @@ -296,6 +296,8 @@ define({
'plugins': 'The plugins field may hold object used to load and configure Tern plugins.',
'commonjsPluginName': 'CommonJS',
'commonjsPluginDescription': 'Plug-in that handles CommonJS-style dependency resolution.',
'asyncAwaitPluginName': 'Early-access async / await support in Tern',
'asyncAwaitPluginDescription': 'Provides early-access support for async / await in Tern prior to an official implementation.',
'ternDocPluginName': 'Doc Comments',
'ternDocPluginDescription': 'Tern plug-in to parse and use JSDoc-like comments for inferencing',
'ternCompleteStringsPluginName': 'String Completion',
Expand Down
Expand Up @@ -47,6 +47,7 @@ define([
"javascript/ternPlugins/quickfixes",
"javascript/ternPlugins/beautifier",
"javascript/ternPlugins/resolver",
"javascript/ternPlugins/async_await" //TODO remove once Tern provides built-in support
], function(TernMetadata, ecma5, ecma6, ecma7, browser, chai) {
var defs = [ecma5, ecma6, ecma7, browser, chai];

Expand Down
Expand Up @@ -65,6 +65,11 @@ define([
}),
plugins: Object.freeze({
required: {
async_await: {
name: Messages.asyncAwaitPluginName,
description: Messages.asyncAwaitPluginDescription,
version: "1.0.0"
},
doc_comment: {
name: Messages["ternDocPluginName"],
description: Messages["ternDocPluginDescription"],
Expand Down
@@ -0,0 +1,53 @@
/*******************************************************************************
* @license
* Copyright (c) 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
* License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html).
*
* Contributors:
* IBM Corporation - Allow original requirejs plugin to find files in Orion workspace
*******************************************************************************/
/* eslint-disable missing-nls */
/*eslint-env node, amd*/
/*globals tern tern*/
define([
"tern/lib/tern",
"javascript/finder"
], function(tern, Finder) {

tern.registerPlugin("async_await", /* @callback */ function(server, options) {
var cachedQuery;

return {
passes: {
/**
* @callback
*/
completion: function(file, query) {
cachedQuery = query;
},
/**
* @callback
*/
variableCompletion: function(file, start, end, gather) {
if(cachedQuery.ecma >= 9 && (cachedQuery.includeKeywords || cachedQuery.includeKeywords === undefined)) {
//always add async
gather('async', null, 0, function(c) {
c.isKeyword = true;
});
//optionally add await, iff we are inside an async closure
var node = Finder.findNode(start, file.ast, {parents: true});
if(node && Finder.inAsync(node)) {
gather('await', null, 0, function(c) {
c.isKeyword = true;
});
}
}
}
}
};
});

});

0 comments on commit 8675913

Please sign in to comment.