summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rennie <Michael_Rennie@ca.ibm.com>2015-12-10 13:23:13 -0500
committerMike Rennie <Michael_Rennie@ca.ibm.com>2015-12-10 13:23:13 -0500
commit3b7f84b5defd61dc945736c4aa3c8f65bb2a19fb (patch)
treef6494affe8682c4bfefae47aaf15d5d6d27c876a
parentd1f6911fd53b20befac318f134fcc9755c853c0e (diff)
downloadorg.eclipse.orion.client-origin/mrennie/jsplugin-worker.zip
org.eclipse.orion.client-origin/mrennie/jsplugin-worker.tar.gz
org.eclipse.orion.client-origin/mrennie/jsplugin-worker.tar.bz2
Bug 484136 - Investigate making the entire JS bundle a workerorigin/mrennie/jsplugin-worker
-rw-r--r--bundles/org.eclipse.orion.client.core/web/orion/pluginregistry.js4
-rw-r--r--bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css2
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js4
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openDeclaration.js29
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openImplementation.js28
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js20
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/commands/renameCommand.js35
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/contentAssist/ternAssist.js29
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/hover.js25
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/workermessages.js5
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js27
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js320
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin_embed_dev.html87
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptWorker.js (renamed from bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorker.js)42
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternServer.js609
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js701
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js3
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js12
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js27
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/css/theme_common.css4
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/defaults.pref4
21 files changed, 847 insertions, 1170 deletions
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/pluginregistry.js b/bundles/org.eclipse.orion.client.core/web/orion/pluginregistry.js
index 170e636..6a2c89a 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/pluginregistry.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/pluginregistry.js
@@ -1076,10 +1076,10 @@ define(["orion/Deferred", "orion/EventTarget", "orion/URL-shim"], function(Defer
}
});
message = "Plugin handshake timeout for: " + url;
- newTimeout = this._loading ? 5000 : (timeout || 60000) + extraTimeout;
+ newTimeout = this._loading ? 50000 : (timeout || 60000) + extraTimeout;
} else {
message = "Plugin load timeout for: " + url;
- newTimeout = timeout || 15000;
+ newTimeout = timeout || 150000;
}
}
if (this._loadTimeout) clearTimeout(this._loadTimeout);
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css b/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css
index 7a0b2e0..3f90933 100644
--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css
+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css
@@ -2,7 +2,7 @@
.textviewTooltip {
font-family: "Consolas", "Monaco", "Vera Mono", monospace;
font-size: 12px;
- background-color: #325C80; /* Must match the quickfix command button border color */
+ background-color: #3B4B54; /* Must match the quickfix command button border color */
color: #FAFAFA;
padding: 8px;
/* The tooltip initial size explicitly counts for padding size, border-box sizing breaks this */
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js
index 6a5ece9..7a4cdc7 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/astManager.js
@@ -63,8 +63,8 @@ define([
ast = _self.parse(text, metadata ? metadata.location : 'unknown'); //$NON-NLS-1$
_self.cache.put(loc, ast);
return ast;
- });
- });
+ });;;;
+ });;;;
},
/**
* Returns the key to use when caching
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openDeclaration.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openDeclaration.js
index 24d1f68..41862ed 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openDeclaration.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openDeclaration.js
@@ -21,14 +21,14 @@ define([
* @constructor
* @public
* @param {javascript.ASTManager} ASTManager The backing AST manager
- * @param {TernWorker} ternWorker The running Tern worker
+ * @param {TernServer} ternServer The running Tern server
* @param {javascript.CUProvider} cuProvider
* @returns {javascript.commands.OpenDeclarationCommand} A new command
* @since 8.0
*/
- function OpenDeclarationCommand(ASTManager, ternWorker, cuProvider, openMode) {
+ function OpenDeclarationCommand(ASTManager, ternServer, cuProvider, openMode) {
this.astManager = ASTManager;
- this.ternworker = ternWorker;
+ this.ternserver = ternServer;
this.cuprovider = cuProvider;
this.openMode = openMode;
this.timeout = null;
@@ -54,26 +54,29 @@ define([
this.timeout = null;
}, 5000);
var files = [{type: 'full', name: options.input, text: text}]; //$NON-NLS-1$
- this.ternworker.postMessage(
- {request:'definition', args:{params:{offset: options.offset}, guess: true, files: files, meta:{location: options.input}}}, //$NON-NLS-1$
- function(response) {
- if(response.request === 'definition') {
- if(response.declaration && (typeof(response.declaration.start) === 'number' && typeof(response.declaration.end) === 'number')) {
- if(response.declaration.guess) {
+ this.ternserver.definition(options.input, options.offset, true, files,
+ function(val, err) {
+ clearTimeout(this.timeout);
+ if(err) {
+ deferred.reject(err.message);
+ } else {
+ if(val) {
+ if(val.guess) {
//TODO handle it being a guess, for now fall through
}
var opts = Object.create(null);
- opts.start = response.declaration.start;
- opts.end = response.declaration.end;
+ opts.start = val.start;
+ opts.end = val.end;
if(this.openMode != null && typeof(this.openMode) !== 'undefined') {
opts.mode = this.openMode;
}
- deferred.resolve(editorContext.openEditor(response.declaration.file, opts));
+ deferred.resolve(editorContext.openEditor(val.file, opts));
} else {
deferred.reject({Severity: 'Warning', Message: Messages['noDeclFound']}); //$NON-NLS-1$
}
}
- }.bind(this)); //$NON-NLS-1$
+ }.bind(this)
+ );
}
});
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openImplementation.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openImplementation.js
index 7957764..23300fa 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openImplementation.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/openImplementation.js
@@ -21,14 +21,14 @@ define([
* @constructor
* @public
* @param {javascript.ASTManager} ASTManager The backing AST manager
- * @param {TernWorker} ternWorker The running Tern worker
+ * @param {TernServer} ternServer The running Tern server
* @param {javascript.CUProvider} cuProvider
* @returns {javascript.commands.OpenImplementationCommand} A new command
* @since 10.0
*/
- function OpenImplementationCommand(ASTManager, ternWorker, cuProvider) {
+ function OpenImplementationCommand(ASTManager, ternServer, cuProvider) {
this.astManager = ASTManager;
- this.ternworker = ternWorker;
+ this.ternserver = ternServer;
this.cuprovider = cuProvider;
this.timeout = null;
}
@@ -53,18 +53,24 @@ define([
this.timeout = null;
}, 5000);
var files = [{type: 'full', name: options.input, text: text}]; //$NON-NLS-1$
- this.ternworker.postMessage(
- {request:'implementation', args:{params:{offset: options.offset}, guess: true, files: files, meta:{location: options.input}}}, //$NON-NLS-1$
- function(response) {
- if(response.implementation && (typeof(response.implementation.start) === 'number' && typeof(response.implementation.end) === 'number')) {
+ this.ternserver.implementation(options.input, options.offset, true, files,
+ function(val, err) {
+ clearTimeout(this.timeout);
+ if(err) {
+ deferred.reject(err.message);
+ } else if(val) {
+ if(val.guess) {
+ //TODO handle a guess
+ }
var opts = Object.create(null);
- opts.start = response.implementation.start;
- opts.end = response.implementation.end;
- deferred.resolve(editorContext.openEditor(response.implementation.file, opts));
+ opts.start = val.start;
+ opts.end = val.end;
+ deferred.resolve(editorContext.openEditor(val.file, opts));
} else {
deferred.reject({Severity: 'Warning', Message: Messages['noImplFound']}); //$NON-NLS-1$
}
- });
+ }.bind(this)
+ );
}
});
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js
index a987436..295e9ba 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js
@@ -22,12 +22,16 @@ define([
* @description Creates a new rename command
* @constructor
* @public
- * @param {TernWorker} ternWorker The running Tern worker
+ * @param {TernServer} ternserver The running Tern worker
+ * @param {ASTManager} astManager The AST manager
+ * @param {ScriptResolver} scriptResolver The backing resolver
+ * @param {CUProvider} cuProvider The backing compilation unit provider
+ * @param {gSearchClient} searchClient The global search client
* @returns {javascript.commands.RenameCommand} A new command
* @since 10.0
*/
- function RefsCommand(ternWorker, astManager, scriptResolver, cuProvider, searchClient) {
- this.ternworker = ternWorker;
+ function RefsCommand(ternServer, astManager, scriptResolver, cuProvider, searchClient) {
+ this.ternserver = ternServer;
this.scriptresolver = scriptResolver;
this.astmanager = astManager;
this.cuprovider = cuProvider;
@@ -163,8 +167,7 @@ define([
return that.astmanager.getAST(editorContext).then(function(ast) {
var node = Finder.findNode(options.offset, ast);
if(node && node.type === 'Identifier') {
- that.ternworker.postMessage(
- {request: 'type', args: {meta: metadata, params: options}}, //$NON-NLS-1$
+ that.ternserver.type(options.input, options.offset,
function(type, err) {
if(err) {
deferred.reject({Severity: 'Error', Message: err}); //$NON-NLS-1$
@@ -198,7 +201,7 @@ define([
if(v === node.name) {
//XXX do not send the full source more than once
//until bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=474420 is fixed
- var req = {request: 'checkRef', args: {meta:{location: file.metadata.Location}, params: {offset: match.end}, origin: type}} //$NON-NLS-1$
+ var req = {location: file.metadata.Location, offset: match.end, origin: type}
if(!srcCache[file.metadata.Location].src) {
srcCache[file.metadata.Location].src = true;
req.files = [{type: 'full', name: file.metadata.Location, text: source}]; //$NON-NLS-1$;
@@ -232,10 +235,9 @@ define([
* @function
* @private
*/
- _checkType: function _checkType(original, file, match, expected, request) {
+ _checkType: function _checkType(original, file, match, expected, options) {
var that = this;
- that.ternworker.postMessage(
- request,
+ that.ternserver.checkRef(options.location, options.offset, options.origin, options.files,
/* @callback */ function(type, err) {
if(type && type.type) {
var _t = type.type, _ot = original.type;
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/renameCommand.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/renameCommand.js
index a2b5c33..84fe9c8 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/renameCommand.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/renameCommand.js
@@ -23,13 +23,13 @@ define([
* @constructor
* @public
* @param {ASTManager} ASTManager The backing AST manager
- * @param {TernWorker} ternWorker The running Tern worker
+ * @param {TernServer} ternServer The running Tern server
* @returns {javascript.commands.RenameCommand} A new command
* @since 9.0
*/
- function RenameCommand(ASTManager, ternWorker, scriptResolver, CUProvider) {
+ function RenameCommand(ASTManager, ternServer, scriptResolver, CUProvider) {
this.astManager = ASTManager;
- this.ternworker = ternWorker;
+ this.ternserver = ternServer;
this.scriptResolver = scriptResolver;
this.cuprovider = CUProvider;
this.timeout = null;
@@ -88,29 +88,26 @@ define([
that.timeout = null;
}, 5000);
var files = [{type:'full', name:params.input, text:text}]; //$NON-NLS-1$
- that.ternworker.postMessage(
- {request:'rename', args:{params:{offset: params.offset}, files: files, meta:{location: params.input}, newname:''}}, //$NON-NLS-1$
- function(response) {
- var changes = response.changes;
- if(changes && changes.changes && changes.changes.length > 0) {
- var ranges = changes.changes;
- // turn the ranges into offset / length
- var offsets = [ranges.length];
- for (var i = 0; i < ranges.length; i++) {
- offsets[i] = {
- offset: ranges[i].start,
- length: ranges[i].end - ranges[i].start
- };
+ that.ternserver.rename(params.input, params.offset, '', files,
+ function(val, err) {
+ if(err) {
+ deferred.reject({Severity: 'Warning', Message: badRename(err.error)}); //$NON-NLS-1$
+ } else if(val.length > 0) {
+ var offsets = [];
+ for (var i = 0; i < val.length; i++) {
+ offsets.push({
+ offset: val[i].start,
+ length: val[i].end - val[i].start
+ });
}
var groups = [{data: {}, positions: offsets}];
var linkModel = {groups: groups};
editorContext.exitLinkedMode().then(function() {
editorContext.enterLinkedMode(linkModel).then(deferred.resolve, deferred.reject);
}, deferred.reject);
- } else if(typeof(response.error) === 'string') {
- deferred.reject({Severity: 'Warning', Message: badRename(response.error)}); //$NON-NLS-1$
}
- });
+ }
+ );
}, deferred.reject);
}
});
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/contentAssist/ternAssist.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/contentAssist/ternAssist.js
index d3d37da..d5e1e13 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/contentAssist/ternAssist.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/contentAssist/ternAssist.js
@@ -152,7 +152,8 @@ define([
});
var provider = new TemplateProvider();
-
+ var ternserver;
+
/**
* @description Creates a new TernContentAssist object
* @constructor
@@ -162,9 +163,9 @@ define([
* @param {Function} pluginEnvironments The function to use to query the Tern server for contributed plugins
* @param {Object} cuprovider The CU Provider that caches compilation units
*/
- function TernContentAssist(astManager, ternWorker, pluginEnvironments, cuprovider) {
+ function TernContentAssist(astManager, ternServer, pluginEnvironments, cuprovider) {
this.astManager = astManager;
- this.ternworker = ternWorker;
+ ternserver = ternServer;
this.pluginenvs = pluginEnvironments;
this.cuprovider = cuprovider;
this.timeout = null;
@@ -223,14 +224,16 @@ define([
}
var args = {params: params, meta: meta, envs:env, files: files};
var deferred = new Deferred();
- var that = this;
- this.ternworker.postMessage({request: 'completions', args: args}, //$NON-NLS-1$
- function(response) {
- clearTimeout(that.timeout);
- deferred.resolve(sortProposals(response.proposals, templates, args));
- }
- );
-
+ ternserver.completions(meta.location, params.offset, params.keywords, files,
+ function(val, err) {
+ clearTimeout(this.timeout);
+ if(err) {
+ deferred.reject(err.message);
+ } else {
+ deferred.resolve(sortProposals(val, templates, args));
+ }
+
+ }.bind(this));
if(this.timeout) {
clearTimeout(this.timeout);
}
@@ -239,8 +242,8 @@ define([
// In the editor we can't return an error message here or it will be treated as a proposal and inserted into text
deferred.resolve(params.timeoutReturn ? params.timeoutReturn : []);
}
- that.timeout = null;
- }, params.timeout ? params.timeout : 5000);
+ this.timeout = null;
+ }.bind(this), params.timeout ? params.timeout : 5000);
return deferred;
},
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/hover.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/hover.js
index 234c6e5..7758c49 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/hover.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/hover.js
@@ -228,14 +228,14 @@ define([
* @public
* @param {javascript.ASTManager} astManager
* @param {javascript.ScriptResolver} resolver
- * @param {javascript.TernWorkerCore} ternWorker
+ * @param {TernServer} ternserver
* @param {javascript.CUProvider} cuProvider
* @since 7.0
*/
- function JavaScriptHover(astManager, resolver, ternWorker, cuProvider) {
+ function JavaScriptHover(astManager, resolver, ternServer, cuProvider) {
this.astManager = astManager;
this.resolver = resolver;
- this.ternworker = ternWorker;
+ this.ternserver = ternServer;
this.cuprovider = cuProvider;
}
@@ -335,13 +335,14 @@ define([
}
deferred = new Deferred();
var files = [{type: 'full', name: meta.location, text: htmlsource ? htmlsource : ast.source}]; //$NON-NLS-1$
- this.ternworker.postMessage(
- {request:'documentation', args:{params:{offset: ctxt.offset, docFormat: 'full'}, files: files, meta:{location: meta.location}}}, //$NON-NLS-1$ //$NON-NLS-2$
- function(response) {
- var hover = '';
- if(response.request === 'documentation') {
- if(response.doc) {
- hover = formatMarkdownHover(response.doc.doc);
+ this.ternserver.documentation(meta.location, ctxt.offset, null, files,
+ function(val, err) {
+ if(err) {
+ deferred.reject(err.message);
+ } else {
+ var hover = '';
+ if(val) {
+ hover = formatMarkdownHover(val);
}
deferred.resolve(hover);
}
@@ -361,7 +362,7 @@ define([
if(path && files) {
var title = null;
if(files.length > 1) {
- title = i18nUtil.formatMessage('###${0} \'${1}\'###', Messages['openFileForTitle'], path); //$NON-NLS-1$ //$NON-NLS-2$
+ title = i18nUtil.formatMessage('###${0} \'${1}\'###', Messages['openFileForTitle'], path); //$NON-NLS-1$
}
var hover = '';
for(var i = 0; i < files.length; i++) {
@@ -372,7 +373,7 @@ define([
{
resource: file.location,
params: {}
- }); //$NON-NLS-0$
+ });
hover += file.name + ']('+href+') - '+file.path+'\n\n'; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/workermessages.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/workermessages.js
index ebdfe9a..7f57768 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/workermessages.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/workermessages.js
@@ -76,6 +76,7 @@ define({
'failedRefs': 'Failed to find references',
'failedRefsNoServer': 'failed to find references - server not started',
'failedType': 'Failed to find type',
+ 'failedTypeNoServer': 'Failed to find type - server not started',
'unknownRequest': 'The request \'${0}\' is unknown',
'serverNotStarted': 'The server has not been started. Request: \'${0}\'',
'funcProposalDescription': ' - The name of the function',
@@ -88,5 +89,7 @@ define({
'eslintRuleEnable': ' - ESLint rule enablement directive',
'eslintRuleDisable': ' - ESLint rule disablement directive',
'failedToComputeProblems': 'Failed to compute ESLint problems/markers',
- 'failedToComputeOutline': 'Failed to compute outline'
+ 'failedToComputeProblemsNoServer': 'Failed to compute ESLint problems/markers - server not started',
+ 'failedToComputeOutline': 'Failed to compute outline',
+ 'failedToComputeOutlineNoServer': 'Failed to compute outline - server not started'
});
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
index da6706c..28433ce 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
@@ -14,16 +14,14 @@ define([
"orion/Deferred"
], function(Defered) {
+ var ternserver;
/**
- * @name javascript.JSOutliner
* @description creates a new instance of the outliner
- * @param {Worker} ternWorker The backing Tern worker
- * @constructor
* @public
- * @param {javascript.ASTManager} astManager
+ * @param {TernServer} ternServer The running Tern server
*/
- function JSOutliner(ternWorker) {
- this.ternWorker = ternWorker;
+ function JSOutliner(ternServer) {
+ ternserver = ternServer;
}
/**
@@ -43,16 +41,15 @@ define([
editorContext.getFileMetadata().then(function(meta) {
editorContext.getText().then(function(text) {
var files = [{type: "full", name: meta.location, text: text}]; //$NON-NLS-1$
- this.ternWorker.postMessage({request: "outline", args: {files: files, meta: {location: meta.location}}}, function(response, error) { //$NON-NLS-1$
- if(response.outline) {
- deferred.resolve(response.outline);
- } else if(error) {
- deferred.reject(error);
- }
+ ternserver.outline(meta.location, files, function(val, err) {
+ if(err) {
+ deferred.reject(err.message);
+ } else if(val) {
+ deferred.resolve(val);
+ }
+ });
});
- }.bind(this));
-
- }.bind(this));
+ });
return deferred;
};
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
index 939c2cb..884c622 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
@@ -23,6 +23,7 @@ define([
'esprima/esprima',
'estraverse/estraverse',
'javascript/scriptResolver',
+"javascript/plugins/ternServer",
'javascript/astManager',
'javascript/quickFixes',
'javascript/contentAssist/ternAssist',
@@ -33,7 +34,6 @@ define([
'javascript/cuProvider',
'javascript/ternProjectManager',
'orion/util',
-'javascript/logger',
'javascript/commands/addToTernCommand',
'javascript/commands/generateDocCommand',
'javascript/commands/openDeclaration',
@@ -46,42 +46,47 @@ define([
'orion/editor/stylers/application_schema_json/syntax',
'orion/editor/stylers/application_x-ejs/syntax',
'i18n!javascript/nls/messages',
-'orion/i18nUtil',
'orion/URL-shim'
-], function(PluginProvider, mServiceRegistry, Deferred, FileClient, Metrics, Esprima, Estraverse, ScriptResolver, ASTManager, QuickFixes, TernAssist,
- EslintValidator, Occurrences, Hover, Outliner, CUProvider, TernProjectManager, Util, Logger, AddToTernCommand, GenerateDocCommand, OpenDeclCommand, OpenImplCommand,
- RenameCommand, RefsCommand, mGSearchClient, mJS, mJSON, mJSONSchema, mEJS, javascriptMessages, i18nUtil) {
-
- var serviceRegistry = new mServiceRegistry.ServiceRegistry();
- var provider = new PluginProvider({
- name: javascriptMessages['pluginName'],
- version: "1.0", //$NON-NLS-1$
- description: javascriptMessages['pluginDescription']
- }, serviceRegistry);
-
- /**
- * Register the JavaScript content types
- */
- provider.registerService("orion.core.contenttype", {}, { //$NON-NLS-1$
- contentTypes: [
- { id: "application/javascript", //$NON-NLS-1$
- "extends": "text/plain", //$NON-NLS-1$ //$NON-NLS-1$
- name: "JavaScript", //$NON-NLS-1$
- extension: ["js"], //$NON-NLS-1$
- imageClass: "file-sprite-javascript modelDecorationSprite" //$NON-NLS-1$
- }, {id: "application/json", //$NON-NLS-1$
- "extends": "text/plain", //$NON-NLS-1$ //$NON-NLS-1$
- name: "JSON", //$NON-NLS-1$
- extension: ["json", "pref", "tern-project"], //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- imageClass: "file-sprite-javascript modelDecorationSprite" //$NON-NLS-1$
- }, {id: "application/x-ejs", //$NON-NLS-1$
- "extends": "text/plain", //$NON-NLS-1$ //$NON-NLS-1$
- name: "Embedded Javascript", //$NON-NLS-1$
- extension: ["ejs"], //$NON-NLS-1$
- imageClass: "file-sprite-javascript modelDecorationSprite" //$NON-NLS-1$
- }
- ]
- });
+], function(PluginProvider, mServiceRegistry, Deferred, FileClient, Metrics, Esprima, Estraverse, ScriptResolver, TernServer, ASTManager, QuickFixes, TernAssist,
+ EslintValidator, Occurrences, Hover, Outliner, CUProvider, TernProjectManager, Util, AddToTernCommand, GenerateDocCommand, OpenDeclCommand, OpenImplCommand,
+ RenameCommand, RefsCommand, mGSearchClient, mJS, mJSON, mJSONSchema, mEJS, javascriptMessages) {
+
+ function connect(provider) {
+ var serviceRegistry = new mServiceRegistry.ServiceRegistry();
+ var headers = {
+ name: javascriptMessages['pluginName'],
+ version: "1.0", //$NON-NLS-1$
+ description: javascriptMessages['pluginDescription']
+ };
+ if(!provider) {
+ provider = new PluginProvider();
+ }
+ provider.updateHeaders(headers);
+
+
+ /**
+ * Register the JavaScript content types
+ */
+ provider.registerService("orion.core.contenttype", {}, { //$NON-NLS-1$
+ contentTypes: [
+ { id: "application/javascript", //$NON-NLS-1$
+ "extends": "text/plain", //$NON-NLS-1$ //$NON-NLS-1$
+ name: "JavaScript", //$NON-NLS-1$
+ extension: ["js"], //$NON-NLS-1$
+ imageClass: "file-sprite-javascript modelDecorationSprite" //$NON-NLS-1$
+ }, {id: "application/json", //$NON-NLS-1$
+ "extends": "text/plain", //$NON-NLS-1$ //$NON-NLS-1$
+ name: "JSON", //$NON-NLS-1$
+ extension: ["json", "pref", "tern-project"], //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ imageClass: "file-sprite-javascript modelDecorationSprite" //$NON-NLS-1$
+ }, {id: "application/x-ejs", //$NON-NLS-1$
+ "extends": "text/plain", //$NON-NLS-1$ //$NON-NLS-1$
+ name: "Embedded Javascript", //$NON-NLS-1$
+ extension: ["ejs"], //$NON-NLS-1$
+ imageClass: "file-sprite-javascript modelDecorationSprite" //$NON-NLS-1$
+ }
+ ]
+ });
/**
* make sure the RecoveredNode is ignored
@@ -103,190 +108,24 @@ define([
*/
var astManager = new ASTManager.ASTManager(Esprima);
- var ternReady = false;
- var messageQueue = [];
-
- function WrappedWorker(script, onMessage, onError) {
- /*if(typeof(SharedWorker) === 'function') {
- this.shared = true;
- var wUrl = new URL(script, window.location.href);
- wUrl.query.set("worker-language", navigator.language);
- this.worker = new SharedWorker(wUrl.href);
- this.worker.port.onmessage = onMessage;
- this.worker.port.onerror = onError;
- this.worker.port.start();
- this.worker.postMessage({request: "start_worker"}); //$NON-NLS-1$
- } else { */
- var wUrl = new URL(script, window.location.href);
- wUrl.query.set("worker-language", navigator.language); //$NON-NLS-1$
- this.worker = new Worker(wUrl.href);
- this.worker.onmessage = onMessage.bind(this);
- this.worker.onerror = onError.bind(this);
- this.worker.postMessage({request: "start_worker"}); //$NON-NLS-1$
- this.messageId = 0;
- this.callbacks = Object.create(null);
- // }
- }
-
- WrappedWorker.prototype.postMessage = function(msg, f) {
- var starting = msg.request === 'start_server';
- if(starting) {
- ternReady = false;
- }
- if(ternReady || starting) {
- if(msg != null && typeof(msg) === 'object') {
- if(typeof(msg.messageID) !== 'number' && typeof(msg.ternID) !== 'number') {
- //don't overwrite an id from a tern-side request
- msg.messageID = this.messageId++;
- this.callbacks[msg.messageID] = f;
- }
- }
- if(this.shared) {
- this.worker.port.postMessage(msg);
- } else {
- this.worker.postMessage(msg);
- }
- } else {
- messageQueue.push({msg: msg, f: f});
- }
- };
-
- /**
- * Object of contributed environments
- *
- * TODO will need to listen to updated tern plugin settings once enabled to clear this cache
- */
- var contributedEnvs;
- var ternWorker;
-
- var handlers ={
- 'read': doRead,
- /**
- * @callback
- */
- 'worker_ready': function(response) {
- ternReady = false;
- ternWorker.postMessage({request: 'start_server', args: {options: {}}}, /* @callback */ function(response) { //$NON-NLS-1$
- serverReady();
- });
- },
- /**
- * @callback
- */
- 'start_server': function(response) {
- serverReady();
- }
- };
-
- // Start the worker
- ternWorker = new WrappedWorker("ternWorker.js", //$NON-NLS-1$
- function(evnt) {
- var _d = evnt.data;
- if(_d.__isError) {
- //TODO log using the new platform hooks when available
- Logger.log(_d.message);
- } else if(typeof(_d) === 'object') {
- var id = _d.messageID;
- var f = this.callbacks[id];
- if(typeof(f) === 'function') {
- f(_d, _d.error);
- delete this.callbacks[id];
- }
- var _handler = handlers[_d.request];
- if(typeof(_handler) === 'function') {
- _handler(_d);
- }
- }
- },
- function(err) {
- Logger.log(err);
- });
-
- /**
- * @description Handler for Tern read requests
- * @param {Object} request Therequest from Tern
- * @since 10.0
- */
- function doRead(request) {
- var response = {request: 'read', ternID: request.ternID, args: {}}; //$NON-NLS-1$
- if(typeof(request.args.file) === 'object') {
- var _l = request.args.file.logical;
- response.args.logical = _l;
- scriptresolver.getWorkspaceFile(_l).then(function(files) {
- if(files && files.length > 0) {
- var rel = scriptresolver.resolveRelativeFiles(_l, files, {location: request.args.file.file, contentType: {name: 'JavaScript'}}); //$NON-NLS-1$
- if(rel && rel.length > 0) {
- return fileClient.read(rel[0].location).then(function(contents) {
- response.args.contents = contents;
- response.args.file = rel[0].location;
- response.args.path = rel[0].path;
- ternWorker.postMessage(response);
- });
- } else {
- response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], _l);
- ternWorker.postMessage(response);
+ var ternServer = new TernServer(scriptresolver, fileClient);
+ ternServer.startServer(Object.create(null), /* @callback */ function(err) {
+ ternServer.installedPlugins(function(val, err) {
+ function cleanPrefs(prefs) {
+ var all = Object.keys(prefs);
+ for(var i = 0, len = all.length; i < len; i++) {
+ var id = all[i];
+ if(/^tern.$/.test(id)) {
+ delete prefs[id];
}
- } else {
- response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], _l);
- ternWorker.postMessage(response);
}
- },
- function(err) {
- response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], _l);
- response.args.message = err.toString();
- ternWorker.postMessage(response);
- });
- } else {
- var file = request.args.file;
- response.args.file = file;
- if(!/\.js|\.htm|\.htm$/ig.test(file)) {
- //no extension given, guess at js
- file += '.js'; //$NON-NLS-1$
- }
- try {
- return fileClient.read(file).then(function(contents) {
- response.args.contents = contents;
- ternWorker.postMessage(response);
- },
- function(err) {
- response.args.message = err.toString();
- response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], file);
- ternWorker.postMessage(response);
- });
- }
- catch(err) {
- response.args.message = err.toString();
- response.args.error = i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], file);
- ternWorker.postMessage(response);
}
- }
- }
-
- /**
- * @description Handles the server being ready
- * @param {Object} request The request
- * @since 10.0
- */
- function serverReady() {
- ternReady = true;
- for(var i = 0, len = messageQueue.length; i < len; i++) {
- var item = messageQueue[i];
- ternWorker.postMessage(item.msg, item.f);
- }
- messageQueue = [];
- function cleanPrefs(prefs) {
- var all = Object.keys(prefs);
- for(i = 0, len = all.length; i < len; i++) {
- var id = all[i];
- if(/^tern.$/.test(id)) {
- delete prefs[id];
- }
+ if(err) {
+ return new Deferred().reject(err.message);
}
- }
- ternWorker.postMessage({request: 'installed_plugins'}, function(response) { //$NON-NLS-1$
- var plugins = response.plugins;
+ var plugins = val;
var preferences = serviceRegistry.getService("orion.core.preference"); //$NON-NLS-1$
- return preferences ? preferences.get("/cm/configurations").then(function(prefs){ // //$NON-NLS-1$
+ return preferences ? preferences.get("/cm/configurations").then(function(prefs){ // //$NON-NLS-1$
var props = prefs["tern"];
cleanPrefs(prefs);
if (!props) {
@@ -296,7 +135,7 @@ define([
}
var keys = Object.keys(plugins);
var plugs = props.plugins ? props.plugins : Object.create(null);
- for(i = 0; i < keys.length; i++) {
+ for(var i = 0; i < keys.length; i++) {
var key = keys[i];
if(/^orion/.test(key)) {
delete plugs[key]; //make sure only the latest of Orion builtins are shown
@@ -308,8 +147,12 @@ define([
return preferences.put("/cm/configurations", prefs, {clear: true}); //$NON-NLS-1$
}) : new Deferred().resolve();
});
- }
-
+ });
+
+ /**
+ * Object of contributed environments
+ */
+ var contributedEnvs;
/**
* @description Queries the Tern server to return all contributed environment names from the installed plugins
* @returns {Object} The object of contributed environments or null
@@ -318,17 +161,21 @@ define([
function getEnvironments() {
var envDeferred = new Deferred();
if(!contributedEnvs) {
- ternWorker.postMessage({request: 'environments'}, function(response) { //$NON-NLS-1$
- contributedEnvs = response.envs;
- envDeferred.resolve(response.envs);
+ ternServer.environments(function(val, err) {
+ if(err) {
+ envDeferred.reject(err.message);
+ } else if(val) {
+ contributedEnvs = val;
+ envDeferred.resolve(val);
+ }
});
} else {
return envDeferred.resolve(contributedEnvs);
}
return envDeferred;
}
-
- provider.registerService("orion.edit.contentassist", new TernAssist.TernContentAssist(astManager, ternWorker, getEnvironments, CUProvider), //$NON-NLS-1$
+
+ provider.registerService("orion.edit.contentassist", new TernAssist.TernContentAssist(astManager, ternServer, getEnvironments, CUProvider), //$NON-NLS-1$
{
contentType: ["application/javascript", "text/html"], //$NON-NLS-1$ //$NON-NLS-2$
nls: 'javascript/nls/messages', //$NON-NLS-1$
@@ -341,7 +188,7 @@ define([
/**
* Register the jsdoc-based outline
*/
- provider.registerService("orion.edit.outliner", new Outliner.JSOutliner(ternWorker), //$NON-NLS-1$
+ provider.registerService("orion.edit.outliner", new Outliner.JSOutliner(ternServer), //$NON-NLS-1$
{ contentType: ["application/javascript"], //$NON-NLS-1$
name: javascriptMessages["sourceOutline"],
title: javascriptMessages['sourceOutlineTitle'],
@@ -359,13 +206,13 @@ define([
/**
* Register the hover support
*/
- provider.registerService("orion.edit.hover", new Hover.JavaScriptHover(astManager, scriptresolver, ternWorker, CUProvider), //$NON-NLS-1$
+ provider.registerService("orion.edit.hover", new Hover.JavaScriptHover(astManager, scriptresolver, ternServer, CUProvider), //$NON-NLS-1$
{
name: javascriptMessages['jsHover'],
contentType: ["application/javascript", "text/html"] //$NON-NLS-1$ //$NON-NLS-2$
});
- var validator = new EslintValidator(ternWorker, CUProvider);
+ var validator = new EslintValidator(ternServer, CUProvider);
/**
* Register the ESLint validator
@@ -388,7 +235,7 @@ define([
types: ["ModelChanging", 'onInputChanged'] //$NON-NLS-1$ //$NON-NLS-2$
});
- var ternProjectManager = new TernProjectManager.TernProjectManager(ternWorker, scriptresolver, fileClient);
+ var ternProjectManager = new TernProjectManager.TernProjectManager(ternServer, scriptresolver, fileClient);
/**
* Register Tern project manager as input changed listener
*/
@@ -400,7 +247,7 @@ define([
types: ['onInputChanged'] //$NON-NLS-1$
});
- if ("true" === localStorage.getItem("darklaunch")) {
+ // if ("true" === localStorage.getItem("darklaunch")) {
provider.registerServiceProvider("orion.navigate.command", //$NON-NLS-1$
new AddToTernCommand.AddToTernCommand(ternProjectManager),
{
@@ -410,7 +257,7 @@ define([
id : "add.js.tern" //$NON-NLS-1$
}
);
- }
+ //}
/**
* register the compilation unit provider as a listener
@@ -436,7 +283,7 @@ define([
);
provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$
- new OpenDeclCommand.OpenDeclarationCommand(astManager, ternWorker, CUProvider, "replace"), //$NON-NLS-1$
+ new OpenDeclCommand.OpenDeclarationCommand(astManager, ternServer, CUProvider, "replace"), //$NON-NLS-1$
{
name: javascriptMessages["openDeclName"],
tooltip : javascriptMessages['openDeclTooltip'],
@@ -451,7 +298,7 @@ define([
name: javascriptMessages['referencesMenuName'],
tooltip : javascriptMessages['referencesMenuTooltip']
});
- var refscommand = new RefsCommand(ternWorker,
+ var refscommand = new RefsCommand(ternServer,
astManager,
scriptresolver,
CUProvider,
@@ -490,7 +337,7 @@ define([
);
provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$
- new OpenImplCommand.OpenImplementationCommand(astManager, ternWorker, CUProvider),
+ new OpenImplCommand.OpenImplementationCommand(astManager, ternServer, CUProvider),
{
name: javascriptMessages["openImplName"],
tooltip : javascriptMessages['openImplTooltip'],
@@ -500,7 +347,7 @@ define([
}
);
provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$
- new RenameCommand.RenameCommand(astManager, ternWorker, scriptresolver, CUProvider),
+ new RenameCommand.RenameCommand(astManager, ternServer, scriptresolver, CUProvider),
{
name: javascriptMessages['renameElement'],
tooltip : javascriptMessages['renameElementTooltip'],
@@ -1154,7 +1001,12 @@ define([
* Re-init
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=462878
*/
- Metrics.initFromRegistry(serviceRegistry);
+ //Metrics.initFromRegistry(serviceRegistry);
});
+ }
+
+ return {
+ connect: connect
+ };
});
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin_embed_dev.html b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin_embed_dev.html
deleted file mode 100644
index 14af2f3..0000000
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin_embed_dev.html
+++ /dev/null
@@ -1,87 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="UTF-8">
- <title>Orion JavaScript Support</title>
- <script src="../../requirejs/require.js"></script>
- <script type="text/javascript">
- /*eslint-env amd*/
- /* eslint-disable missing-nls */
- require({
- baseUrl: "../../",
- paths: {
- i18n: 'requirejs/i18n',
- json: 'requirejs/json',
- 'orion/bootstrap': 'embeddedEditor/builder/buildFrom/bootstrap'
- }
- });
-
- require(["javascript/plugins/javascriptPlugin"]);
- </script>
-</head>
-<body>
- <h1>JavaScript Tools Support</h1>
- <p>This plugin provides a variety of JavaScript tooling, including:</p>
- <ul>
- <li><em>Editing</em> - an editor with syntax highlighting, navigation, code completion, etc.</li>
- <li><em>Navigation</em> - source navigation from the editor as well as a variety of outines.</li>
- <li><em>Content Assist</em> - smart content assist while editing.</li>
- <li><em>Search</em> - named item searching, editor occurrences, etc.</li>
- </ul>
- <div style="width:50%">
- <h3>Third Party Libraries</h3>
- <table>
- <tr>
- <td>Doctrine 0.5.1</td>
- <td><a href="https://github.com/Constellation/doctrine/blob/0.5.1/README.md">Readme</a></td>
- <td><a href="https://github.com/Constellation/doctrine/blob/0.5.1/LICENSE.BSD">License</a></td>
- </tr>
- <tr>
- <td>ESLint 1.9.0</td>
- <td><a href="https://github.com/eslint/eslint/blob/v1.9.0/README.md">Readme</a></td>
- <td><a href="https://github.com/eslint/eslint/blob/v1.9.0/LICENSE">License</a></td>
- </tr>
- <tr>
- <td>Eprima 2.0.0</td>
- <td><a href="https://github.com/jquery/esprima/blob/2.0/README.md">Readme</a></td>
- <td><a href="https://github.com/jquery/esprima/blob/2.0/LICENSE.BSD">License</a></td>
- </tr>
- <tr>
- <td>EScope 1.0.0</td>
- <td><a href="https://github.com/Constellation/escope/blob/1.0.0/README.md">Readme</a></td>
- <td><a href="https://github.com/Constellation/escope/blob/1.0.0/LICENSE.BSD">License</a></td>
- </tr>
- <tr>
- <td>ESTraverse 1.9.0</td>
- <td><a href="https://github.com/Constellation/estraverse/blob/1.9.0/README.md">Readme</a></td>
- <td><a href="https://github.com/Constellation/estraverse/blob/1.9.0/LICENSE.BSD">License</a></td>
- </tr>
- <tr>
- <td>Tern 0.6.2</td>
- <td><a href="https://github.com/marijnh/tern/blob/0.6.2/README.md">Readme</a></td>
- <td><a href="https://github.com/marijnh/tern/blob/0.6.2/LICENSE">License</a></td>
- </tr>
- </table>
- </div>
- <div style="width:50%">
- <h3>License</h3>
- <p>
- The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
- indicated below, the Content is provided to you under the terms and conditions of the
- <a href="http://www.eclipse.org/legal/epl-v10.html">Eclipse Public License Version 1.0</a>
- (&quot;EPL&quot;), and the <a href="http://www.eclipse.org/org/documents/edl-v10.html">
- Eclipse Distribution License Version 1.0</a> (&quot;EDL&quot;).
- For purposes of the EPL and EDL, &quot;Program&quot; will mean the Content.
- </p>
-
- <p>
- If you did not receive this Content directly from the Eclipse Foundation, the Content is
- being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
- apply to your use of any object code in the Content. Check the Redistributor's license that was
- provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
- indicated below, the terms and conditions of the EPL still apply to any source code in the Content
- and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.
- </p>
- </div>
-</body>
-</html> \ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorker.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptWorker.js
index bb7d042..ec5ea9b 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorker.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptWorker.js
@@ -1,20 +1,22 @@
-/*******************************************************************************
- * @license
- * Copyright (c) 2015 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 - initial API and implementation
- *******************************************************************************/
-/*eslint-env node, browser*/
-/*globals importScripts */
-importScripts('../../requirejs/require.js'); // synchronous //$NON-NLS-1$
-require(["../../orion/require-config.js"], function(config){
- require.config({
- baseUrl: "../../"
- });
- require(["javascript/plugins/ternWorkerCore"], null, config.errback);
-});
+/*******************************************************************************
+ * @license
+ * Copyright (c) 2015 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 - initial API and implementation
+ ******************************************************************************/
+/*globals importScripts orion*/
+/*eslint-env browser, amd*/
+importScripts("../../orion/Deferred.js", "../../orion/plugin.js", '../../requirejs/require.min.js');
+var pluginProvider = new orion.PluginProvider();
+require(["../../orion/require-config.js"], function(config){
+ require.config({
+ baseUrl: "../../" //$NON-NLS-1$
+ });
+ require(["javascript/plugins/javascriptPlugin"], function(plugin){
+ plugin.connect(pluginProvider);
+ }, config.errback);
+});
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternServer.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternServer.js
new file mode 100644
index 0000000..c455f8d
--- /dev/null
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternServer.js
@@ -0,0 +1,609 @@
+/*******************************************************************************
+ * @license
+ * Copyright (c) 2015 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 - initial API and implementation
+ ******************************************************************************/
+/*eslint-env amd */
+define([
+ "requirejs/require",
+ "tern/lib/tern",
+ "javascript/plugins/ternDefaults",
+ "orion/Deferred",
+ "orion/objects",
+ "orion/serialize",
+ "i18n!javascript/nls/workermessages",
+ "i18n!javascript/nls/messages",
+ "orion/i18nUtil"
+],
+/* @callback */ function(requirejs, Tern, defaultOptions, Deferred, Objects, Serialize, Messages, javascriptMessages, i18nUtil) {
+
+ var ternserver, scriptresolver, fileclient;
+
+ /**
+ * @name TernServer
+ * @description Creates a new TernServer
+ * @param {ScriptResolver} scriptResolver The resolver used to find scripts for getFile
+ * @param {FileClient} fileClient The file client
+ * @returns {TernServer} A new TernServer instance
+ */
+ function TernServer(scriptResolver, fileClient) {
+ scriptresolver = scriptResolver;
+ fileclient = fileClient;
+ }
+
+ Objects.mixin(TernServer.prototype, {
+ /**
+ * @description Add a file to the Tern server
+ * @param {String} file The fully qualified name of the file
+ * @param {String} text The optional text of the file
+ */
+ addFile: function addFile(file, text) {
+ if(ternserver) {
+ ternserver.addFile(file, text);
+ }
+ },
+ /**
+ * @description Checks if the type reference at the given offset matches the given origin type
+ * @param {String} file The fully qualified name of the file context
+ * @param {Number} offset The offset of the identifier to check
+ * @param {Object} origin The original type information
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ checkRef: function checkRef(file, offset, origin, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "checkRef", //$NON-NLS-1$
+ file: file,
+ end: offset,
+ origin: origin
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, type) {
+ if(error) {
+ callback(null, {error: typeof(error) === 'string' ? error : error.message, message: Messages['failedType']});
+ } else {
+ callback(type);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedTypeNoServer']});
+ }
+
+ },
+ /**
+ * @description Computes content assist for the given options
+ * @param {String} file The fully qualified name of the file context
+ * @param {Number} offset The offset of the completion
+ * @param {Boolean} keywords If keywords should be returned as well
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ completions: function completions(file, offset, keywords, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "completions", //$NON-NLS-1$
+ file: file,
+ types: true,
+ origins: true,
+ urls: true,
+ docs: true,
+ end: offset,
+ sort:true,
+ includeKeywords: keywords,
+ caseInsensitive: true
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, completions) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedToComputeProposals']});
+ } else if(completions && completions.completions) {
+ callback(completions.completions);
+ } else {
+ callback([]);
+ }
+ });
+
+ } else {
+ callback(null, {message: Messages['failedToComputeProposalsNoServer']});
+ }
+ },
+ /**
+ * @description Computes the definition of the identifier at the given offset
+ * @param {String} file The fully qualified name of the file context
+ * @param {Number} offset The offset of the completion
+ * @param {Boolean} guess If we should take a guess at the definition if one cannot be computed
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ definition: function definition(file, offset, guess, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "definition", //$NON-NLS-1$
+ file: file,
+ end: offset,
+ guess: guess
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, decl) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedToComputeDecl']});
+ }
+ if(decl && typeof(decl.start) === 'number' && typeof(decl.end) === "number") {
+ callback(decl);
+ } else {
+ callback(null);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedToComputeDeclNoServer']});
+ }
+ },
+ /**
+ * @description Deletes the given file from the server. Does nothing if the file does not exist
+ * @param {String] file The fully qualified name of the file to delete
+ */
+ delFile: function delFile(file) {
+ if(ternserver) {
+ ternserver.delFile(file);
+ }
+ },
+ /**
+ * @description Computes the documentation associated with the given offset in the file
+ * @param {String} file The fully qualified name of the file context
+ * @param {Number} offset The offset of the completion
+ * @param {String} docFormat The format of the doc. If not given 'full' is assumed
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ documentation: function documentation(file, offset, docFormat, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "documentation", //$NON-NLS-1$
+ file: file,
+ end: offset,
+ docFormat: typeof(docFormat) === 'string' ? docFormat : 'full' //$NON-NLS-1$
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, doc) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedToComputeDoc']});
+ } else if(doc && doc.doc) {
+ callback(doc.doc);
+ } else {
+ callback(null);
+ }
+ });
+ } else {
+ callback(null, {request: 'documentation', message: Messages['failedToComputeDocNoServer']}); //$NON-NLS-1$
+ }
+ },
+ /**
+ * @description Returns the list of environments from plugins in Tern, if any
+ * @param {Function} callback The callback which is called to return the results
+ */
+ environments: function environments(callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: 'environments' //$NON-NLS-1$
+ }},
+ function(error, envs) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedGetEnvs']});
+ }
+ if(typeof(envs) === 'object') {
+ callback(envs);
+ } else {
+ callback(null);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedGetEnvsNoServer']});
+ }
+ },
+ /**
+ * @description Computes the implementation of the identifier at the given offset
+ * @param {String} file The fully qualified name of the file context
+ * @param {Number} offset The offset of the completion
+ * @param {Boolean} guess If we should take a guess at the definition if one cannot be computed
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ implementation: function implementation(file, offset, guess, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "implementation", //$NON-NLS-1$
+ file: file,
+ end: offset,
+ guess: guess
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, impl) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedToComputeImpl']});
+ } else if(impl && impl.implementation && typeof(impl.implementation.start) === 'number' && typeof(impl.implementation.end) === "number") {
+ callback(impl.implementation);
+ } else {
+ callback(null);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedToComputeImplNoServer']});
+ }
+ },
+ /**
+ * @description Returns the list of plugins installed in Tern, if any
+ * @param {Function} callback The callback which is called to return the results
+ */
+ installedPlugins: function installedPlugins(callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: 'installed_plugins' //$NON-NLS-1$
+ }},
+ function(error, plugins) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedGetInstalledPlugins']});
+ }
+ if(plugins != null && typeof(plugins) === 'object') {
+ callback(plugins);
+ } else {
+ callback([]);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedGetInstalledPluginsNoServer']});
+ }
+ },
+ /**
+ * @description Runs ESLint on the given file context
+ * @param {String} file The fully qualified name of the file context
+ * @param {Object} rules The map of ESLint rules
+ * @param {Object} env The map of existing environment names
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ lint: function lint(file, rules, env, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "lint", //$NON-NLS-1$
+ file: file,
+ config: {
+ rules: rules
+ },
+ env: env ? env : Object.create(null)
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, problems) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedToComputeProblems']});
+ } else if(problems && Array.isArray(problems)) {
+ callback(problems);
+ } else {
+ callback([]);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedToComputeProblemsNoServer']});
+ }
+ },
+ /**
+ * @description Computes an outline of the given file
+ * @param {String} file The fully qualified name of the file context
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ outline: function outline(file, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "outline", //$NON-NLS-1$
+ file: file
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, outline) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedToComputeOutline']});
+ } else if(outline && Array.isArray(outline)) {
+ callback(outline);
+ } else {
+ callback([]);
+ }
+ }
+ );
+ } else {
+ callback(null, {message: Messages['failedToComputeOutlineNoServer']});
+ }
+ },
+ /**
+ * @description Computes a rename array for the identifier at the given offset
+ * @param {String} file The fully qualified name of the file context
+ * @param {Number} offset The offset of the completion
+ * @param {String} newname The new name to change to
+ * @param {Array.<Object>} files The optional array of file objects
+ * @param {Function} callback The callback which is called to return the results
+ */
+ rename: function rename(file, offset, newname, files, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "rename", //$NON-NLS-1$
+ file: file,
+ end: offset,
+ newName: newname
+ },
+ files: Array.isArray(files) ? files : []},
+ function(error, changes) {
+ if(error) {
+ callback(null, {error: error.message, message: Messages['failedRename']});
+ } else if(changes && Array.isArray(changes.changes)) {
+ callback(changes.changes);
+ } else {
+ callback([]);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedRenameNoServer']});
+ }
+ },
+ /**
+ * @description Start up the Tern server, send a message after trying
+ * @param {Object} jsonOptions The optional map of JSON options to start the server with
+ * @param {Function} callback The callback which is called to return the results
+ */
+ startServer: function startServer(jsonOptions, callback) {
+ if (ternserver){
+ ternserver.reset();
+ ternserver = null;
+ }
+ var options = {
+ async: true,
+ debug: false,
+ projectDir: '/',
+ getFile: doRead
+ };
+ var pluginsDir = defaultOptions.pluginsDir;
+ var defsDir = defaultOptions.defsDir;
+ var defNames = [];
+ if (jsonOptions) {
+ if (jsonOptions.plugins){
+ options.plugins = jsonOptions.plugins;
+ }
+ if(jsonOptions.pluginDir) {
+ pluginsDir = jsonOptions.pluginsDir;
+ }
+ if (Array.isArray(jsonOptions.libs)){
+ defNames = jsonOptions.libs;
+ defsDir = jsonOptions.defsDir;
+ }
+ if (Array.isArray(jsonOptions.defs)){
+ defNames = jsonOptions.defs;
+ defsDir = jsonOptions.defsDir;
+ }
+ if (typeof jsonOptions.ecmaVersion === 'number'){
+ options.ecmaVersion = jsonOptions.ecmaVersion;
+ }
+ if (typeof jsonOptions.dependencyBudget === 'number'){
+ options.dependencyBudget = jsonOptions.dependencyBudget;
+ }
+ }
+ function defaultStartUp(err) {
+ options.plugins = defaultOptions.plugins;
+ options.defs = defaultOptions.defs;
+ ternserver = new Tern.Server(options);
+ callback(err);
+ }
+ if(!options.plugins && (!defNames || defNames.length < 1)) {
+ defaultStartUp();
+ } else {
+ Deferred.all(loadPlugins(options.plugins, pluginsDir)).then(/* @callback */ function(plugins) {
+ Deferred.all(loadDefs(defNames, defsDir)).then(function(json) {
+ options.defs = json;
+ ternserver = new Tern.Server(options);
+ callback();
+ }, defaultStartUp);
+ }, defaultStartUp);
+ }
+ },
+ /**
+ * @description Computes the type information at the given offset
+ * @param {String} file The fully qualified name of the file context
+ * @param {Number} offset The offset of the completion
+ * @param {Function} callback The callback which is called to return the results
+ */
+ type: function type(file, offset, callback) {
+ if(ternserver) {
+ ternserver.request({
+ query: {
+ type: "type", //$NON-NLS-1$
+ file: file,
+ end: offset
+ }},
+ function(error, type) {
+ if(error) {
+ callback(null, {error: typeof(error) === 'string' ? error : error.message, message: Messages['failedType']});
+ } else {
+ callback(type);
+ }
+ });
+ } else {
+ callback(null, {message: Messages['failedTypeNoServer']});
+ }
+ }
+
+ });
+
+
+
+ /**
+ * @description Loads the plugins listed in the given plugins object
+ * @param {Object} plugins The object of plugins
+ * @param {String} pluginsDir The base directory to load plugins from, if not defined, the default of 'tern/plugin/' is assumed
+ * @returns {Promise} The promise to resolve all of the plugin loads
+ * @since 11.0
+ */
+ function loadPlugins(plugins, pluginsDir) {
+ var promises = [];
+ if(plugins) {
+ Object.keys(plugins).forEach(function(key) {
+ if(defaultOptions.plugins[key]) {
+ //default plugins are statically loaded
+ return;
+ }
+ var plugin = plugins[key];
+ var loc = plugin.location;
+ if(typeof(loc) !== 'string') {
+ if(typeof(pluginsDir) === 'string') {
+ loc = pluginsDir + key;
+ } else {
+ //assume it is in /tern/plugin/
+ loc = 'tern/plugin/' + key; //$NON-NLS-1$
+ }
+ }
+ var deferred = new Deferred();
+ try {
+ promises.push(deferred);
+ requirejs([loc], function(_) {
+ deferred.resolve(_);
+ },
+ function(err) {
+ deferred.reject(err);
+ });
+ }
+ catch(err) {
+ deferred.reject(err);
+ }
+ });
+ }
+ return promises;
+ }
+
+ /**
+ * @description Load any defs from the .tern-project file
+ * @param {Array.<String>|Object} defs The definitions, either from an array of names or an object of names with additional metadata
+ * @param {String} defsDir The optional directory where to find the definitions. If not given the 'tern/defs' directory is assumed
+ * @returns {Promise} Returns a promise to resolve all def loads
+ * @since 11.0
+ */
+ function loadDefs(defs, defsDir) {
+ var _defs = [];
+ if(Array.isArray(defs)) {
+ defs.forEach(function(_def) {
+ _defs.push(_loadDef(_def, defsDir, _defs));
+ });
+ } else if(defs && typeof(defs) === 'object') {
+ Object.keys(defs).forEach(function(key) {
+ var def = defs[key];
+ if(typeof(def.location) === 'string') {
+ _defs.push(_loadDef(def.location, defsDir, _defs));
+ } else {
+ _defs.push(_loadDef(key, defsDir, _defs));
+ }
+ });
+ }
+ return _defs;
+ }
+
+ /**
+ * @description Delegate to actually load a definition
+ * @private
+ * @param {String} def The name of the definition load try and load
+ * @param {String} defsDir The optional base directory to load from
+ * @param {Array.<Object>} defs The collector array for loaded defs
+ * @since 11.0
+ */
+ function _loadDef(def, defsDir) {
+ var loc = def;
+ if(typeof(defsDir) === 'string') {
+ loc = defsDir + def;
+ } else {
+ //assume it is in /tern/defs/
+ loc = 'json!tern/defs/' + def; //$NON-NLS-1$
+ }
+ if(!/^json!/i.test(loc)) {
+ loc = 'json!'+loc; //$NON-NLS-1$
+ }
+ if(!/$.json/i.test(def)) {
+ loc = loc + '.json'; //$NON-NLS-1$
+ }
+ var deferred = new Deferred();
+ try {
+ requirejs([loc], function(_) {
+ deferred.resolve(_);
+ },
+ function(err) {
+ deferred.reject(err);
+ });
+ }
+ catch(err) {
+ deferred.reject(err);
+ }
+ return deferred;
+ }
+
+ /**
+ * @description Handler for Tern read requests
+ * @param {Object|String}} file The file to read
+ * @param {Function} callback The finction to call back to
+ */
+ function doRead(file, callback) {
+ if(typeof(file) === 'object') {
+ var _l = file.logical;
+ var val = Object.create(null);
+ val.logical = _l;
+ scriptresolver.getWorkspaceFile(_l).then(function(files) {
+ if(files && files.length > 0) {
+ var rel = scriptresolver.resolveRelativeFiles(_l, files, {location: file.file, contentType: {name: 'JavaScript'}}); //$NON-NLS-1$
+ if(rel && rel.length > 0) {
+ return fileclient.read(rel[0].location).then(function(contents) {
+ val.contents = contents;
+ val.file = rel[0].location;
+ val.path = rel[0].path;
+ callback(null, val);
+ },
+ function(reject) {
+ callback(reject);
+ });
+ } else {
+ callback(i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], _l));
+ }
+ } else {
+ callback(i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], _l));
+ }
+ },
+ /* @callback */ function(err) {
+ callback(i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], _l));
+ });
+ } else {
+ if(!/\.js|\.htm|\.htm$/ig.test(file)) {
+ //no extension given, guess at js
+ file += '.js'; //$NON-NLS-1$
+ }
+ try {
+ return fileclient.read(file).then(function(contents) {
+ callback(null, contents);
+ },
+ /* @callback */ function(err) {
+ callback(err);
+ });
+ }
+ catch(err) {
+ callback(i18nUtil.formatMessage(javascriptMessages['failedToReadFile'], file));
+ }
+ }
+ }
+
+ return TernServer;
+}); \ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js
deleted file mode 100644
index 5cebaea..0000000
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js
+++ /dev/null
@@ -1,701 +0,0 @@
-/*******************************************************************************
- * @license
- * Copyright (c) 2015 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 - initial API and implementation
- *******************************************************************************/
-/*globals importScripts onmessage:true onconnect:true requirejs*/
-/*eslint-env node, browser*/
-var lang ='en'; //$NON-NLS-1$
-var sear = self.location.search;
-if(sear) {
- var langs = sear.split('worker-language'); //$NON-NLS-1$
- if(Array.isArray(langs) && langs.length === 2) {
- lang = langs[1].slice(1);
- if(lang){
- lang = lang.toLocaleLowerCase();
- }
- }
-}
-requirejs.config({locale: lang});
-require([
- 'tern/lib/tern',
- 'javascript/plugins/ternDefaults',
- 'orion/Deferred',
- 'orion/serialize',
- 'i18n!javascript/nls/workermessages',
- 'orion/i18nUtil'
-],
-/* @callback */ function(Tern, defaultOptions, Deferred, Serialize, Messages, i18nUtil) {
-
- var ternserver = null;
-
- /**
- * @param {Object} jsonOptions The optional map of JSON options to start the server with
- * @param {Function} callback The optional function to callback to
- * @description Start up the Tern server, send a message after trying
- */
- function startServer(jsonOptions, callback) {
- if (ternserver){
- ternserver.reset();
- ternserver = null;
- }
- var options = {
- async: true,
- debug: false,
- projectDir: '/',
- getFile: _getFile
- };
- var pluginsDir = defaultOptions.pluginsDir;
- var defsDir = defaultOptions.defsDir;
- var defNames = [];
- if (jsonOptions) {
- if (jsonOptions.plugins){
- options.plugins = jsonOptions.plugins;
- }
- if(jsonOptions.pluginDir) {
- pluginsDir = jsonOptions.pluginsDir;
- }
- if (Array.isArray(jsonOptions.libs)){
- defNames = jsonOptions.libs;
- defsDir = jsonOptions.defsDir;
- }
- if (Array.isArray(jsonOptions.defs)){
- defNames = jsonOptions.defs;
- defsDir = jsonOptions.defsDir;
- }
- if (typeof jsonOptions.ecmaVersion === 'number'){
- options.ecmaVersion = jsonOptions.ecmaVersion;
- }
- if (typeof jsonOptions.dependencyBudget === 'number'){
- options.dependencyBudget = jsonOptions.dependencyBudget;
- }
- }
- function defaultStartUp(err) {
- options.plugins = defaultOptions.plugins;
- options.defs = defaultOptions.defs;
- ternserver = new Tern.Server(options);
- callback({request: 'start_server', state: "server_ready"}); //$NON-NLS-1$ //$NON-NLS-2$
- if(err) {
- post(Serialize.serializeError(err));
- }
- }
- if(!options.plugins && (!defNames || defNames.length < 1)) {
- defaultStartUp();
- } else {
- Deferred.all(loadPlugins(options.plugins, pluginsDir)).then(/* @callback */ function(plugins) {
- Deferred.all(loadDefs(defNames, defsDir)).then(function(json) {
- options.defs = json;
- ternserver = new Tern.Server(options);
- callback({request: 'start_server', state: "server_ready"}); //$NON-NLS-1$ //$NON-NLS-2$
- }, defaultStartUp);
- }, defaultStartUp);
- }
- }
- post({request: "worker_ready"}); //$NON-NLS-1$
-
- var handlers = {
- 'start_server': function(args, callback){
- startServer(args.options, callback);
- },
- 'addFile': function(args, callback) {
- ternserver.addFile(args.file, args.source);
- callback({request: 'addFile'}); //$NON-NLS-1$
- },
- 'completions': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: "completions", //$NON-NLS-1$
- file: args.meta.location,
- types: true,
- origins: true,
- urls: true,
- docs: true,
- end: args.params.offset,
- sort:true,
- includeKeywords: args.params.keywords,
- caseInsensitive: true
- },
- files: args.files},
- function(error, comps) {
- if(error) {
- callback({request: 'completions', proposals:[], error: error.message, message: Messages['failedToComputeProposals']}); //$NON-NLS-1$
- } else if(comps && comps.completions) {
- callback({request: 'completions', proposals: comps.completions}); //$NON-NLS-1$
- } else {
- callback({request: 'completions', proposals:[]}); //$NON-NLS-1$
- }
- });
-
- } else {
- callback({request: 'completions', message: Messages['failedToComputeProposalsNoServer']}); //$NON-NLS-1$
- }
- },
- 'definition': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: "definition", //$NON-NLS-1$
- file: args.meta.location,
- end: args.params.offset,
- guess: args.guess
- },
- files: args.files},
- function(error, decl) {
- if(error) {
- callback({request: 'definition', error: error.message, message: Messages['failedToComputeDecl']}); //$NON-NLS-1$
- }
- if(decl && typeof(decl.start) === 'number' && typeof(decl.end) === "number") {
- callback({request: 'definition', declaration:decl}); //$NON-NLS-1$
- } else {
- callback({request: 'definition', declaration: null}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'definition', message: Messages['failedToComputeDeclNoServer']}); //$NON-NLS-1$
- }
- },
- 'delFile': function(args, callback) {
- if(ternserver && typeof(args.file) === 'string') {
- ternserver.delFile(args.file);
- callback({request: 'delFile'}); //$NON-NLS-1$
- } else {
- callback({request: 'delFile', message: i18nUtil.formatMessage(Messages['failedDeleteRequest'], args.file)}); //$NON-NLS-1$
- }
- },
- 'documentation': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: "documentation", //$NON-NLS-1$
- file: args.meta.location,
- end: args.params.offset,
- docFormat: args.params.docFormat
- },
- files: args.files},
- function(error, doc) {
- if(error) {
- callback({request: 'documentation', error: error.message, message: Messages['failedToComputeDoc']}); //$NON-NLS-1$
- } else if(doc && doc.doc) {
- callback({request: 'documentation', doc:doc}); //$NON-NLS-1$
- } else {
- callback({request: 'documentation', doc: null}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'documentation', message: Messages['failedToComputeDocNoServer']}); //$NON-NLS-1$
- }
- },
- /**
- * @callback
- */
- 'environments': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: 'environments' //$NON-NLS-1$
- }},
- function(error, envs) {
- if(error) {
- callback({request: 'environments', error: error.message, message: Messages['failedGetEnvs']}); //$NON-NLS-1$
- }
- if(typeof(envs) === 'object') {
- callback({request: 'environments', envs:envs}); //$NON-NLS-1$
- } else {
- callback({request: 'environments', envs: null}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'environments', message: Messages['failedGetEnvsNoServer']}); //$NON-NLS-1$
- }
- },
- 'implementation': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: "implementation", //$NON-NLS-1$
- file: args.meta.location,
- end: args.params.offset,
- guess: args.guess
- },
- files: args.files},
- function(error, impl) {
- if(error) {
- callback({request: 'implementation', error: error.message, message: Messages['failedToComputeImpl']}); //$NON-NLS-1$
- }
- if(impl && impl.implementation && typeof(impl.implementation.start) === 'number' && typeof(impl.implementation.end) === "number") {
- callback({request: 'implementation', implementation:impl.implementation}); //$NON-NLS-1$
- } else {
- callback({request: 'implementation', implementation: null}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'implementation', message: Messages['failedToComputeImplNoServer']}); //$NON-NLS-1$
- }
- },
- /**
- * @callback
- */
- 'install_plugins': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: 'install_plugins' //$NON-NLS-1$
- }},
- function(error, res) {
- if(error) {
- callback({request: 'install_plugins', error: error.message, message: Messages['failedInstallPlugins']}); //$NON-NLS-1$
- }
- if(typeof(res) === 'object') {
- callback({request: 'install_plugins', status:res}); //$NON-NLS-1$
- } else {
- callback({request: 'install_plugins', status: {state: -1}}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'install_plugins', message: Messages['failedInstallPluginsNoServer']}); //$NON-NLS-1$
- }
- },
- /**
- * @callback
- */
- 'installed_plugins': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: 'installed_plugins' //$NON-NLS-1$
- }},
- function(error, plugins) {
- if(error) {
- callback({request: 'installed_plugins', error: error.message, message: Messages['failedGetInstalledPlugins']}); //$NON-NLS-1$
- }
- if(typeof(plugins) === 'object') {
- callback({request: 'installed_plugins', plugins:plugins}); //$NON-NLS-1$
- } else {
- callback({request: 'installed_plugins', plugins: null}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'installed_plugins', message: Messages['failedGetInstalledPluginsNoServer']}); //$NON-NLS-1$
- }
- },
- 'occurrences': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: "refs", //$NON-NLS-1$
- file: args.meta.location,
- end: args.params.selection.start
- }},
- function(error, refs) {
- if(error) {
- callback({request: 'occurrences', error: error.message, message: Messages['failedToComputeOccurrences']}); //$NON-NLS-1$
- } else if(refs && Array.isArray(refs)) {
- callback({request: 'occurrences', refs:refs}); //$NON-NLS-1$
- } else {
- callback({request: 'occurrences', refs:[]}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'occurrences', message: Messages['failedToComputeOccurrencesNoServer']}); //$NON-NLS-1$
- }
- },
- /**
- * @callback
- */
- 'plugin_enablement': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: 'plugin_enablement' //$NON-NLS-1$
- }},
- function(error, res) {
- if(error) {
- callback({request: 'plugin_enablement', error: error.message, message: Messages['failedEnablementPlugins']}); //$NON-NLS-1$
- }
- if(typeof(res) === 'object') {
- callback({request: 'plugin_enablement', status:res}); //$NON-NLS-1$
- } else {
- callback({request: 'plugin_enablement', status: {state: -1}}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'plugin_enablement', message: Messages['failedEnablementPluginsNoServer']}); //$NON-NLS-1$
- }
- },
- /**
- * @callback
- */
- 'remove_plugins': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: 'remove_plugins' //$NON-NLS-1$
- }},
- function(error, res) {
- if(error) {
- callback({request: 'remove_plugins', error: error.message, message: Messages['failedRemovePlugins']}); //$NON-NLS-1$
- }
- if(typeof(res) === 'object') {
- callback({request: 'remove_plugins', status:res}); //$NON-NLS-1$
- } else {
- callback({request: 'remove_plugins', status: {state: -1}}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'remove_plugins', message: Messages['failedRemovePluginsNoServer']}); //$NON-NLS-1$
- }
- },
- 'rename': function(args, callback) {
- if(ternserver) {
- ternserver.request({
- query: {
- type: "rename", //$NON-NLS-1$
- file: args.meta.location,
- end: args.params.offset,
- newName: args.newname
- },
- files: args.files},
- function(error, changes) {
- if(error) {
- callback({request: 'rename', error: error.message, message: Messages['failedRename']}); //$NON-NLS-1$
- } else if(changes && Array.isArray(changes.changes)) {
- callback({request: 'rename', changes:changes}); //$NON-NLS-1$
- } else {
- callback({request: 'rename', changes:[]}); //$NON-NLS-1$
- }
- });
- } else {
- callback({request: 'rename', message: Messages['failedRenameNoServer']}); //$NON-NLS-1$
- }
- },
- 'type': function(args, callback) {
- ternserver.request({
- query: {
- type: "type", //$NON-NLS-1$
- file: args.meta.location,
- end: args.params.offset
- }},
- function(error, type) {
- if(error) {
- callback({request: 'type', error: typeof(error) === 'string' ? error : error.message, message: Messages['failedType']}); //$NON-NLS-1$
- } else {
- callback({request: 'type', type: type}); //$NON-NLS-1$
- }
- });
- },
- 'checkRef': function(args, callback) {
- ternserver.request({
- query: {
- type: "checkRef", //$NON-NLS-1$
- file: args.meta.location,
- end: args.params.offset,
- origin: args.origin
- },
- files: args.files},
- function(error, type) {
- if(error) {
- callback({request: 'checkRef', error: typeof(error) === 'string' ? error : error.message, message: Messages['failedType']}); //$NON-NLS-1$
- } else {
- callback({request: 'checkRef', type: type}); //$NON-NLS-1$
- }
- });
- },
- 'lint': function(args, callback) {
- var query =
- {
- type: "lint", //$NON-NLS-1$
- file: args.meta.location,
- config: {
- rules: args.rules
- }
- };
-
- if (args.env) {
- query.env = args.env;
- }
- ternserver.request(
- {
- query: query,
- files: args.files
- },
- function(error, problems) {
- if(error) {
- callback({request: 'lint', error: error.message, message: Messages['failedToComputeProblems']}); //$NON-NLS-1$
- } else if(problems && Array.isArray(problems)) {
- callback({request: 'lint', problems: problems}); //$NON-NLS-1$
- } else {
- callback({request: 'lint', problems: []}); //$NON-NLS-1$
- }
- });
- },
- 'outline': function(args, callback) {
- ternserver.request({
- query: {
- type: "outline", //$NON-NLS-1$
- file: args.meta.location
- },
- files: args.files
- },
- function(error, outline) {
- if(error) {
- callback({request: 'outline', error: error.message, message: Messages['failedToComputeOutline']}); //$NON-NLS-1$
- } else if(outline && Array.isArray(outline)) {
- callback({request: 'outline', outline: outline}); //$NON-NLS-1$
- } else {
- callback({request: 'outline', outline: []}); //$NON-NLS-1$
- }
- }
- );
- }
- };
-
- var ternID = 0;
- var reads = Object.create(null);
- var resolverReads = Object.create(null);
-
- /**
- * @description Worker callback when a message is sent to the worker
- * @callback
- */
- onmessage = function(evnt) {
- if(typeof(evnt.data) === 'object') {
- var _d = evnt.data;
- if (!ternserver && _d.request !== 'start_server'){
- serverNotReady(_d);
- }
- var _handler = handlers[_d.request];
- if(typeof(_handler) === 'function') {
- _handler(_d.args, function(response) {
- if(typeof(_d.messageID) === 'number') {
- response.messageID = _d.messageID;
- } else if(typeof(_d.ternID) === 'number') {
- response.ternID = _d.ternID;
- }
- post(response);
- return;
- });
- } else if(_d.request === 'read') {
- var _read = reads[_d.ternID];
- if(typeof(_read) === 'function') {
- var text = '';
- if(_d.args && _d.args.contents) {
- text = _d.args.contents;
- }
- _read(_d.args.error, text);//{contents: _d.args.contents ? _d.args.contents : '', file:_d.args.file, logical: _d.args.logical});
- delete reads[_d.ternID];
- }
- _read = resolverReads[_d.ternID];
- if(typeof(_read) === 'function') {
- _read(_d.args.error, {contents: _d.args.contents ? _d.args.contents : '', file:_d.args.file, logical: _d.args.logical});
- delete reads[_d.ternID];
- }
- return;
- } else {
- //no one handled the request, report back an error
- unknownRequest(_d);
- }
- }
- };
-
- /**
- * @description Respond back that the request is unknown
- * @param {Object} data The original request data
- */
- function unknownRequest(data) {
- var response = Object.create(null);
- response.request = data.request;
- if(data.messageID) {
- response.messageID = data.messageID;
- } else if(data.ternID) {
- response.ternID = data.ternID;
- }
- response.error = i18nUtil.formatMessage(Messages['unknownRequest'], response.request);
- post(response);
- }
-
- /**
- * @description Respond back that the tern server has not been started
- * @param {Object} data The original request data
- */
- function serverNotReady(data) {
- var response = Object.create(null);
- response.request = data.request;
- if(data.messageID) {
- response.messageID = data.messageID;
- } else if(data.ternID) {
- response.ternID = data.ternID;
- }
- response.error = i18nUtil.formatMessage(Messages['serverNotStarted'], response.request);
- post(response);
- }
-
- /**
- * @description Worker callback when an error occurs
- * @callback
- */
- onerror = function(evnt) {
- post(evnt);
- };
-
- /**
- * @description Worker callback when a shared worker starts up
- * @callback
- */
- onconnect = function(evnt) {
- this.port = evnt.ports[0];
- this.port.onmessage = onmessage;
- this.port.start();
- };
-
- /**
- * @description Sends the given message back to the client. If the msg is null, send an Error
- * object with the optional given error message
- * @param {Object} msg The message to send back to the client
- * @param {String} errormsg The optional error message to send back to the client if the main message is null
- */
- function post(msg, errormsg) {
- if(!msg) {
- msg = new Error(errormsg ? errormsg : Messages['unknownError']);
- }
- if(this.port) {
- this.port.postMessage(msg);
- } else {
- postMessage(msg);
- }
- }
-
- /**
- * @description Read a file from the workspace into Tern
- * @private
- * @param {String} file The full path of the file
- * @param {Function} callback The callback once the file has been read or failed to read
- */
- function _getFile(file, callback) {
- if(ternserver) {
- var request = {request: 'read', ternID: ternID++, args: {file:file}}; //$NON-NLS-1$
- if(file != null && typeof(file) === 'object') {
- resolverReads[request.ternID] = callback;
- } else {
- reads[request.ternID] = callback;
- }
- post(request, null);
- } else {
- post(i18nUtil.formatMessage(Messages['failedReadRequest'], typeof(file) === 'object' ? file.logical : file));
- }
- }
-
- /**
- * @description Loads the plugins listed in the given plugins object
- * @param {Object} plugins The object of plugins
- * @param {String} pluginsDir The base directory to load plugins from, if not defined, the default of 'tern/plugin/' is assumed
- * @returns {Promise} The promise to resolve all of the plugin loads
- * @since 11.0
- */
- function loadPlugins(plugins, pluginsDir) {
- var promises = [];
- if(plugins) {
- Object.keys(plugins).forEach(function(key) {
- if(defaultOptions.plugins[key]) {
- //default plugins are statically loaded
- return;
- }
- var plugin = plugins[key];
- var loc = plugin.location;
- if(typeof(loc) !== 'string') {
- if(typeof(pluginsDir) === 'string') {
- loc = pluginsDir + key;
- } else {
- //assume it is in /tern/plugin/
- loc = 'tern/plugin/' + key; //$NON-NLS-1$
- }
- }
- var deferred = new Deferred();
- try {
- promises.push(deferred);
- requirejs([loc], function(_) {
- deferred.resolve(_);
- },
- function(err) {
- deferred.reject(err);
- });
- }
- catch(err) {
- post(err);
- deferred.reject(err);
- }
- });
- }
- return promises;
- }
-
- /**
- * @description Load any defs from the .tern-project file
- * @param {Array.<String>|Object} defs The definitions, either from an array of names or an object of names with additional metadata
- * @param {String} defsDir The optional directory where to find the definitions. If not given the 'tern/defs' directory is assumed
- * @returns {Promise} Returns a promise to resolve all def loads
- * @since 11.0
- */
- function loadDefs(defs, defsDir) {
- var _defs = [];
- if(Array.isArray(defs)) {
- defs.forEach(function(_def) {
- _defs.push(_loadDef(_def, defsDir, _defs));
- });
- } else if(defs && typeof(defs) === 'object') {
- Object.keys(defs).forEach(function(key) {
- var def = defs[key];
- if(typeof(def.location) === 'string') {
- _defs.push(_loadDef(def.location, defsDir, _defs));
- } else {
- _defs.push(_loadDef(key, defsDir, _defs));
- }
- });
- }
- return _defs;
- }
-
- /**
- * @description Delegate to actually load a definition
- * @private
- * @param {String} def The name of the definition load try and load
- * @param {String} defsDir The optional base directory to load from
- * @param {Array.<Object>} defs The collector array for loaded defs
- * @since 11.0
- */
- function _loadDef(def, defsDir) {
- var loc = def;
- if(typeof(defsDir) === 'string') {
- loc = defsDir + def;
- } else {
- //assume it is in /tern/defs/
- loc = 'json!tern/defs/' + def; //$NON-NLS-1$
- }
- if(!/^json!/i.test(loc)) {
- loc = 'json!'+loc; //$NON-NLS-1$
- }
- if(!/$.json/i.test(def)) {
- loc = loc + '.json'; //$NON-NLS-1$
- }
- var deferred = new Deferred();
- try {
- requirejs([loc], function(_) {
- deferred.resolve(_);
- },
- function(err) {
- deferred.reject(err);
- });
- }
- catch(err) {
- post(err);
- deferred.reject(err);
- }
- return deferred;
- }
-});
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js
index 295a954..64fe51c 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js
@@ -107,6 +107,9 @@ define([
}
}
return null;
+ },
+ /* @callback */ function(reject) {
+ return null;
});
},
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js
index 6320b5c..e14b292 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js
@@ -20,13 +20,13 @@ define([
* @constructor
* @public
* @param {javascript.ASTManager} ASTManager The backing AST manager
- * @param {TernWorker} ternWorker The running Tern worker
+ * @param {TernServer} ternSErver The running Tern server
* @param {javascript.CUProvider} cuProvider
* @returns {javascript.commands.OpenDeclarationCommand} A new command
* @since 8.0
*/
- function TernProjectManager(ternWorker, scriptResolver, fileClient) {
- this.ternWorker = ternWorker;
+ function TernProjectManager(ternServer, scriptResolver, fileClient) {
+ this.ternWorker = ternServer;
this.scriptResolver = scriptResolver;
this.fileClient = fileClient;
this.currentProjectLocation = null;
@@ -145,7 +145,7 @@ define([
// console.log(jsonOptions);
if (jsonOptions.plugins || Array.isArray(jsonOptions.libs) || jsonOptions.dependencyBudget || jsonOptions.ecmaVersion){
- this.ternWorker.postMessage({request: "start_server", args: {options: jsonOptions}}); //$NON-NLS-1$
+ this.ternWorker.startServer(jsonOptions);
}
if (Array.isArray(jsonOptions.loadEagerly)){
@@ -165,9 +165,7 @@ define([
if (files.length > 1){
console.log('Tern-Project File: Found multiple potential files for: ' + filename);
}
- this.ternWorker.postMessage(
- {request:'addFile', args:{file: files[0].location}} //$NON-NLS-1$
- );
+ this.ternWorker.addFile(files[0].location);
} else {
console.log("Tern-Project File: Could not find any matching files for: " + filename);
}
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js
index bd58e28..94803c0 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js
@@ -59,14 +59,13 @@ define([
/**
* @description Creates a new ESLintValidator
- * @constructor
* @public
- * @param {javascript.ASTManager} astManager The AST manager backing this validator
- * @param {javascript.CUProvider} cuProvider
+ * @param {TernServer} ternServer The backing running server
+ * @param {CUProvider} cuProvider
* @returns {ESLintValidator} Returns a new validator
*/
- function ESLintValidator(ternWorker, cuProvider) {
- this.ternWorker = ternWorker;
+ function ESLintValidator(ternServer, cuProvider) {
+ this.ternserver = ternServer;
this.cuprovider = cuProvider;
config.setDefaults();
}
@@ -222,16 +221,9 @@ define([
undefRuleValue = config.rules['no-undef'];
config.rules['no-undef'] = 0;
}
-
- config.env = env;
var files = [{type: 'full', name: meta.location, text: text}]; //$NON-NLS-1$
- var request = {request: 'lint', args: {meta: {location: meta.location}, files: files, rules: config.rules}}; //$NON-NLS-1$
- if(env) {
- request.env = config.env;
- }
- this.ternWorker.postMessage(
- request,
- /* @callback */ function(type, err) {
+ this.ternserver.lint(meta.location, config.rules, env, files,
+ function(val, err) {
var eslintErrors = [];
if(err) {
eslintErrors.push({
@@ -239,13 +231,14 @@ define([
args: {0: err.error, nls: "eslintValidationFailure" }, //$NON-NLS-0$
severity: "error" //$NON-NLS-0$
});
- } else if (type.problems) {
- type.problems.forEach(function(element) {
+ } else if (val) {
+ val.forEach(function(element) {
eslintErrors.push(element);
});
}
deferred.resolve({ problems: eslintErrors.map(toProblem) });
- });
+ }
+ );
if (htmlMode) {
config.rules['no-undef'] = undefRuleValue;
}
diff --git a/bundles/org.eclipse.orion.client.ui/web/css/theme_common.css b/bundles/org.eclipse.orion.client.ui/web/css/theme_common.css
index 54034a8..118821e 100644
--- a/bundles/org.eclipse.orion.client.ui/web/css/theme_common.css
+++ b/bundles/org.eclipse.orion.client.ui/web/css/theme_common.css
@@ -1137,10 +1137,6 @@ a.breadcrumb.currentLocation {
transition: opacity 0.2s ease-in;
}
-.textviewTooltip {
- background-color: #158d7a;
-}
-
.textviewTooltip .commandButton {
border-color: white;
color: white;
diff --git a/bundles/org.eclipse.orion.client.ui/web/defaults.pref b/bundles/org.eclipse.orion.client.ui/web/defaults.pref
index 3325b8f..7edceba 100644
--- a/bundles/org.eclipse.orion.client.ui/web/defaults.pref
+++ b/bundles/org.eclipse.orion.client.ui/web/defaults.pref
@@ -1,9 +1,9 @@
{
"/plugins":{
- "plugins/orionSharedWorker.js": true,
+ "plugins/orionWorker.js": true,
"git/plugins/gitPlugin.html":true,
"webtools/plugins/webToolsPlugin.html":true,
- "javascript/plugins/javascriptPlugin.html":true,
+ "javascript/plugins/javascriptWorker.js":true,
"edit/content/imageViewerPlugin.html":true,
"edit/content/jsonEditorPlugin.html":true,
"cfui/plugins/cFPlugin.html":true,