Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Bug 521635 - Provide keyword content assist for async / await (#166)
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
bundles/org.eclipse.orion.client.javascript/web/javascript/ternPlugins/async_await.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| }); |