|
Lines 1-6
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* @license |
2 |
* @license |
| 3 |
* Copyright (c) 2015 IBM Corporation and others. |
3 |
* Copyright (c) 2015, 2016 IBM Corporation and others. |
| 4 |
* All rights reserved. This program and the accompanying materials are made |
4 |
* All rights reserved. This program and the accompanying materials are made |
| 5 |
* available under the terms of the Eclipse Public License v1.0 |
5 |
* available under the terms of the Eclipse Public License v1.0 |
| 6 |
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution |
6 |
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution |
|
Lines 58-67
Link Here
|
| 58 |
var pluginsDir = defaultOptions.pluginsDir; |
58 |
var pluginsDir = defaultOptions.pluginsDir; |
| 59 |
var defNames, plugins, projectLoc; |
59 |
var defNames, plugins, projectLoc; |
| 60 |
if (jsonOptions) { |
60 |
if (jsonOptions) { |
| 61 |
projectLoc = jsonOptions.projectLoc; |
61 |
projectLoc = jsonOptions.projectLoc; |
| 62 |
plugins = jsonOptions.plugins; |
62 |
plugins = jsonOptions.plugins; |
| 63 |
pluginsDir = jsonOptions.pluginsDir; |
63 |
pluginsDir = jsonOptions.pluginsDir; |
| 64 |
defNames = jsonOptions.libs; |
64 |
defNames = jsonOptions.libs; |
|
|
65 |
if(Array.isArray(jsonOptions.loadEagerly) && jsonOptions.loadEagerly.length > 0) { |
| 66 |
options.loadEagerly = jsonOptions.loadEagerly; |
| 67 |
} |
| 65 |
if (typeof jsonOptions.ecmaVersion === 'number') { |
68 |
if (typeof jsonOptions.ecmaVersion === 'number') { |
| 66 |
options.ecmaVersion = jsonOptions.ecmaVersion; |
69 |
options.ecmaVersion = jsonOptions.ecmaVersion; |
| 67 |
} |
70 |
} |
|
Lines 82-102
Link Here
|
| 82 |
} |
85 |
} |
| 83 |
} |
86 |
} |
| 84 |
if(typeof plugins !== 'object') { |
87 |
if(typeof plugins !== 'object') { |
| 85 |
plugins = null; |
88 |
plugins = null; |
| 86 |
} else { |
89 |
} else { |
| 87 |
Objects.mixin(options.plugins, plugins); |
90 |
Objects.mixin(options.plugins, plugins); |
| 88 |
} |
91 |
} |
| 89 |
if(!Array.isArray(defNames)) { |
92 |
if(!Array.isArray(defNames)) { |
| 90 |
defNames = null; |
93 |
defNames = null; |
| 91 |
} |
94 |
} |
| 92 |
/** |
95 |
/** |
| 93 |
* A subtlety - if the user provides no plugins entry at all, they get all the defaults, |
96 |
* A subtlety - if the user provides no plugins entry at all, they get all the defaults, |
| 94 |
* if they provide an empty object they still need the required ones only for a default startup |
97 |
* if they provide an empty object they still need the required ones only for a default startup |
| 95 |
*/ |
98 |
*/ |
| 96 |
var requiredOnly = plugins && Object.keys(plugins).length < 1; |
99 |
var requiredOnly = plugins && Object.keys(plugins).length < 1; |
|
|
100 |
/** |
| 101 |
* @description Start the server with the default options |
| 102 |
* @param {Error} err The error object from the failed deferred |
| 103 |
*/ |
| 97 |
function defaultStartUp(err) { |
104 |
function defaultStartUp(err) { |
| 98 |
options.plugins = defaultOptions.plugins.required; |
105 |
options.plugins = defaultOptions.plugins.required; |
| 99 |
if(!requiredOnly) { |
106 |
if(!requiredOnly) { |
| 100 |
Objects.mixin(options.plugins, defaultOptions.plugins.optional); |
107 |
Objects.mixin(options.plugins, defaultOptions.plugins.optional); |
| 101 |
} |
108 |
} |
| 102 |
options.defs = defaultOptions.defs; |
109 |
options.defs = defaultOptions.defs; |
|
Lines 105-144
Link Here
|
| 105 |
post(Serialize.serializeError(err)); |
112 |
post(Serialize.serializeError(err)); |
| 106 |
} |
113 |
} |
| 107 |
} |
114 |
} |
|
|
115 |
/** |
| 116 |
* @description Starts the tern server wit the given options |
| 117 |
* @param {Object} options The options to start the server with |
| 118 |
*/ |
| 108 |
function startAndMessage(options) { |
119 |
function startAndMessage(options) { |
| 109 |
ternserver = new Tern.Server(options); |
120 |
ternserver = new Tern.Server(options); |
|
|
121 |
if(Array.isArray(options.loadEagerly) && options.loadEagerly.length > 0) { |
| 122 |
options.loadEagerly.forEach(function(file) { |
| 123 |
ternserver.addFile(file); |
| 124 |
}); |
| 125 |
} |
| 110 |
callback({request: 'start_server', state: "server_ready"}); //$NON-NLS-1$ //$NON-NLS-2$ |
126 |
callback({request: 'start_server', state: "server_ready"}); //$NON-NLS-1$ //$NON-NLS-2$ |
| 111 |
|
127 |
} |
| 112 |
} |
128 |
if((!plugins || requiredOnly) && !defNames) { |
| 113 |
if((!plugins || requiredOnly) && !defNames) { |
|
|
| 114 |
defaultStartUp(); |
129 |
defaultStartUp(); |
| 115 |
} else { |
130 |
} else { |
| 116 |
Deferred.all(loadPlugins(options.plugins, pluginsDir)).then(/* @callback */ function(plugins) { |
131 |
Deferred.all(loadPlugins(options.plugins, pluginsDir)).then(/* @callback */ function(plugins) { |
| 117 |
if(defNames) { |
132 |
if(defNames) { |
| 118 |
if(defNames.length < 1) { |
133 |
if(defNames.length < 1) { |
| 119 |
startAndMessage(options); |
134 |
startAndMessage(options); |
| 120 |
} else { |
135 |
} else { |
| 121 |
Deferred.all(loadDefs(defNames, projectLoc)).then(function(json) { |
136 |
Deferred.all(loadDefs(defNames, projectLoc)).then(function(json) { |
| 122 |
options.defs = json; |
137 |
options.defs = json; |
| 123 |
startAndMessage(options); |
138 |
startAndMessage(options); |
| 124 |
}, defaultStartUp); |
139 |
}, defaultStartUp); |
| 125 |
} |
140 |
} |
| 126 |
} else { |
141 |
} else { |
| 127 |
startAndMessage(options); |
142 |
startAndMessage(options); |
| 128 |
} |
143 |
} |
| 129 |
}, defaultStartUp); |
144 |
}, defaultStartUp); |
| 130 |
} |
145 |
} |
| 131 |
} |
146 |
} |
| 132 |
post({request: "worker_ready"}); //$NON-NLS-1$ |
147 |
post({request: "worker_ready"}); //$NON-NLS-1$ |
| 133 |
|
148 |
|
| 134 |
var handlers = { |
149 |
var handlers = { |
|
|
150 |
/* start_server message handler */ |
| 135 |
'start_server': function(args, callback){ |
151 |
'start_server': function(args, callback){ |
| 136 |
startServer(args.options, callback); |
152 |
startServer(args.options, callback); |
| 137 |
}, |
153 |
}, |
|
|
154 |
/* addFile message handler */ |
| 138 |
'addFile': function(args, callback) { |
155 |
'addFile': function(args, callback) { |
| 139 |
ternserver.addFile(args.file, args.source); |
156 |
ternserver.addFile(args.file, args.source); |
| 140 |
callback({request: 'addFile'}); //$NON-NLS-1$ |
157 |
callback({request: 'addFile'}); //$NON-NLS-1$ |
| 141 |
}, |
158 |
}, |
|
|
159 |
/* completions message handler */ |
| 142 |
'completions': function(args, callback) { |
160 |
'completions': function(args, callback) { |
| 143 |
if(ternserver) { |
161 |
if(ternserver) { |
| 144 |
ternserver.request({ |
162 |
ternserver.request({ |
|
Lines 170-175
Link Here
|
| 170 |
callback({request: 'completions', message: Messages['failedToComputeProposalsNoServer']}); //$NON-NLS-1$ |
188 |
callback({request: 'completions', message: Messages['failedToComputeProposalsNoServer']}); //$NON-NLS-1$ |
| 171 |
} |
189 |
} |
| 172 |
}, |
190 |
}, |
|
|
191 |
/* definition message handler */ |
| 173 |
'definition': function(args, callback) { |
192 |
'definition': function(args, callback) { |
| 174 |
if(ternserver) { |
193 |
if(ternserver) { |
| 175 |
ternserver.request({ |
194 |
ternserver.request({ |
|
Lines 194-199
Link Here
|
| 194 |
callback({request: 'definition', message: Messages['failedToComputeDeclNoServer']}); //$NON-NLS-1$ |
213 |
callback({request: 'definition', message: Messages['failedToComputeDeclNoServer']}); //$NON-NLS-1$ |
| 195 |
} |
214 |
} |
| 196 |
}, |
215 |
}, |
|
|
216 |
/* delFile message handler */ |
| 197 |
'delFile': function(args, callback) { |
217 |
'delFile': function(args, callback) { |
| 198 |
if(ternserver && typeof args.file === 'string') { |
218 |
if(ternserver && typeof args.file === 'string') { |
| 199 |
ternserver.delFile(args.file); |
219 |
ternserver.delFile(args.file); |
|
Lines 202-207
Link Here
|
| 202 |
callback({request: 'delFile', message: i18nUtil.formatMessage(Messages['failedDeleteRequest'], args.file)}); //$NON-NLS-1$ |
222 |
callback({request: 'delFile', message: i18nUtil.formatMessage(Messages['failedDeleteRequest'], args.file)}); //$NON-NLS-1$ |
| 203 |
} |
223 |
} |
| 204 |
}, |
224 |
}, |
|
|
225 |
/* documentation message handler */ |
| 205 |
'documentation': function(args, callback) { |
226 |
'documentation': function(args, callback) { |
| 206 |
if(ternserver) { |
227 |
if(ternserver) { |
| 207 |
ternserver.request({ |
228 |
ternserver.request({ |
|
Lines 225-233
Link Here
|
| 225 |
callback({request: 'documentation', message: Messages['failedToComputeDocNoServer']}); //$NON-NLS-1$ |
246 |
callback({request: 'documentation', message: Messages['failedToComputeDocNoServer']}); //$NON-NLS-1$ |
| 226 |
} |
247 |
} |
| 227 |
}, |
248 |
}, |
| 228 |
/** |
249 |
/* environments message handler */ |
| 229 |
* @callback |
|
|
| 230 |
*/ |
| 231 |
'environments': function(args, callback) { |
250 |
'environments': function(args, callback) { |
| 232 |
if(ternserver) { |
251 |
if(ternserver) { |
| 233 |
ternserver.request({ |
252 |
ternserver.request({ |
|
Lines 248-253
Link Here
|
| 248 |
callback({request: 'environments', message: Messages['failedGetEnvsNoServer']}); //$NON-NLS-1$ |
267 |
callback({request: 'environments', message: Messages['failedGetEnvsNoServer']}); //$NON-NLS-1$ |
| 249 |
} |
268 |
} |
| 250 |
}, |
269 |
}, |
|
|
270 |
/* implementation message handler */ |
| 251 |
'implementation': function(args, callback) { |
271 |
'implementation': function(args, callback) { |
| 252 |
if(ternserver) { |
272 |
if(ternserver) { |
| 253 |
ternserver.request({ |
273 |
ternserver.request({ |
|
Lines 272-280
Link Here
|
| 272 |
callback({request: 'implementation', message: Messages['failedToComputeImplNoServer']}); //$NON-NLS-1$ |
292 |
callback({request: 'implementation', message: Messages['failedToComputeImplNoServer']}); //$NON-NLS-1$ |
| 273 |
} |
293 |
} |
| 274 |
}, |
294 |
}, |
| 275 |
/** |
295 |
/* installed_plugins message handler */ |
| 276 |
* @callback |
|
|
| 277 |
*/ |
| 278 |
'installed_plugins': function(args, callback) { |
296 |
'installed_plugins': function(args, callback) { |
| 279 |
if(ternserver) { |
297 |
if(ternserver) { |
| 280 |
ternserver.request({ |
298 |
ternserver.request({ |
|
Lines 295-303
Link Here
|
| 295 |
callback({request: 'installed_plugins', message: Messages['failedGetInstalledPluginsNoServer']}); //$NON-NLS-1$ |
313 |
callback({request: 'installed_plugins', message: Messages['failedGetInstalledPluginsNoServer']}); //$NON-NLS-1$ |
| 296 |
} |
314 |
} |
| 297 |
}, |
315 |
}, |
| 298 |
/** |
316 |
/* installed_defs message handler */ |
| 299 |
* @callback |
|
|
| 300 |
*/ |
| 301 |
'installed_defs': function(args, callback) { |
317 |
'installed_defs': function(args, callback) { |
| 302 |
if(ternserver) { |
318 |
if(ternserver) { |
| 303 |
ternserver.request({ |
319 |
ternserver.request({ |
|
Lines 318-323
Link Here
|
| 318 |
callback({request: 'installed_defs', message: Messages['failedGetInstalledDefsNoServer']}); //$NON-NLS-1$ |
334 |
callback({request: 'installed_defs', message: Messages['failedGetInstalledDefsNoServer']}); //$NON-NLS-1$ |
| 319 |
} |
335 |
} |
| 320 |
}, |
336 |
}, |
|
|
337 |
/* rename message handler */ |
| 321 |
'rename': function(args, callback) { |
338 |
'rename': function(args, callback) { |
| 322 |
if(ternserver) { |
339 |
if(ternserver) { |
| 323 |
ternserver.request({ |
340 |
ternserver.request({ |
|
Lines 341-346
Link Here
|
| 341 |
callback({request: 'rename', message: Messages['failedRenameNoServer']}); //$NON-NLS-1$ |
358 |
callback({request: 'rename', message: Messages['failedRenameNoServer']}); //$NON-NLS-1$ |
| 342 |
} |
359 |
} |
| 343 |
}, |
360 |
}, |
|
|
361 |
/* type message handler */ |
| 344 |
'type': function(args, callback) { |
362 |
'type': function(args, callback) { |
| 345 |
ternserver.request({ |
363 |
ternserver.request({ |
| 346 |
query: { |
364 |
query: { |
|
Lines 356-361
Link Here
|
| 356 |
} |
374 |
} |
| 357 |
}); |
375 |
}); |
| 358 |
}, |
376 |
}, |
|
|
377 |
/* checkRef message handler */ |
| 359 |
'checkRef': function(args, callback) { |
378 |
'checkRef': function(args, callback) { |
| 360 |
ternserver.request({ |
379 |
ternserver.request({ |
| 361 |
query: { |
380 |
query: { |
|
Lines 373-378
Link Here
|
| 373 |
} |
392 |
} |
| 374 |
}); |
393 |
}); |
| 375 |
}, |
394 |
}, |
|
|
395 |
/* lint message handler */ |
| 376 |
'lint': function(args, callback) { |
396 |
'lint': function(args, callback) { |
| 377 |
var query = |
397 |
var query = |
| 378 |
{ |
398 |
{ |
|
Lines 401-406
Link Here
|
| 401 |
} |
421 |
} |
| 402 |
}); |
422 |
}); |
| 403 |
}, |
423 |
}, |
|
|
424 |
/* outline message handler */ |
| 404 |
'outline': function(args, callback) { |
425 |
'outline': function(args, callback) { |
| 405 |
ternserver.request({ |
426 |
ternserver.request({ |
| 406 |
query: { |
427 |
query: { |
|
Lines 632-638
Link Here
|
| 632 |
} |
653 |
} |
| 633 |
return _defs; |
654 |
return _defs; |
| 634 |
} |
655 |
} |
| 635 |
|
656 |
|
| 636 |
/** |
657 |
/** |
| 637 |
* @description Delegate to actually load a definition |
658 |
* @description Delegate to actually load a definition |
| 638 |
* @private |
659 |
* @private |